$params */ public function showRequest(array $params = []): Response { return $this->view('auth/forgot', [ 'title' => 'Mot de passe oublie - Wakdo Admin', 'csrfToken' => Csrf::token($this->sessionManager()), 'notice' => null, ]); } /** * @param array $params */ public function submitRequest(array $params = []): Response { $form = $this->request->formBody(); if (!Csrf::validate($this->sessionManager(), $form['_csrf'] ?? null)) { return $this->view('auth/forgot', [ 'title' => 'Mot de passe oublie - Wakdo Admin', 'csrfToken' => Csrf::token($this->sessionManager()), 'notice' => null, ], 403); } $email = trim($form['email'] ?? ''); // Reponse neutre quoi qu'il arrive (existence, validite, meme panne base). if ($email !== '' && strlen($email) <= 254) { try { $this->resetService()->requestReset($email, $this->baseUrl()); } catch (Throwable $exception) { error_log('[wakdo][auth] reset request failure: ' . $exception->getMessage()); } } return $this->view('auth/forgot', [ 'title' => 'Mot de passe oublie - Wakdo Admin', 'csrfToken' => Csrf::token($this->sessionManager()), 'notice' => self::NEUTRAL_NOTICE, ]); } /** * @param array $params */ public function showConfirm(array $params = []): Response { return $this->renderConfirm($this->request->query('token') ?? '', null); } /** * @param array $params */ public function submitConfirm(array $params = []): Response { $form = $this->request->formBody(); $token = $form['token'] ?? ''; if (!Csrf::validate($this->sessionManager(), $form['_csrf'] ?? null)) { return $this->renderConfirm($token, 'Session expiree, merci de reessayer.', 403); } $password = $form['password'] ?? ''; $confirm = $form['password_confirm'] ?? ''; if ($password !== $confirm) { return $this->renderConfirm($token, 'Les mots de passe ne correspondent pas.'); } try { $result = $this->resetService()->confirmReset($token, $password); } catch (Throwable $exception) { error_log('[wakdo][auth] reset confirm failure: ' . $exception->getMessage()); return $this->renderConfirm($token, self::INVALID_LINK); } if ($result->success && $result->redirectTo !== null) { return $this->redirect($result->redirectTo); } return $this->renderConfirm($token, $result->error ?? self::INVALID_LINK); } protected function sessionManager(): SessionManager { return new SessionManager($this->config); } protected function resetService(): PasswordResetService { return new PasswordResetService( $this->database, $this->config, new PasswordHasher($this->config), new LogMailer(), ); } private function baseUrl(): string { return $this->config->get('APP_URL_ADMIN', '') ?? ''; } private function redirect(string $location, int $status = 302): Response { return Response::make('', $status, ['Location' => $location]); } private function renderConfirm(string $token, ?string $error, int $status = 200): Response { return $this->view('auth/reset', [ 'title' => 'Nouveau mot de passe - Wakdo Admin', 'csrfToken' => Csrf::token($this->sessionManager()), 'token' => $token, 'error' => $error, ], $status); } }