Added first draft of remember me to auth.
This commit is contained in:
parent
8c9bd12003
commit
b6537da8b6
|
@ -52,6 +52,15 @@ public static function user()
|
|||
|
||||
$id = IoC::container()->core('session')->get(Auth::user_key);
|
||||
|
||||
if (is_null($id) AND ! is_null($cookie = strrev(Crypter::decrypt(\Cookie::get('remember')))))
|
||||
{
|
||||
$cookie = explode('|', $cookie);
|
||||
if ($cookie[2] == md5(\Request::server('HTTP_USER_AGENT')))
|
||||
{
|
||||
$id = $cookie[0];
|
||||
}
|
||||
}
|
||||
|
||||
return static::$user = call_user_func(Config::get('auth.user'), $id);
|
||||
}
|
||||
|
||||
|
@ -65,12 +74,14 @@ public static function user()
|
|||
* @param string $password
|
||||
* @return bool
|
||||
*/
|
||||
public static function attempt($username, $password = null)
|
||||
public static function attempt($username, $password = null, $remember = false)
|
||||
{
|
||||
if ( ! is_null($user = call_user_func(Config::get('auth.attempt'), $username, $password)))
|
||||
{
|
||||
static::login($user);
|
||||
|
||||
if ($remember) static::remember($user);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -108,4 +119,15 @@ public static function logout()
|
|||
IoC::container()->core('session')->forget(Auth::user_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a cookie so that users are remembered.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function remember($user)
|
||||
{
|
||||
static::$user = $user;
|
||||
$cookie = Crypter::encrypt(strrev($user->id.'|'.\Request::ip().'|'.md5(\Request::server('HTTP_USER_AGENT')).'|'.time()));
|
||||
\Cookie::put('remember', $cookie, 60);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue