middleware('guest:club')->except('logout'); } /** * Get the guard to be used during authentication. */ protected function guard(): StatefulGuard { return Auth::guard('club'); } /** * Show the application's login form. */ public function showLoginForm(): View { return view('club.auth.login'); } /** * Where to redirect users after login. */ protected function redirectTo(): string { return $this->authLoggedRedirectPath(); } /** * Attempt to log the user into the application. */ protected function attemptLogin(Request $request): bool { $credentials = $this->credentials($request); $customerModel = Customer::query()->where('email', Arr::get($credentials, 'email'))->first(); $crmCustomer = CrmCustomer::findWithEmail(Arr::get($credentials, 'email')); // Check database customer. if (! $customerModel) { // Check crm customer. if (! $crmCustomer) { return false; } /** @var \App\Models\Customer $customerModel */ $customerModel = new Customer(Arr::only($crmCustomer->jsonSerialize(), ['email'])); $customerModel->username = Utils::getUniquePseudo( $crmCustomer->firstname, $crmCustomer->lastname ); $customerModel->hashcode = $crmCustomer->hashcode; if (! $customerModel->saveOrFail()) { return false; } } else { // Check crm customer. if (! $crmCustomer) { $customerModel->delete(); return false; } } // end if try { CrmCustomer::login(Arr::get($credentials, 'email'), Arr::get($credentials, 'password')); } catch (Exception $ex) { Log::error($ex); return false; } $this->guard()->loginUsingId($customerModel->getKey()); return true; } /** * The user has been authenticated. * * @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing, Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed */ protected function authenticated(Request $request, Model $customerModel): void { // @phpstan-ignore-next-line $customerModel->last_connection = \now(); $customerModel->saveOrFail(); Session::flash('success', trans('Vous êtes à présent connecté')); } /** * The user has logged out of the application. * * @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass */ protected function loggedOut(Request $request): void { Session::flash('info', trans('Vous êtes à présent déconnecté')); } }