fluent.php 1.4 KB

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