1 | <?php |
||
17 | class PasswordRecoveryControllerProvider implements ControllerProviderInterface |
||
18 | { |
||
19 | /** |
||
20 | * @var Application Reference to the Silex app for easy access to the services etc. |
||
21 | */ |
||
22 | private $app; |
||
23 | /** |
||
24 | * @var string The timeout of a reset request, as DateInterval https://secure.php.net/manual/en/class.dateinterval.php |
||
25 | */ |
||
26 | private $request_timeout = 'P1W'; |
||
27 | /** |
||
28 | * @var int The length of the generated token for validating requests |
||
29 | */ |
||
30 | private $token_length = 32; |
||
31 | /** |
||
32 | * @var int The minimum length for a new user password |
||
33 | */ |
||
34 | private $password_min_length = 8; |
||
35 | /** |
||
36 | * @var string Name of the route for reset, used with the UrlGenerator |
||
37 | */ |
||
38 | private $reset_route = 'POST_GET_password_reset_token'; |
||
39 | /** |
||
40 | * @var string Name of the route for request, used with the UrlGenerator |
||
41 | */ |
||
42 | private $request_route = 'POST_GET_password_request'; |
||
43 | |||
44 | /** |
||
45 | * Returns routes to connect to the given application. |
||
46 | * |
||
47 | * @param Application $app An Application instance |
||
48 | * |
||
49 | * @return ControllerCollection A ControllerCollection instance |
||
50 | */ |
||
51 | public function connect(Application $app) |
||
113 | |||
114 | /** |
||
115 | * Deletes all old requests from the database. A request is considered old, |
||
116 | * if its registration happened before now - $timeout. |
||
117 | */ |
||
118 | private function cleanupRequests() |
||
125 | |||
126 | /** |
||
127 | * Validates the given $token by looking it up in the database. |
||
128 | * |
||
129 | * @param string $token |
||
130 | * @return bool True if the token is valid, false otherwise. |
||
131 | */ |
||
132 | private function validateRequest($token) |
||
137 | |||
138 | /** |
||
139 | * Validates the given password. |
||
140 | * |
||
141 | * @param string $password |
||
142 | * @param string $password_repeat |
||
143 | * @return bool True on success, false otherwise. |
||
144 | */ |
||
145 | private function validateNewPassword($password, $password_repeat) |
||
152 | |||
153 | /** |
||
154 | * Returns the recovery request from the database. |
||
155 | * |
||
156 | * @param $token |
||
157 | * @return array |
||
158 | */ |
||
159 | private function getRecoveryRequest($token) |
||
163 | |||
164 | /** |
||
165 | * Finally updates the users password after a successful recovery. |
||
166 | * |
||
167 | * @param $uid |
||
168 | * @param $password |
||
169 | */ |
||
170 | private function updatePassword($uid, $password) |
||
176 | |||
177 | /** |
||
178 | * Deletes the request associated with the given $token from the database. |
||
179 | * |
||
180 | * @param string $token |
||
181 | */ |
||
182 | private function closeRequest($token) |
||
186 | |||
187 | /** |
||
188 | * Registers the given $email by storing it in the database. The method |
||
189 | * also generates and returns a random token associated with this request. |
||
190 | * |
||
191 | * @param string $uid |
||
192 | * @param string $email |
||
193 | * @return string The token associated with this request. |
||
194 | */ |
||
195 | private function registerRequest($uid, $email) |
||
205 | |||
206 | /** |
||
207 | * Sends the recovery email containing a link with the $token to $email. |
||
208 | * |
||
209 | * @param array $member Array of attributes for the member as returned by \Zend\Ldap |
||
210 | * @param string $token The random token which is passed to the reset URL for validation |
||
211 | * @return int The number of successful mail deliveries. |
||
212 | */ |
||
213 | private function sendRecoveryMail($member, $token) |
||
233 | } |
||
234 |