middleware('guest:frontend'); $this->middleware('signed')->only('showResetForm'); $this->middleware('throttle:6,1')->only('showResetForm'); } /** * Get the guard to be used during authentication. */ protected function guard(): StatefulGuard { return Auth::guard('frontend'); } /** * Display the password reset view for the given token. * * If no token is present, display the link request form. */ public function showResetForm(Request $request): View { $token = $request->route()->parameter('token'); /** @var view-string $view */ $view = 'theme::auth.passwords.reset'; return view($view)->with( ['token' => $token, 'email' => $request->email] ); } /** * Reset the given user's password. * * @throws \Illuminate\Validation\ValidationException If something goes wrong. */ protected function resetPassword(Customer $customer, string $password): void { /** @var CrmApiV4 */ $crm = resolve('crmAPI'); try { if (! ($crmCustomer = $crm->getCustomer($customer->hashcode))) { throw ValidationException::withMessages([ 'error' => trans('Changement impossible, compte inexistant.'), ]); } $crmCustomer->password = $password; $crmCustomer->save(); } catch (TypeError | CrmException | ApiErrorException $e) { report($e); throw ValidationException::withMessages([ 'error' => trans('front.messages.unexpected_error_try_later'), ]); } catch (ExceptionsValidationException $e) { throw ValidationException::withMessages([ 'password' => $e->getMessage(), ]); } $customer->setRememberToken(Str::random(60)); $customer->save(); event(new PasswordReset($customer)); $this->guard()->login($customer); } /** * Get the post register / login redirect path. */ public function redirectPath(): string { return $this->authLoggedRedirectPath(); } /** * Get the broker to be used during password reset. */ public function broker(): PasswordBroker { return Password::broker('customers'); } }