Ejemplo n.º 1
0
 public function auto_login()
 {
     if ($token = cookie::get('authautologin')) {
         // Load the token and user
         $token = new Model_UserToken($token);
         if ($token->id > 0 && $token->user_id > 0) {
             if ($token->user_agent === sha1(Eight::$user_agent)) {
                 // Save the token to create a new unique token
                 $token->save();
                 // Set the new token
                 cookie::set('authautologin', $token->token, $token->expires - time());
                 // Complete the login with the found data
                 $user = new Model_User($token->user_id);
                 $this->complete_login($user);
                 // Automatic login was successful
                 return TRUE;
             }
             // Token is invalid
             $token->delete();
         }
     }
     return FALSE;
 }
Ejemplo n.º 2
0
 /**
  * Stores a cookie to remember the specified user
  */
 private function _remember_user(Model_User $user)
 {
     // Create a new autologin token
     $token = new Model_UserToken();
     // Set token data
     $token->user_id = $user->id;
     $token->expires = time() + $this->config['lifetime'];
     $token->save();
     // Set the auto login cookie
     cookie::set($this->config['auto_login_cookie'], $token->token, $this->config['lifetime']);
     return $token;
 }