Auth_Jelly::auto_login PHP Method

auto_login() public method

Logs a user in, based on the authautologin Cookie.
public auto_login ( ) : boolean
return boolean
    public function auto_login()
    {
        if ($token = Cookie::get('authautologin')) {
            // Load the token and user
            $token = Jelly::select('user_token')->where('token', '=', $token)->load();
            if ($token->loaded() and $token->user->loaded()) {
                if ($token->user_agent === sha1(Request::$user_agent)) {
                    // Save the token to create a new unique token
                    $token->update();
                    // Set the new token
                    Cookie::set('authautologin', $token->token, $token->expires - time());
                    // Complete the login with the found data
                    $this->complete_login($token->user);
                    // Automatic login was successful
                    return TRUE;
                }
                // Token is invalid
                $token->delete();
            }
        }
        return FALSE;
    }