simplified hashing. re-worked the auth class for a little more flexibility.

This commit is contained in:
Taylor Otwell
2011-09-11 22:44:01 -05:00
parent 7f2e1e9ca0
commit 9db8e1bb6c
4 changed files with 67 additions and 115 deletions

View File

@@ -4,41 +4,61 @@ return array(
/*
|--------------------------------------------------------------------------
| Retrieve Users By ID
| Retrieve The Current User
|--------------------------------------------------------------------------
|
| This method is called by the Auth::user() method when attempting to
| retrieve a user by their user ID, such as when retrieving a user by the
| user ID stored in the session.
| This closure is called by the Auth::user() method when attempting to
| retrieve a user by their ID stored in the session.
|
| You are free to change this method for your application however you wish.
| Simply return an object representing the user with the given ID. Or, if
| no user with the given ID is registered to use your application, you do
| not need to return anything.
|
| Of course, a simple, elegant authentication solution is already provided
| for you using Eloquent and the default Laravel hashing engine.
|
*/
'by_id' => function($id)
'user' => function($id)
{
return User::find($id);
if ( ! is_null($id)) return User::find($id);
},
/*
|--------------------------------------------------------------------------
| Retrieve Users By Username
| Authenticate User Credentials
|--------------------------------------------------------------------------
|
| This method is called by the Auth::check() method when attempting to
| retrieve a user by their username, such as when checking credentials
| received from a login form.
| This closure is called by the Auth::attempt() method when attempting to
| authenticate a user that is logging into your application.
|
| You are free to change this method for your application however you wish.
| If the provided credentials are correct, simply return an object that
| represents the user being authenticated. If the credentials are not
| valid, don't return anything.
|
| Note: This method must return an object that has "id" and "password"
| properties. The type of object returned does not matter.
| Note: If a user object is returned, it must have an "id" property.
|
*/
'by_username' => function($username)
'attempt' => function($username, $password)
{
return User::where_email($username)->first();
if ( ! is_null($user = User::where('email', '=', $username)->first()))
{
if (Hasher::check($password, $user->password)) return $user;
}
},
/*
|--------------------------------------------------------------------------
| Logout
|--------------------------------------------------------------------------
|
| 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.
|
*/
'logout' => function($id) {}
);