1: <?php namespace Laravel\Auth\Drivers; use Laravel\Hash, Laravel\Config;
2:
3: class Eloquent extends Driver {
4:
5: 6: 7: 8: 9: 10: 11: 12:
13: public function retrieve($token)
14: {
15:
16:
17: if (filter_var($token, FILTER_VALIDATE_INT) !== false)
18: {
19: return $this->model()->find($token);
20: }
21: else if (is_object($token) and get_class($token) == Config::get('auth.model'))
22: {
23: return $token;
24: }
25: }
26:
27: 28: 29: 30: 31: 32:
33: public function attempt($arguments = array())
34: {
35: $user = $this->model()->where(function($query) use($arguments)
36: {
37: $username = Config::get('auth.username');
38:
39: $query->where($username, '=', $arguments['username']);
40:
41: foreach(array_except($arguments, array('username', 'password', 'remember')) as $column => $val)
42: {
43: $query->where($column, '=', $val);
44: }
45: })->first();
46:
47:
48:
49: $password = $arguments['password'];
50:
51: $password_field = Config::get('auth.password', 'password');
52:
53: if ( ! is_null($user) and Hash::check($password, $user->{$password_field}))
54: {
55: return $this->login($user->get_key(), array_get($arguments, 'remember'));
56: }
57:
58: return false;
59: }
60:
61: 62: 63: 64: 65:
66: protected function model()
67: {
68: $model = Config::get('auth.model');
69:
70: return new $model;
71: }
72:
73: }
74: