eloquent.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php namespace Laravel\Auth\Drivers; use Laravel\Hash, Laravel\Config;
  2. class Eloquent extends Driver {
  3. /**
  4. * Get the current user of the application.
  5. *
  6. * If the user is a guest, null should be returned.
  7. *
  8. * @param int $id
  9. * @return mixed|null
  10. */
  11. public function retrieve($id)
  12. {
  13. if (filter_var($id, FILTER_VALIDATE_INT) !== false)
  14. {
  15. return $this->model()->find($id);
  16. }
  17. }
  18. /**
  19. * Attempt to log a user into the application.
  20. *
  21. * @param array $arguments
  22. * @return void
  23. */
  24. public function attempt($arguments = array())
  25. {
  26. $username = Config::get('auth.username');
  27. $user = $this->model()->where($username, '=', $arguments['username'])->first();
  28. // This driver uses a basic username and password authentication scheme
  29. // so if the credentials match what is in the database we will just
  30. // log the user into the application and remember them if asked.
  31. $password = $arguments['password'];
  32. $password_field = Config::get('auth.password');
  33. if ( ! is_null($user) and Hash::check($password, $user->get_attribute($password_field)))
  34. {
  35. return $this->login($user->id, array_get($arguments, 'remember'));
  36. }
  37. return false;
  38. }
  39. /**
  40. * Get a fresh model instance.
  41. *
  42. * @return Eloquent
  43. */
  44. protected function model()
  45. {
  46. $model = Config::get('auth.model');
  47. return new $model;
  48. }
  49. }