/** * @param User $user The user to clear auth tokens for. * @return LogoutTemplate Chainable */ private function deleteUserAuthTokens(User $user) { $token = $this->modelFactory()->create(AuthToken::class); if ($token->source()->tableExists()) { $table = $token->source()->table(); $q = 'DELETE FROM ' . $table . ' WHERE username = :username'; $token->source()->dbQuery($q, ['username' => $user->username()]); } return $this; }
/** * @param RequestInterface $request A PSR-7 compatible Request instance. * @param ResponseInterface $response A PSR-7 compatible Response instance. * @return ResponseInterface * @todo This should be done via an Authenticator object. */ public function run(RequestInterface $request, ResponseInterface $response) { $user = User::getAuthenticated($this->modelFactory()); $res = $user->logout(); $this->setSuccess($res); return $response; }
/** * Determine if the current user is authenticated. If not it redirects them to the login page. * * @return void */ private function auth() { if (!session_id()) { session_cache_limiter(false); session_start(); } $u = User::getAuthenticated(); if ($u === null || !$u->id()) { die('Auth required'); } }
/** * @param RequestInterface $request The request. * @param User $u The user. * @return void */ public function setRememberCookie(RequestInterface $request, User $u) { $remember = $request->getParam('remember-me'); if (!$remember) { return; } $authToken = $this->modelFactory()->create('charcoal/admin/object/auth-token'); $authToken->generate($u->username()); $authToken->sendCookie(); $authToken->save(); }
/** * * @param User $user The user to send the lost-password email to. * @param string $token The lost-password token, as string. * @return void */ private function sendLostPasswordEmail(User $user, $token) { $userEmail = $user->email(); $subject = 'Charcoal lost password'; $from = '*****@*****.**'; // Create email $emailObj = $this->emailFactory->create('email'); $emailObj->setData(['campaign' => 'admin.lost-password', 'to' => $userEmail, 'subject' => $subject, 'from' => $from, 'log' => true, 'template_ident' => 'charcoal/admin/email/user.lost-password', 'template_data' => ['user' => $user, 'token' => $token->id(), 'urlResetPassword' => $this->adminUrl() . 'account/reset-password/' . $token->id(), 'expiry' => $token->expiry()->format('Y-m-d H:i:s'), 'ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '']]); $emailObj->send(); }