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(); //$url_part = explode('/',$request->getServerParams()['HTTP_REFERER'] ?? '/'); //$chemin = $url_part[3].'/'.$url_part[4]; $validator = (new Validator($params)) ->notEmpty('email') ->email('email'); if ($validator->isValid()) { if ($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 a été envoyé à l'utilisateur"); $affichage_div = false; return new RedirectBackResponse($request); } else { $this->flashService->error('Aucun utilisateur ne correspond à cet email'); } } else { $errors = $validator->getErrors(); } $affichage_div = true; $email = $params['email']; return $this->renderer->render('@auth/password', compact('email','errors','affichage_div')); } }