1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* NOTICE OF LICENSE |
5
|
|
|
* |
6
|
|
|
* Part of the Rinvex Fort Package. |
7
|
|
|
* |
8
|
|
|
* This source file is subject to The MIT License (MIT) |
9
|
|
|
* that is bundled with this package in the LICENSE file. |
10
|
|
|
* |
11
|
|
|
* Package: Rinvex Fort Package |
12
|
|
|
* License: The MIT License (MIT) |
13
|
|
|
* Link: https://rinvex.com |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace Rinvex\Fort\Repositories; |
17
|
|
|
|
18
|
|
|
use Rinvex\Fort\Contracts\CanResetPasswordContract; |
19
|
|
|
use Rinvex\Fort\Contracts\ResetTokenRepositoryContract; |
20
|
|
|
|
21
|
|
|
class ResetTokenRepository extends AbstractTokenRepository implements ResetTokenRepositoryContract |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
|
|
public function create(CanResetPasswordContract $user) |
27
|
|
|
{ |
28
|
|
|
$email = $user->getEmailForPasswordReset(); |
29
|
|
|
$agent = request()->server('HTTP_USER_AGENT'); |
30
|
|
|
$ip = request()->ip(); |
|
|
|
|
31
|
|
|
|
32
|
|
|
$this->deleteExisting($user); |
33
|
|
|
|
34
|
|
|
// We will create a new, random token for the user so that we can e-mail them |
35
|
|
|
// a safe link to the password reset form. Then we will insert a record in |
36
|
|
|
// the database so that we can verify the token within the actual reset. |
37
|
|
|
$token = $this->createNewToken(); |
38
|
|
|
|
39
|
|
|
$this->getTable()->insert($this->getPayload($email, $token, $agent, $ip)); |
40
|
|
|
|
41
|
|
|
return $token; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
|
|
public function exists(CanResetPasswordContract $user, $token) |
48
|
|
|
{ |
49
|
|
|
$email = $user->getEmailForPasswordReset(); |
50
|
|
|
|
51
|
|
|
$token = (array) $this->getTable()->where('email', $email)->where('token', $token)->first(); |
52
|
|
|
|
53
|
|
|
return $token && ! $this->tokenExpired($token); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
|
|
protected function deleteExisting(CanResetPasswordContract $user) |
60
|
|
|
{ |
61
|
|
|
return $this->getTable()->where('email', $user->getEmailForPasswordReset())->delete(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
|
|
public function getData(CanResetPasswordContract $user, $token) |
68
|
|
|
{ |
69
|
|
|
$email = $user->getEmailForPasswordReset(); |
70
|
|
|
|
71
|
|
|
return (array) $this->getTable()->where('email', $email)->where('token', $token)->first(); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.