|
131 | 131 | case "/login/": |
132 | 132 | case "/register": |
133 | 133 | case "/register/": |
| 134 | + case "/reset-password": |
| 135 | + case "/reset-password/": |
| 136 | + case "/change-password": |
| 137 | + case "/change-password/": |
134 | 138 | include_once(FRONTENDDIR . "generated.html"); |
135 | 139 | break; |
136 | 140 | case "/sharing": |
|
151 | 155 | switch ($request) { |
152 | 156 | case "/api/accounts/verify": |
153 | 157 | case "/api/accounts/verify/": |
154 | | - $email = $_POST['email']; |
155 | 158 | $verifyData = [ |
156 | | - 'email' => $email |
| 159 | + 'email' => $_POST['email'] |
157 | 160 | ]; |
158 | 161 |
|
159 | | - $digits = 6; |
160 | | - $code = rand(0,1000000); |
161 | | - $code = str_pad($code, $digits, '0', STR_PAD_LEFT); |
162 | | - |
163 | | - $verifyData['code'] = $code; |
164 | | - $expires = new \DateTime(); |
165 | | - $expires->add(new \DateInterval('PT30M')); // expire after 30 minutes |
166 | | - $verifyData['expires'] = $expires->getTimestamp(); |
167 | | - |
168 | | - User::saveVerifyToken($verifyData); |
169 | | - $verifyToken = User::getVerifyToken($code); |
170 | | - |
| 162 | + $verifyToken = User::saveVerifyToken('verify', $verifyData); |
171 | 163 | Mailer::sendVerify($verifyToken); |
172 | 164 |
|
173 | 165 | $responseData = "OK"; |
|
177 | 169 | break; |
178 | 170 | case "/api/accounts/new": |
179 | 171 | case "/api/accounts/new/": |
180 | | - if (User::userEmailExists($_POST['email'])) { |
| 172 | + $verifyToken = User::getVerifyToken($_POST['confirm']); |
| 173 | + if (!$verifyToken) { |
181 | 174 | header("HTTP/1.1 400 Bad Request"); |
182 | 175 | exit(); |
183 | 176 | } |
184 | | - $verifyToken = User::getVerifyToken($_POST['confirm']); |
185 | | - if (!$verifyToken) { |
| 177 | + if ($verifyToken['email'] !== $_POST['email']) { |
| 178 | + header("HTTP/1.1 400 Bad Request"); |
| 179 | + exit(); |
| 180 | + } |
| 181 | + if (User::userEmailExists($_POST['email'])) { |
186 | 182 | header("HTTP/1.1 400 Bad Request"); |
187 | 183 | exit(); |
188 | 184 | } |
189 | | - |
190 | 185 | if (!$_POST['password'] === $_POST['repeat_password']) { |
191 | 186 | header("HTTP/1.1 400 Bad Request"); |
192 | 187 | exit(); |
|
207 | 202 | header("Content-type: application/json"); |
208 | 203 | echo json_encode($responseData, JSON_PRETTY_PRINT); |
209 | 204 | break; |
| 205 | + case "/api/accounts/reset-password": |
| 206 | + case "/api/accounts/reset-password/": |
| 207 | + if (!User::userEmailExists($_POST['email'])) { |
| 208 | + header("HTTP/1.1 200 OK"); // Return OK even when user is not found; |
| 209 | + header("Content-type: application/json"); |
| 210 | + echo json_encode("OK"); |
| 211 | + exit(); |
| 212 | + } |
| 213 | + $verifyData = [ |
| 214 | + 'email' => $_POST['email'] |
| 215 | + ]; |
| 216 | + |
| 217 | + $verifyToken = User::saveVerifyToken('passwordReset', $verifyData); |
| 218 | + Mailer::sendResetPassword($verifyToken); |
| 219 | + header("HTTP/1.1 200 OK"); |
| 220 | + header("Content-type: application/json"); |
| 221 | + echo json_encode("OK"); |
| 222 | + break; |
| 223 | + case "/api/accounts/change-password": |
| 224 | + case "/api/accounts/change-password/": |
| 225 | + $verifyToken = User::getVerifyToken($_POST['token']); |
| 226 | + if (!$verifyToken) { |
| 227 | + header("HTTP/1.1 400 Bad Request"); |
| 228 | + exit(); |
| 229 | + } |
| 230 | + User::setUserPassword($verifyToken['email'], $_POST['newPassword']); |
| 231 | + header("HTTP/1.1 200 OK"); |
| 232 | + header("Content-type: application/json"); |
| 233 | + echo json_encode("OK"); |
| 234 | + break; |
210 | 235 | case "/login/password": |
211 | 236 | case "/login/password/": |
212 | 237 | if (User::checkPassword($_POST['username'], $_POST['password'])) { |
|
272 | 297 | $returnUrl = urldecode($_POST['returnUrl']); |
273 | 298 | header("Location: $returnUrl"); |
274 | 299 | } |
275 | | - // FIXME: force user to be logged in |
276 | | - // FIXME: save the allowed clients in the logged in user; |
277 | | - |
278 | 300 | break; |
279 | 301 | case "/token": |
280 | 302 | case "/token/": |
|
0 commit comments