1 | <?php |
||
12 | class CachingThrottler implements ThrottlerInterface |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * @author Andrea Marco Sartori |
||
17 | * @var Illuminate\Contracts\Cache\Repository $cache Cache repository. |
||
18 | */ |
||
19 | protected $cache; |
||
20 | |||
21 | /** |
||
22 | * @author Andrea Marco Sartori |
||
23 | * @var string $key Source where attempts come from. |
||
24 | */ |
||
25 | protected $key; |
||
26 | |||
27 | /** |
||
28 | * @author Andrea Marco Sartori |
||
29 | * @var string $lockOutKey Key to store lock out time in. |
||
30 | */ |
||
31 | protected $lockOutKey; |
||
32 | |||
33 | /** |
||
34 | * Set the dependencies. |
||
35 | * |
||
36 | * @author Andrea Marco Sartori |
||
37 | * @param Illuminate\Contracts\Cache\Repository $cache |
||
38 | * @return void |
||
39 | */ |
||
40 | public function __construct(Cache $cache) |
||
44 | |||
45 | /** |
||
46 | * Set univocal source where attempts come from. |
||
47 | * |
||
48 | * @author Andrea Marco Sartori |
||
49 | * @return boolean |
||
50 | */ |
||
51 | public function setSource($source) |
||
57 | |||
58 | /** |
||
59 | * Determine whether the user has been locked out. |
||
60 | * |
||
61 | * @author Andrea Marco Sartori |
||
62 | * @return boolean |
||
63 | */ |
||
64 | public function lockedOut() |
||
68 | |||
69 | /** |
||
70 | * Retrieve the number of remaining seconds before the next attempt. |
||
71 | * |
||
72 | * @author Andrea Marco Sartori |
||
73 | * @return integer |
||
74 | */ |
||
75 | public function getRemainingSeconds() |
||
79 | |||
80 | /** |
||
81 | * Increment the number of failed attempts. |
||
82 | * |
||
83 | * @author Andrea Marco Sartori |
||
84 | * @return void |
||
85 | */ |
||
86 | public function incrementAttempts() |
||
92 | |||
93 | /** |
||
94 | * Retrieve the minutes after which keys expire. |
||
95 | * |
||
96 | * @author Andrea Marco Sartori |
||
97 | * @return integer |
||
98 | */ |
||
99 | private function getExpiry() |
||
103 | |||
104 | /** |
||
105 | * Retrieve the seconds to wait before the next attempt. |
||
106 | * |
||
107 | * @author Andrea Marco Sartori |
||
108 | * @return integer |
||
109 | */ |
||
110 | private function getDelay() |
||
114 | |||
115 | /** |
||
116 | * Determine whether a user has performed too many attempts. |
||
117 | * |
||
118 | * @author Andrea Marco Sartori |
||
119 | * @return boolean |
||
120 | */ |
||
121 | public function tooManyAttempts() |
||
127 | |||
128 | /** |
||
129 | * Lock a user out. |
||
130 | * |
||
131 | * @author Andrea Marco Sartori |
||
132 | * @return void |
||
133 | */ |
||
134 | public function lockOut() |
||
140 | |||
141 | /** |
||
142 | * Reset the attempts counter. |
||
143 | * |
||
144 | * @author Andrea Marco Sartori |
||
145 | * @return void |
||
146 | */ |
||
147 | public function resetAttempts() |
||
151 | |||
152 | } |
||
153 |