app/library/Auth.php: in loginAuth() lookup by OAuth provider id.
This commit is contained in:
parent
643387b3f3
commit
bbcf6d2644
1 changed files with 4 additions and 16 deletions
|
|
@ -45,32 +45,20 @@ class Auth extends Component
|
|||
*
|
||||
* @param UserDataInterface $auth
|
||||
*/
|
||||
public function loginOauth(UserDataInterface $auth)
|
||||
public function loginOauth(UserDataInterface $data)
|
||||
{
|
||||
// Look for a user with this email.
|
||||
$user = User::findFirstByEmail($auth->getEmail());
|
||||
$user = User::findFirstByOAuthID($data);
|
||||
|
||||
if (!$user) {
|
||||
// Did not find any user. create him.
|
||||
if (strlen($auth->getUsername()) > 0) {
|
||||
$name = $auth->getUsername();
|
||||
} else if(strlen($auth->getName()) > 0) {
|
||||
$name = $auth->getName();
|
||||
} else {
|
||||
$name = '';
|
||||
}
|
||||
|
||||
$user = new User();
|
||||
$user->setEmail($auth->getEmail())
|
||||
->setUsername($name);
|
||||
|
||||
$user = User::createFromOAuthData($data);
|
||||
$user->save();
|
||||
}
|
||||
|
||||
$this->setIdentity($user->getId());
|
||||
|
||||
$this->_eventsManager->fire('auth:onLogin', $this,
|
||||
"OAuth {$auth->getProvider()}");
|
||||
"OAuth {$data->getProvider()}");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Reference in a new issue