public function checkLoginAction() { $request = $this->getRequest(); $adminLoginForm = new AdminLogin($request); try { $form = $this->validateForm($adminLoginForm, "post"); $authenticator = new AdminUsernamePasswordFormAuthenticator($request, $adminLoginForm); $user = $authenticator->getAuthentifiedUser(); // Success -> store user in security context $this->getSecurityContext()->setAdminUser($user); // Log authentication success AdminLog::append("admin", "LOGIN", "Authentication successful", $request, $user, false); $this->applyUserLocale($user); /** * we have tou find a way to send cookie */ if (intval($form->get('remember_me')->getData()) > 0) { // If a remember me field if present and set in the form, create // the cookie thant store "remember me" information $this->createRememberMeCookie($user, $this->getRememberMeCookieName(), $this->getRememberMeCookieExpiration()); } $this->dispatch(TheliaEvents::ADMIN_LOGIN); // Redirect to the success URL, passing the cookie if one exists. return $this->generateSuccessRedirect($adminLoginForm); } catch (FormValidationException $ex) { // Validation problem $message = $this->createStandardFormValidationErrorMessage($ex); } catch (AuthenticationException $ex) { // Log authentication failure AdminLog::append("admin", "LOGIN", sprintf("Authentication failure for username '%s'", $authenticator->getUsername()), $request); $message = $this->getTranslator()->trans("Login failed. Please check your username and password."); } catch (\Exception $ex) { // Log authentication failure AdminLog::append("admin", "LOGIN", sprintf("Undefined error: %s", $ex->getMessage()), $request); $message = $this->getTranslator()->trans("Unable to process your request. Please try again (%err).", array("%err" => $ex->getMessage())); } $this->setupFormErrorContext("Login process", $message, $adminLoginForm, $ex); // Display the login form again return $this->render("login"); }
/** * @param $request * @param $session */ protected function getRememberMeAdmin(Request $request, Session $session) { // try to get the remember me cookie $cookieAdminName = ConfigQuery::read('admin_remember_me_cookie_name', 'armcn'); $cookie = $this->getRememberMeKeyFromCookie($request, $cookieAdminName); if (null !== $cookie) { // try to log $authenticator = new AdminTokenAuthenticator($cookie); try { // If have found a user, store it in the security context $user = $authenticator->getAuthentifiedUser(); $session->setAdminUser($user); $this->applyUserLocale($user, $session); AdminLog::append("admin", "LOGIN", "Authentication successful", $request, $user, false); } catch (TokenAuthenticationException $ex) { AdminLog::append("admin", "LOGIN", "Token based authentication failed.", $request); // Clear the cookie $this->clearRememberMeCookie($cookieAdminName); } } }
/** * Helper to append a message to the admin log. * * @param string $resource * @param string $action * @param string $message */ public function adminLogAppend($resource, $action, $message, $resourceId = null) { AdminLog::append($resource, $action, $message, $this->getRequest(), $this->getSecurityContext()->getAdminUser(), true, $resourceId); }