/** * Attempts to log in the user with the given credentials. * * @param string $username * @param string $password * @throws AuthenticationException If the login fails. */ function doLogin($username, $password) { if (empty($username)) { throw new AuthenticationException(AuthenticationException::MISSING_INFO); } else { $user = $this->user; if (!$user->findByName($username)) { throw new AuthenticationException(AuthenticationException::UNKNOWN_USER); } else { if (!$user->verifyPassword($password)) { throw new AuthenticationException(AuthenticationException::WRONG_PASSWORD); } else { if (!$user->activeField()) { throw new AuthenticationException(AuthenticationException::DISABLED); } else { try { $user->onLogin(); $this->session->setUser($user); } catch (\Exception $e) { throw new AuthenticationException($e->getMessage()); } } } } } }