Пример #1
0
 public function showLoginAction()
 {
     // Check if we can authenticate the user with a cookie-based token
     if (null !== ($key = $this->getRememberMeKeyFromCookie())) {
         // Create the authenticator
         $authenticator = new AdminTokenAuthenticator($key);
         try {
             // If have found a user, store it in the security context
             $user = $authenticator->getAuthentifiedUser();
             $this->getSecurityContext()->setAdminUser($user);
             $this->adminLogAppend("admin", "LOGIN", "Successful token authentication");
             // Update the cookie
             $this->createAdminRememberMeCookie($user);
             $this->applyUserLocale($user);
             // Render the home page
             return $this->render("home");
         } catch (TokenAuthenticationException $ex) {
             $this->adminLogAppend("admin", "LOGIN", "Token based authentication failed.");
             // Clear the cookie
             $this->clearRememberMeCookie();
         }
     }
     return $this->render("login");
 }
Пример #2
0
 /**
  * @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);
         }
     }
 }