|
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\CanVerifyEmailContract; |
|
19
|
|
|
use Rinvex\Fort\Contracts\VerificationTokenRepositoryContract; |
|
20
|
|
|
|
|
21
|
|
|
class VerificationTokenRepository extends AbstractTokenRepository implements VerificationTokenRepositoryContract |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritdoc} |
|
25
|
|
|
*/ |
|
26
|
|
|
public function create(CanVerifyEmailContract $user) |
|
27
|
|
|
{ |
|
28
|
|
|
$email = $user->getEmailForVerification(); |
|
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 for verification. Then we will insert a record in database |
|
36
|
|
|
// so that we can verify the token within the actual verification. |
|
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(CanVerifyEmailContract $user, $token) |
|
48
|
|
|
{ |
|
49
|
|
|
$email = $user->getEmailForVerification(); |
|
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(CanVerifyEmailContract $user) |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->getTable()->where('email', $user->getEmailForVerification())->delete(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* {@inheritdoc} |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getData(CanVerifyEmailContract $user, $token) |
|
68
|
|
|
{ |
|
69
|
|
|
$email = $user->getEmailForVerification(); |
|
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.