Example #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;
 }
Example #2
0
 /**
  * Tries to "auto-login" the user by searching for the user's
  * auto login cookie in their browser.
  * 
  * @return boolean
  */
 public function auto_login()
 {
     if ($token = cookie::get($this->config['auto_login_cookie'])) {
         // 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 user id
                 $user_id = $token->user_id;
                 // Delete old token
                 $token->delete();
                 // Create a new user
                 $user = new Model_User($user_id);
                 // Remember User
                 $this->_remember_user($user);
                 // Complete the login
                 $this->complete_login($user);
                 // Automatic login was successful
                 return TRUE;
             } else {
                 // Token is invalid
                 $token->delete();
             }
         }
     }
     return FALSE;
 }