1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php namespace System;
- if (Config::get('session.driver') == '')
- {
- throw new \Exception("You must specify a session driver before using the Auth class.");
- }
- class Auth {
-
- public static $user;
-
- private static $key = 'laravel_user_id';
-
- public static function check()
- {
- return ( ! is_null(static::user()));
- }
-
- 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;
- }
-
- 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::$user = $user;
- Session::put(static::$key, $user->id);
- return true;
- }
- }
- return false;
- }
-
- public static function logout()
- {
- Session::forget(static::$key);
- static::$user = null;
- }
- }
|