getPassword(); if (strlen($hash) > 1 && password_verify($password, $hash)) { $this->setIdentity($user->getId()); $this->_eventsManager->fire('auth:onLogin', $this, 'password'); return true; } } return false; } /** * Login using OAuth * * @param UserDataInterface $auth */ public function loginOauth(UserDataInterface $auth) { // Look for a user with this email. $user = User::findFirstByEmail($auth->getEmail()); 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->save(); } $this->setIdentity($user->getId()); $this->_eventsManager->fire('auth:onLogin', $this, "OAuth {$auth->getProvider()}"); } /** * @param $identity * @return Auth */ public function setIdentity($identity) { $this->session->set($this->_session_key, $identity); return $this; } /** * return \Model\Data\User */ public function getIdentity() { $id = $this->session->get($this->_session_key); if ($id !== null) { return User::findFirst($id); } return null; } /** * return \Model\Data\User */ public function getUser() { if ($this->hasIdentity()) { $id = $this->session->get($this->_session_key); return User::findFirst($id); } return null; } public function hasIdentity() { return $this->getIdentity() !== NULL; } /** * Clears the identity information. * * @return Auth */ public function clearIdentity() { $this->session->remove($this->_session_key); return $this; } }