|
1
|
|
|
<?php namespace Cerbero\Auth\Repositories; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Eloquent repository for users. |
|
5
|
|
|
* |
|
6
|
|
|
* @author Andrea Marco Sartori |
|
7
|
|
|
*/ |
|
8
|
|
|
class EloquentUserRepository implements UserRepositoryInterface { |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @author Andrea Marco Sartori |
|
12
|
|
|
* @var User $user User model. |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $user; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Set the dependencies. |
|
18
|
|
|
* |
|
19
|
|
|
* @author Andrea Marco Sartori |
|
20
|
|
|
* @return void |
|
21
|
|
|
*/ |
|
22
|
|
|
public function __construct() |
|
23
|
|
|
{ |
|
24
|
|
|
$user = config('auth.model'); |
|
25
|
|
|
|
|
26
|
|
|
$this->user = new $user; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Register a new user. |
|
31
|
|
|
* |
|
32
|
|
|
* @author Andrea Marco Sartori |
|
33
|
|
|
* @param array $attributes |
|
34
|
|
|
* @return User |
|
35
|
|
|
*/ |
|
36
|
|
|
public function register(array $attributes) |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->user->create($attributes); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Assign a token to reset the password of the user with the given email. |
|
43
|
|
|
* |
|
44
|
|
|
* @author Andrea Marco Sartori |
|
45
|
|
|
* @param string $token |
|
46
|
|
|
* @param string $email |
|
47
|
|
|
* @return void |
|
48
|
|
|
*/ |
|
49
|
|
|
public function assignResetToken($token, $email) |
|
50
|
|
|
{ |
|
51
|
|
|
$user = $this->user->whereEmail($email)->first(); |
|
52
|
|
|
|
|
53
|
|
|
$user->reset_token = $token; |
|
54
|
|
|
|
|
55
|
|
|
$user->save(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Retrieve the user with the given reset token. |
|
60
|
|
|
* |
|
61
|
|
|
* @author Andrea Marco Sartori |
|
62
|
|
|
* @param string $token |
|
63
|
|
|
* @return User|null |
|
64
|
|
|
*/ |
|
65
|
|
|
public function findByResetToken($token) |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->user->whereResetToken($token)->first(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Reset the password of the given user. |
|
72
|
|
|
* |
|
73
|
|
|
* @author Andrea Marco Sartori |
|
74
|
|
|
* @param User $user |
|
75
|
|
|
* @param string $password |
|
76
|
|
|
* @return boolean |
|
77
|
|
|
*/ |
|
78
|
|
|
public function resetPassword($user, $password) |
|
79
|
|
|
{ |
|
80
|
|
|
$user->password = $password; |
|
81
|
|
|
|
|
82
|
|
|
$user->reset_token = null; |
|
83
|
|
|
|
|
84
|
|
|
$user->save(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|