/** * @param $email * @return User * @throws UserNotFoundException * @throws \Exception */ public function createPasswordRestoringToken($email) { $user = $this->usersReader->getUserByEmail($email); if ($user === null) { throw new UserNotFoundException(); } $user->createToken(); return $this->saveUser($user); }
/** * Performs an authentication against e.g. database. * and returns IIdentity on success or throws AuthenticationException * @return IIdentity * @throws AuthenticationException * @throws InaccessibleAccountException */ public function authenticate(array $credentials) { list($email, $password) = $credentials; $user = $this->usersReader->getUserByEmail($email); if ($user === null) { throw new AuthenticationException('Zadali jste špatný email.'); } if (!Passwords::verify($password, $user->password)) { throw new AuthenticationException('Zadali jste špatné heslo.'); } elseif (Passwords::needsRehash($user->password)) { $user->password = Passwords::hash($password); } if (!$user->isUserAccountAccessible()) { throw new InaccessibleAccountException(); // user is banned } $this->onLoggedIn($user); return new FakeIdentity($user->getId(), get_class($user)); }