123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?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;
-
- protected 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::remember($user);
- return true;
- }
- }
- return false;
- }
-
- public static function remember($user)
- {
- static::$user = $user;
- Session::put(static::$key, $user->id);
- }
-
- public static function logout()
- {
- static::$user = null;
- Session::forget(static::$key);
- }
- }
|