eloquent.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. if ( ! is_null($user) and Hash::check($password, $user->password))
  33. {
  34. return $this->login($user->id, array_get($arguments, 'remember'));
  35. }
  36. return false;
  37. }
  38. /**
  39. * Get a fresh model instance.
  40. *
  41. * @return Eloquent
  42. */
  43. protected function model()
  44. {
  45. $model = Config::get('auth.model');
  46. return new $model;
  47. }
  48. }