12
12
use Application \Auth ;
13
13
use Application \Users ;
14
14
use Bluz \Application \Exception \ApplicationException ;
15
+ use Bluz \Auth \AuthException ;
15
16
use Bluz \Auth \EntityInterface ;
16
17
use Bluz \Proxy \Config ;
17
18
use Bluz \Proxy \Messages ;
@@ -48,7 +49,7 @@ class AuthProvider implements AuthInterface
48
49
public function __construct ($ providerName )
49
50
{
50
51
if (!in_array (ucfirst ($ providerName ), $ this ->getAvailableProviders ())) {
51
- throw new ApplicationException (sprintf ('Provider % is not defined
52
+ throw new ApplicationException (__ ('Provider `%s` is not defined
52
53
in configuration file ' , ucfirst ($ providerName )));
53
54
}
54
55
$ this ->providerName = ucfirst ($ providerName );
@@ -117,7 +118,7 @@ public function getAuthAdapter()
117
118
$ this ->authAdapter = $ this ->getHybridauth ()->authenticate ($ this ->providerName );
118
119
119
120
if (!$ this ->authAdapter ->isUserConnected ()) {
120
- throw new \ Exception ('Cannot connect to current provider ! ' );
121
+ throw new AuthException ('Cannot connect to current provider! ' );
121
122
}
122
123
}
123
124
@@ -148,7 +149,7 @@ public function registration($data, $user)
148
149
$ row ->tokenType = Auth \Table::TYPE_ACCESS ;
149
150
$ row ->save ();
150
151
151
- Messages::addNotice (sprintf ( 'Your account was linked to %s successfully ! ' , $ this ->providerName ) );
152
+ Messages::addNotice ('Your account was linked to %s successfully ! ' , $ this ->providerName );
152
153
Response::redirectTo ('users ' , 'profile ' , ['id ' => $ user ->id ]);
153
154
}
154
155
@@ -160,15 +161,11 @@ public function authProcess()
160
161
$ this ->authAdapter = $ this ->getAuthAdapter ();
161
162
$ profile = $ this ->getProfile ();
162
163
163
- /**
164
- * @var Auth\Table $authTable
165
- */
166
- $ authTable = Auth \Table::getInstance ();
167
- $ auth = $ authTable ->getAuthRow (strtolower ($ this ->providerName ), $ profile ->identifier );
164
+ $ auth = Auth \Table::getAuthRow (strtolower ($ this ->providerName ), $ profile ->identifier );
168
165
169
166
if ($ this ->identity ) {
170
167
if ($ auth ) {
171
- Messages::addNotice (sprintf ( 'You have already linked to %s ' , $ this ->providerName ) );
168
+ Messages::addNotice ('You have already linked to %s ' , $ this ->providerName );
172
169
Response::redirectTo ('users ' , 'profile ' , ['id ' => $ this ->identity ->id ]);
173
170
} else {
174
171
$ user = Users \Table::findRow ($ this ->identity ->id );
@@ -179,7 +176,7 @@ public function authProcess()
179
176
if ($ auth ) {
180
177
$ this ->alreadyRegisteredLogic ($ auth );
181
178
} else {
182
- Messages::addError (sprintf ( 'First you need to be linked to %s ' , $ this ->providerName ) );
179
+ Messages::addError ('First you need to be linked to %s ' , $ this ->providerName );
183
180
Response::redirectTo ('users ' , 'signin ' );
184
181
}
185
182
}
@@ -209,11 +206,11 @@ public function alreadyRegisteredLogic($auth)
209
206
{
210
207
$ user = Users \Table::findRow ($ auth ->userId );
211
208
212
- if ($ user ->status != Users \Table::STATUS_ACTIVE ) {
209
+ if ($ user ->status !== Users \Table::STATUS_ACTIVE ) {
213
210
Messages::addError ('User is not active ' );
214
211
}
215
212
216
- $ user -> tryLogin ();
213
+ Table:: tryLogin ($ user );
217
214
Response::redirectTo ('index ' , 'index ' );
218
215
}
219
216
0 commit comments