@@ -13,16 +13,19 @@ class DatabaseTokenRepository extends AbstractTokenRepository
13
13
{
14
14
public function __construct (
15
15
protected ConnectionInterface $ connection ,
16
- protected int $ expires ,
17
- protected int $ tokenLength ,
18
- protected string $ table
16
+ protected int $ expires ,
17
+ protected int $ tokenLength ,
18
+ protected string $ table
19
19
) {
20
20
parent ::__construct ($ expires , $ tokenLength );
21
21
}
22
22
23
- public function deleteExisting (OTPNotifiable $ user ): bool
23
+ public function deleteExisting (OTPNotifiable $ user, string $ indicator ): bool
24
24
{
25
- return (bool ) optional ($ this ->getTable ()->where ('mobile ' , $ user ->getMobileForOTPNotification ()))->delete ();
25
+ return (bool )optional ($ this ->getTable ()->where ([
26
+ 'mobile ' => $ user ->getMobileForOTPNotification (),
27
+ 'indicator ' => $ indicator ,
28
+ ]))->delete ();
26
29
}
27
30
28
31
protected function getLatestRecord (array $ filters ): ?array
@@ -32,21 +35,22 @@ protected function getLatestRecord(array $filters): ?array
32
35
->latest ()
33
36
->first ();
34
37
35
- return $ record ? (array ) $ record : null ;
38
+ return $ record ? (array )$ record : null ;
36
39
}
37
40
38
- public function exists (string $ mobile ): bool
41
+ public function exists (string $ mobile, string $ indicator ): bool
39
42
{
40
- $ record = $ this ->getLatestRecord (['mobile ' => $ mobile ]);
43
+ $ record = $ this ->getLatestRecord (['mobile ' => $ mobile, ' indicator ' => $ indicator ]);
41
44
42
45
return $ record && ! $ this ->tokenExpired ($ record ['expires_at ' ]);
43
46
}
44
47
45
- public function isTokenMatching (OTPNotifiable $ user , string $ token ): bool
48
+ public function isTokenMatching (OTPNotifiable $ user , string $ indicator , string $ token ): bool
46
49
{
47
50
$ record = $ this ->getLatestRecord ([
48
51
'mobile ' => $ user ->getMobileForOTPNotification (),
49
52
'token ' => $ token ,
53
+ 'indicator ' => $ indicator ,
50
54
]);
51
55
52
56
return $ record && ! $ this ->tokenExpired ($ record ['expires_at ' ]);
@@ -57,13 +61,14 @@ protected function getTable(): Builder
57
61
return $ this ->connection ->table ($ this ->table );
58
62
}
59
63
60
- protected function save (string $ mobile , string $ token ): bool
64
+ protected function save (string $ mobile , string $ indicator , string $ token ): bool
61
65
{
62
- return $ this ->getTable ()->insert ($ this ->getPayload ($ mobile , $ token ));
66
+ return $ this ->getTable ()->insert ($ this ->getPayload ($ mobile , $ indicator , $ token ));
63
67
}
64
68
65
- protected function getPayload (string $ mobile , string $ token ): array
69
+ protected function getPayload (string $ mobile , string $ indicator , string $ token ): array
66
70
{
67
- return parent ::getPayload ($ mobile , $ token ) + ['expires_at ' => now ()->addMinutes ($ this ->expires )];
71
+ return parent ::getPayload ($ mobile , $ indicator , $ token ) +
72
+ ['expires_at ' => now ()->addMinutes ($ this ->expires ), 'indicator ' => $ indicator ];
68
73
}
69
74
}
0 commit comments