<?php
// 路径 application/config/auth.php
return array(
/*
|--------------------------------------------------------------------------
| Retrieve The Current User
|--------------------------------------------------------------------------
| 获取当前用户
| This closure is called by the Auth class' "user" method when trying to
| retrieve a user by the ID that is stored in their session. If you find
| the user, just return the user object, but make sure it has an "id"
| property. If you can't find the user, just return null.
| 当尝试通过存储在session中的ID获取一个用户的时候,这个闭包被Auth类的user方法调用。
| 如果找到这个用户,就会返回一个用户对象,但是请确认它有一个id属性。如果没有找到这个用户,就返回null。
|
| Of course, a simple and elegant authentication solution has already
| been provided for you using the query builder and hashing engine.
| We love making your life as easy as possible.
| 当然,一个简单的和优雅的授权解决方法已经为你提供了,是通过使用查询构造器和hash引擎。 我们喜欢让你的生活变得尽可能容易。
*/
'user' => function($id)
{
// 通过过滤器判断id是否为int型
if (filter_var($id, FILTER_VALIDATE_INT) !== false)
{
// 查询指定id的用户
return DB::table('users')->find($id);
}
},
/*
|--------------------------------------------------------------------------
| Authenticate User Credentials
|--------------------------------------------------------------------------
| 验证用户凭证
| This closure is called by the Auth::attempt() method when attempting to
| authenticate a user that is logging into your application. It's like a
| super buff bouncer to your application.
| 当一个用户试图登录应用的时候,这个闭包通过Auth::attempt()方法被调用。
| If the provided credentials are correct, simply return an object that
| represents the user being authenticated. As long as it has a property
| for the "id", any object will work. If the credentials are not valid,
| you don't meed to return anything.
| 如果提供的凭证是正确的,代表被授权的一个对象将被返回。只要它有一个id属性,任何对象就是可行的。
| 如果拼争不合理,你不必返回任何东西。
*/
'attempt' => function($username, $password)
{
// 查询指定用户名的用户
$user = DB::table('users')->where_username($username)->first();
// 判断用户存在而且密码正确
if ( ! is_null($user) and Hash::check($password, $user->password))
{
return $user;
}
},
/*
|--------------------------------------------------------------------------
| Logout The Current User
|--------------------------------------------------------------------------
| 注销当前用户
| Here you may do anything that needs to be done when a user logs out of
| your application, such as call the logout method on a third-party API
| you are using for authentication or anything else you desire.
| 当一个用户退出你的应用的时候,这儿有一些需要处理的事情你可能要去做,像调用在你在使用的授权的第三方API上的退出方法,
| 或者你渴望的其他任何事情。
*/
'logout' => function($user) {},
/*
|--------------------------------------------------------------------------
| "Remember Me" Cookie Name
|--------------------------------------------------------------------------
| “记住我” Cookie名称
| Here you may specify the cookie name that will be used for the cookie
| that serves as the "remember me" token. Of course, a sensible default
| has been set for you, so you probably don't need to change it.
| 需要"记住我"的token的cookie制定cookie名。当然,这里为你设置了一个默认的,因此你可能不必改变它。
*/
'cookie' => 'laravel_remember',
);
github地址: https://github.com/liu-shilong/laravel3-scr