Archived
1
0
Fork 0

app/library/Auth.php: in loginOAuth() we pass a UserDataInterface now.

This commit is contained in:
Henrik Hautakoski 2018-04-06 11:48:36 +02:00
parent ef8e78084e
commit deed1c5318

View file

@ -2,6 +2,7 @@
namespace Httpcb;
use Httpcb\OAuth\UserData\UserDataInterface;
use Phalcon\Mvc\User\Component;
use App\Model\Data\User;
@ -42,24 +43,19 @@ class Auth extends Component
/**
* 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.
$user = User::findFirstByEmail($email);
$user = User::findFirstByEmail($auth->getEmail());
if (!$user) {
// Did not find any user. create him.
if (isset($auth['info']['nickname'])) {
$name = $auth['info']['nickname'];
} else if(isset($auth['info']['name'])) {
$name = $auth['info']['name'];
if (strlen($auth->getUsername()) > 0) {
$name = $auth->getUsername();
} else if(strlen($auth->getName()) > 0) {
$name = $auth->getName();
} else {
$name = '';
}
@ -74,7 +70,7 @@ class Auth extends Component
$this->setIdentity($user->getId());
$this->_eventsManager->fire('auth:onLogin', $this,
"OAuth {$auth['provider']}");
"OAuth {$auth->getProvider()}");
}
/**