public function auto_login()
{
if ($token = Cookie::get($this->_config['autologin_key'])) {
// Load the token and user
$token = ORM::factory('user_token', array('token' => $token));
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->save();
// Set the new token
Cookie::set($this->_config['autologin_key'], $token->token, $token->expires - time());
// Complete the login with the found data
$this->complete_login($token->user);
// Automatic login was successful
return $token->user;
}
// Token is invalid
$token->delete();
}
}
return FALSE;
}