From bbffa96c2d21285b4a287b4198aab03754a70b92 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 16 Nov 2011 22:57:56 -0600 Subject: [PATCH] refactoring the auth login method. allow the developer to just pass an integer. --- laravel/auth.php | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/laravel/auth.php b/laravel/auth.php index d9f1dac6..16d1cd40 100644 --- a/laravel/auth.php +++ b/laravel/auth.php @@ -72,6 +72,8 @@ class Auth { static::$user = call_user_func(Config::get('auth.user'), $id); + // If the user was not found in the database, but a "remember me" cookie + // exists, we will attempt to recall the user based on the cookie value. if (is_null(static::$user) and ! is_null($cookie = Cookie::get(Auth::remember_key))) { static::$user = static::recall($cookie); @@ -136,17 +138,32 @@ class Auth { /** * Log a user into the application. * - * @param object $user - * @param bool $remember + * An object representing the user or an integer user ID may be given to the method. + * If an object is given, the object must have an "id" property containing the user + * ID as it is stored in the database. + * + * + * // Login a user by passing a user object + * Auth::login($user); + * + * // Login the user with an ID of 15 + * Auth::login(15); + * + * // Login a user and set a "remember me" cookie + * Auth::login($user, true); + * + * + * @param object|int $user + * @param bool $remember * @return void */ public static function login($user, $remember = false) { - static::$user = $user; + $id = (is_object($user)) ? $user->id : (int) $user; - if ($remember) static::remember($user->id); + if ($remember) static::remember($id); - IoC::core('session')->put(Auth::user_key, $user->id); + IoC::core('session')->put(Auth::user_key, $id); } /**