Exemplo n.º 1
0
 /**
  * Logs on using the information in the coookies
  *
  * @return Phalcon\Http\Response
  */
 public function loginWithRememberMe()
 {
     $userId = $this->cookies->get('RMU')->getValue();
     $cookieToken = $this->cookies->get('RMT')->getValue();
     $user = Users::findFirstById($userId);
     if ($user) {
         $userAgent = $this->request->getUserAgent();
         $token = md5($user->email . $user->password . $userAgent);
         if ($cookieToken == $token) {
             $remember = RememberTokens::findFirst(array('usersid = ?0 AND token = ?1', 'bind' => array($user->id, $token)));
             if ($remember) {
                 // Check if the cookie has not expired
                 if (($this->config->database->adapter == 'Postgresql' ? date('d/m/Y H:i:s', strtotime('-8 Days')) : time() - 86400 * 8) < $remember->createdAt) {
                     // Check if the user was flagged
                     $this->checkUserFlags($user);
                     // Register identity
                     $this->session->set('auth-identity', array('id' => $user->id, 'name' => $user->name, 'profile' => $user->profile->name));
                     // Register the successful login
                     $this->saveSuccessLogin($user);
                     return $this->response->redirect('users');
                 }
             }
         }
     }
     $this->cookies->get('RMU')->delete();
     $this->cookies->get('RMT')->delete();
     return $this->response->redirect('session/login');
 }