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
|
* @param UserDataInterface $auth
|
||||||
*/
|
*/
|
||||||
public function loginOauth(UserDataInterface $auth)
|
public function loginOauth(UserDataInterface $data)
|
||||||
{
|
{
|
||||||
// Look for a user with this email.
|
$user = User::findFirstByOAuthID($data);
|
||||||
$user = User::findFirstByEmail($auth->getEmail());
|
|
||||||
|
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
// Did not find any user. create him.
|
// Did not find any user. create him.
|
||||||
if (strlen($auth->getUsername()) > 0) {
|
$user = User::createFromOAuthData($data);
|
||||||
$name = $auth->getUsername();
|
|
||||||
} else if(strlen($auth->getName()) > 0) {
|
|
||||||
$name = $auth->getName();
|
|
||||||
} else {
|
|
||||||
$name = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$user = new User();
|
|
||||||
$user->setEmail($auth->getEmail())
|
|
||||||
->setUsername($name);
|
|
||||||
|
|
||||||
$user->save();
|
$user->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setIdentity($user->getId());
|
$this->setIdentity($user->getId());
|
||||||
|
|
||||||
$this->_eventsManager->fire('auth:onLogin', $this,
|
$this->_eventsManager->fire('auth:onLogin', $this,
|
||||||
"OAuth {$auth->getProvider()}");
|
"OAuth {$data->getProvider()}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Reference in a new issue