app/library/Auth.php: in loginOAuth() we pass a UserDataInterface now.
This commit is contained in:
parent
ef8e78084e
commit
deed1c5318
1 changed files with 9 additions and 13 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Httpcb;
|
namespace Httpcb;
|
||||||
|
|
||||||
|
use Httpcb\OAuth\UserData\UserDataInterface;
|
||||||
use Phalcon\Mvc\User\Component;
|
use Phalcon\Mvc\User\Component;
|
||||||
use App\Model\Data\User;
|
use App\Model\Data\User;
|
||||||
|
|
||||||
|
|
@ -42,24 +43,19 @@ class Auth extends Component
|
||||||
/**
|
/**
|
||||||
* Login using OAuth
|
* Login using OAuth
|
||||||
*
|
*
|
||||||
* @param $auth
|
* @param UserDataInterface $auth
|
||||||
*/
|
*/
|
||||||
public function loginOauth($auth)
|
public function loginOauth(UserDataInterface $auth)
|
||||||
{
|
{
|
||||||
$email = '';
|
|
||||||
if (isset($auth['info']['email'])) {
|
|
||||||
$email = $auth['info']['email'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Look for a user with this email.
|
// Look for a user with this email.
|
||||||
$user = User::findFirstByEmail($email);
|
$user = User::findFirstByEmail($auth->getEmail());
|
||||||
|
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
// Did not find any user. create him.
|
// Did not find any user. create him.
|
||||||
if (isset($auth['info']['nickname'])) {
|
if (strlen($auth->getUsername()) > 0) {
|
||||||
$name = $auth['info']['nickname'];
|
$name = $auth->getUsername();
|
||||||
} else if(isset($auth['info']['name'])) {
|
} else if(strlen($auth->getName()) > 0) {
|
||||||
$name = $auth['info']['name'];
|
$name = $auth->getName();
|
||||||
} else {
|
} else {
|
||||||
$name = '';
|
$name = '';
|
||||||
}
|
}
|
||||||
|
|
@ -74,7 +70,7 @@ class Auth extends Component
|
||||||
$this->setIdentity($user->getId());
|
$this->setIdentity($user->getId());
|
||||||
|
|
||||||
$this->_eventsManager->fire('auth:onLogin', $this,
|
$this->_eventsManager->fire('auth:onLogin', $this,
|
||||||
"OAuth {$auth['provider']}");
|
"OAuth {$auth->getProvider()}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Reference in a new issue