auth.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. return array(
  3. /*
  4. |--------------------------------------------------------------------------
  5. | Authentication Username
  6. |--------------------------------------------------------------------------
  7. |
  8. } This option should be set to the "username" property of your users.
  9. | Typically, this will be set to "email" or "username".
  10. |
  11. | The value of this property will be used by the "attempt" closure when
  12. | searching for users by their username. It will also be used when the
  13. | user is set to be "remembered", as the username is embedded into the
  14. | encrypted cookie and is used to verify the user's identity.
  15. |
  16. */
  17. 'username' => 'email',
  18. /*
  19. |--------------------------------------------------------------------------
  20. | Retrieve The Current User
  21. |--------------------------------------------------------------------------
  22. |
  23. | This closure is called by the Auth::user() method when attempting to
  24. | retrieve a user by their ID stored in the session.
  25. |
  26. | Simply return an object representing the user with the given ID. Or, if
  27. | no user with the given ID is registered to use your application, you do
  28. | not need to return anything.
  29. |
  30. | Of course, a simple, elegant authentication solution is already provided
  31. | for you using Eloquent and the default Laravel hashing engine.
  32. |
  33. */
  34. 'user' => function($id)
  35. {
  36. if ( ! is_null($id) and filter_var($id, FILTER_VALIDATE_INT) !== false)
  37. {
  38. return User::find($id);
  39. }
  40. },
  41. /*
  42. |--------------------------------------------------------------------------
  43. | Authenticate User Credentials
  44. |--------------------------------------------------------------------------
  45. |
  46. | This closure is called by the Auth::attempt() method when attempting to
  47. | authenticate a user that is logging into your application.
  48. |
  49. | If the provided credentials are correct, simply return an object that
  50. | represents the user being authenticated. If the credentials are not
  51. | valid, don't return anything.
  52. |
  53. | Note: If a user object is returned, it must have an "id" property.
  54. |
  55. */
  56. 'attempt' => function($username, $password, $config)
  57. {
  58. $user = User::where($config['username'], '=', $username)->first();
  59. if ( ! is_null($user) and Hash::check($password, $user->password))
  60. {
  61. return $user;
  62. }
  63. },
  64. /*
  65. |--------------------------------------------------------------------------
  66. | Logout
  67. |--------------------------------------------------------------------------
  68. |
  69. | Here you may do anything that needs to be done when a user logs out of
  70. | your application, such as call the logout method on a third-party API
  71. | you are using for authentication, or anything else you desire.
  72. |
  73. */
  74. 'logout' => function($user) {}
  75. );