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 $auth */ public function loginOauth($auth) { $email = ''; if (isset($auth['info']['email'])) { $email = $auth['info']['email']; } // Look for a user with this email. $user = User::findFirstByEmail($email); 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']; } else { $name = ''; } $user = new User(); $user->setEmail($email) ->setUsername($name); $user->save(); } $this->setIdentity($user->getId()); $this->_eventsManager->fire('auth:onLogin', $this, "OAuth {$auth['provider']}"); } /** * @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; } }