Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 41 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
SignUpWaitEmailsEntityDao | |
0.00% |
0 / 41 |
|
0.00% |
0 / 5 |
30 | |
0.00% |
0 / 1 |
selectExistsToken | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
selectEmail | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
selectLikeEmails | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
insertEmail | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
deleteToken | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Models\Dao\Entities; |
6 | |
7 | use PeServer\Core\Database\DaoBase; |
8 | use PeServer\Core\Database\DaoTrait; |
9 | use PeServer\Core\Database\DatabaseRowResult; |
10 | use PeServer\Core\Database\DatabaseTableResult; |
11 | use PeServer\Core\Database\IDatabaseContext; |
12 | |
13 | class SignUpWaitEmailsEntityDao extends DaoBase |
14 | { |
15 | use DaoTrait; |
16 | |
17 | #region function |
18 | |
19 | public function selectExistsToken(string $token, int $limitMinutes): bool |
20 | { |
21 | return 1 === $this->context->selectSingleCount( |
22 | <<<SQL |
23 | |
24 | select |
25 | count(*) |
26 | from |
27 | sign_up_wait_emails |
28 | where |
29 | sign_up_wait_emails.token = :token |
30 | and |
31 | (STRFTIME('%s', CURRENT_TIMESTAMP) - STRFTIME('%s', sign_up_wait_emails.timestamp)) < :limit_minutes * 60 |
32 | |
33 | SQL, |
34 | [ |
35 | 'token' => $token, |
36 | 'limit_minutes' => $limitMinutes, |
37 | ] |
38 | ); |
39 | } |
40 | |
41 | public function selectEmail(string $token): string |
42 | { |
43 | /** @phpstan-var DatabaseRowResult<array{email:string}> */ |
44 | $result = $this->context->querySingle( |
45 | <<<SQL |
46 | |
47 | select |
48 | sign_up_wait_emails.email |
49 | from |
50 | sign_up_wait_emails |
51 | where |
52 | sign_up_wait_emails.token = :token |
53 | |
54 | SQL, |
55 | [ |
56 | 'token' => $token, |
57 | ] |
58 | ); |
59 | |
60 | return $result->fields['email']; |
61 | } |
62 | |
63 | /** |
64 | * @template TFieldArray of array{mark_email:int,token:string,email:string} |
65 | * @param int $markEmail |
66 | * @phpstan-return DatabaseTableResult<TFieldArray> |
67 | */ |
68 | public function selectLikeEmails(int $markEmail): DatabaseTableResult |
69 | { |
70 | /** @phpstan-var DatabaseTableResult<TFieldArray> */ |
71 | return $this->context->query( |
72 | <<<SQL |
73 | |
74 | select |
75 | sign_up_wait_emails.mark_email, |
76 | sign_up_wait_emails.token, |
77 | sign_up_wait_emails.email |
78 | from |
79 | sign_up_wait_emails |
80 | where |
81 | sign_up_wait_emails.mark_email = :mark_email |
82 | |
83 | SQL, |
84 | [ |
85 | 'mark_email' => $markEmail, |
86 | ] |
87 | ); |
88 | } |
89 | |
90 | public function insertEmail(string $token, string $email, int $markEmail, string $ipAddress, string $userAgent): void |
91 | { |
92 | $this->context->insertSingle( |
93 | <<<SQL |
94 | |
95 | insert into |
96 | sign_up_wait_emails |
97 | ( |
98 | token, |
99 | email, |
100 | mark_email, |
101 | timestamp, |
102 | ip_address, |
103 | user_agent |
104 | ) |
105 | values |
106 | ( |
107 | :token, |
108 | :email, |
109 | :mark_email, |
110 | CURRENT_TIMESTAMP, |
111 | :ip_address, |
112 | :user_agent |
113 | ) |
114 | |
115 | SQL, |
116 | [ |
117 | 'token' => $token, |
118 | 'email' => $email, |
119 | 'mark_email' => $markEmail, |
120 | 'ip_address' => $ipAddress, |
121 | 'user_agent' => $userAgent, |
122 | ] |
123 | ); |
124 | } |
125 | |
126 | public function deleteToken(string $token): void |
127 | { |
128 | $this->context->deleteByKey( |
129 | <<<SQL |
130 | |
131 | delete |
132 | from |
133 | sign_up_wait_emails |
134 | where |
135 | sign_up_wait_emails.token = :token |
136 | |
137 | SQL, |
138 | [ |
139 | 'token' => $token, |
140 | ] |
141 | ); |
142 | } |
143 | |
144 | #endregion |
145 | } |