renderer = $renderer; $this->router = $router; $this->userTable = $userTable; $this->mailer = $mailer; $this->flashService = $flashService; } public function __invoke(ServerRequestInterface $request) { if ($request->getMethod() === 'GET') { $affichage_div = true; return $this->renderer->render('@auth/password',compact('affichage_div')); } $params = $request->getParsedBody(); $validator = (new Validator($params)) ->notEmpty('email') ->email('email'); if ($validator->isValid()) { try { $user = $this->userTable->findBy('email', $params['email']); $token = $this->userTable->resetPassword($user->id); $this->mailer->send($user->email, [ 'id' => $user->id, 'token' => $token ]); $this->flashService->success('Un email vous a été envoyé'); //return new RedirectResponse($request->getUri()->getPath()); //$path = $this->router->generateUri('account.profil'); //$this->session->delete('auth.redirect'); //return new RedirectResponse($path); $affichage_div = false; return $this->renderer->render('@auth/password',compact('affichage_div')); } catch (NoRecordException $e) { //$errors = ['email' => 'Aucun utilisateur ne correspond à cet email']; $this->flashService->error('Aucun utilisateur ne correspond à cet email'); } } else { $errors = $validator->getErrors(); } $affichage_div = true; return $this->renderer->render('@auth/password', compact('errors','affichage_div')); } }