1 | <?php |
||
28 | class PasswordResetBroker implements PasswordBrokerContract |
||
29 | { |
||
30 | /** |
||
31 | * The password token repository. |
||
32 | * |
||
33 | * @var \Illuminate\Auth\Passwords\TokenRepositoryInterface |
||
34 | */ |
||
35 | protected $tokens; |
||
36 | |||
37 | /** |
||
38 | * The user provider implementation. |
||
39 | * |
||
40 | * @var \Illuminate\Contracts\Auth\UserProvider |
||
41 | */ |
||
42 | protected $users; |
||
43 | |||
44 | /** |
||
45 | * The custom password validator callback. |
||
46 | * |
||
47 | * @var \Closure |
||
48 | */ |
||
49 | protected $passwordValidator; |
||
50 | |||
51 | /** |
||
52 | * Create a new password broker instance. |
||
53 | * |
||
54 | * @param \Rinvex\Fort\Contracts\PasswordResetTokenRepositoryContract $tokens |
||
55 | * @param \Illuminate\Contracts\Auth\UserProvider $users |
||
56 | */ |
||
57 | public function __construct(PasswordResetTokenRepositoryContract $tokens, UserProvider $users) |
||
58 | { |
||
59 | $this->users = $users; |
||
60 | $this->tokens = $tokens; |
||
|
|||
61 | } |
||
62 | |||
63 | /** |
||
64 | * Send a password reset link to a user. |
||
65 | * |
||
66 | * @param array $credentials |
||
67 | * |
||
68 | * @return string |
||
69 | */ |
||
70 | public function sendResetLink(array $credentials) |
||
71 | { |
||
72 | // First we will check to see if we found a user at the given credentials and |
||
73 | // if we did not we will redirect back to this current URI with a piece of |
||
74 | // "flash" data in the session to indicate to the developers the errors. |
||
75 | $user = $this->getUser($credentials); |
||
76 | |||
77 | if (is_null($user)) { |
||
78 | return static::INVALID_USER; |
||
79 | } |
||
80 | |||
81 | // Once we have the reset password token, we are ready to send the message out |
||
82 | // to this user with a link for password. We will then redirect back to the |
||
83 | // current URI having nothing set in the session to indicate errors. |
||
84 | $data = $this->tokens->getData($user, $token = $this->tokens->create($user)); |
||
85 | $expiration = $this->tokens->getExpiration(); |
||
86 | |||
87 | // Returned token is hashed, and we need the |
||
88 | // public token to be sent to the user |
||
89 | $data['token'] = $token; |
||
90 | |||
91 | $user->sendPasswordResetNotification($data, $expiration); |
||
92 | |||
93 | return static::RESET_LINK_SENT; |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * Reset the password for the given token. |
||
98 | * |
||
99 | * @param array $credentials |
||
100 | * @param \Closure $callback |
||
101 | * |
||
102 | * @return mixed |
||
103 | */ |
||
104 | public function reset(array $credentials, Closure $callback) |
||
105 | { |
||
106 | // If the responses from the validate method is not a user instance, we will |
||
107 | // assume that it is a redirect and simply return it from this method and |
||
108 | // the user is properly redirected having an error message on the post. |
||
109 | $user = $this->validateReset($credentials); |
||
110 | |||
111 | if (! $user instanceof CanResetPasswordContract) { |
||
112 | return $user; |
||
113 | } |
||
114 | |||
115 | $password = $credentials['password']; |
||
116 | |||
117 | // Once the reset has been validated, we'll call the given callback with the |
||
118 | // new password. This gives the user an opportunity to store the password |
||
119 | // in their persistent storage. Then we'll delete the token and return. |
||
120 | $callback($user, $password); |
||
121 | |||
122 | $this->tokens->delete($user); |
||
123 | |||
124 | return static::PASSWORD_RESET; |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * Set a custom password validator. |
||
129 | * |
||
130 | * @param \Closure $callback |
||
131 | * |
||
132 | * @return void |
||
133 | */ |
||
134 | public function validator(Closure $callback) |
||
138 | |||
139 | /** |
||
140 | * Determine if the passwords match for the request. |
||
141 | * |
||
142 | * @param array $credentials |
||
143 | * |
||
144 | * @return bool |
||
145 | */ |
||
146 | public function validateNewPassword(array $credentials) |
||
161 | |||
162 | /** |
||
163 | * Determine if the passwords are valid for the request. |
||
164 | * |
||
165 | * @param array $credentials |
||
166 | * |
||
167 | * @return bool |
||
168 | */ |
||
169 | protected function validatePasswordWithDefaults(array $credentials) |
||
178 | |||
179 | /** |
||
180 | * Get the user for the given credentials. |
||
181 | * |
||
182 | * @param array $credentials |
||
183 | * |
||
184 | * @throws \UnexpectedValueException |
||
185 | * |
||
186 | * @return \Rinvex\Fort\Contracts\CanResetPasswordContract |
||
187 | */ |
||
188 | public function getUser(array $credentials) |
||
200 | |||
201 | /** |
||
202 | * Create a new password reset token for the given user. |
||
203 | * |
||
204 | * @param CanResetPasswordContract $user |
||
205 | * |
||
206 | * @return string |
||
207 | */ |
||
208 | public function createToken(CanResetPasswordContract $user) |
||
212 | |||
213 | /** |
||
214 | * Delete password reset tokens of the given user. |
||
215 | * |
||
216 | * @param \Illuminate\Contracts\Auth\CanResetPassword $user |
||
217 | * |
||
218 | * @return void |
||
219 | */ |
||
220 | public function deleteToken(CanResetPasswordContract $user) |
||
224 | |||
225 | /** |
||
226 | * Validate the given password reset token. |
||
227 | * |
||
228 | * @param \Rinvex\Fort\Contracts\CanResetPasswordContract $user |
||
229 | * @param string $token |
||
230 | * |
||
231 | * @return bool |
||
232 | */ |
||
233 | public function tokenExists(CanResetPasswordContract $user, $token) |
||
237 | |||
238 | /** |
||
239 | * Get the password reset token repository implementation. |
||
240 | * |
||
241 | * @return \Illuminate\Auth\Passwords\TokenRepositoryInterface |
||
242 | */ |
||
243 | public function getRepository() |
||
247 | |||
248 | /** |
||
249 | * Validate a password reset for the given credentials. |
||
250 | * |
||
251 | * @param array $credentials |
||
252 | * |
||
253 | * @return \Illuminate\Contracts\Auth\CanResetPassword|string |
||
254 | */ |
||
255 | protected function validateReset(array $credentials) |
||
271 | } |
||
272 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..