* $email = Auth::user()->email; * * * @return object */ public static function user() { if (is_null(static::$user) and Session::has(static::$key)) { static::$user = call_user_func(Config::get('auth.by_id'), Session::get(static::$key)); } return static::$user; } /** * Attempt to log a user into your application. * * If the user credentials are valid. The user's ID will be stored in the session and the * user will be considered "logged in" on subsequent requests to the application. * * The password passed to the method should be plain text, as it will be hashed * by the Hash class when authenticating. * * * if (Auth::login('email@example.com', 'password')) * { * // The credentials are valid and the user is now logged in. * } * * * @param string $username * @param string $password * @return bool */ public static function login($username, $password) { if ( ! is_null($user = call_user_func(Config::get('auth.by_username'), $username))) { if (Hash::check($password, $user->password)) { static::remember($user); return true; } } return false; } /** * Log a user into your application. * * The user's ID will be stored in the session and the user will be considered * "logged in" on subsequent requests to your application. This method is called * by the login method after determining a user's credentials are valid. * * Note: The user given to this method should be an object having an "id" property. * * @param object $user * @return void */ public static function remember($user) { static::$user = $user; Session::put(static::$key, $user->id); } /** * Log the user out of your application. * * The user ID will be removed from the session and the user will no longer * be considered logged in on subsequent requests to your application. * * @return void */ public static function logout() { static::$user = null; Session::forget(static::$key); } }