middleware('guest:frontend'); } /** * Get the guard to be used during authentication. * * @return StatefulGuard */ protected function guard() { return Auth::guard('frontend'); } /** * Show the application registration form. * * @return View */ public function showRegistrationForm() { /** @var view-string $view */ $view = 'theme::auth.register'; return view($view); } /** * Get a validator for an incoming registration request. * * @throws IlluminateValidationException If data is incorrect. * * @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass */ protected function validator(array $data): ValidationValidator { // phpcs:enable $request = CreateAccountRequest::capture(); $request->prepareForValidation(); return Validator::make( $request->validationData(), $request->rules(), $request->messages(), $request->attributes() ); } /** * Create a new user instance after a valid registration. * * @throws IlluminateValidationException If there are validation errors. * @throws RuntimeException On unhandled api Error. */ protected function create(array $data): Customer { $data['ok_cgv'] = \request()->boolean('ok_cgv'); $data['opt_in'] = \request()->boolean('opt_in'); $data['phone'] = Arr::get($data, 'phone'); // * This field is not standard in crm $data['postcode'] = Arr::get($data, 'postal_code'); Arr::forget($data, 'postal_code'); try { return DB::transaction(function () use ($data) { $crmCustomer = new CrmCustomer(Arr::only( $data, [ 'firstname', 'lastname', 'birth_date', 'address', 'address2', 'postcode', 'country', 'city', 'phone', 'email', 'password', 'opt_in', ] )); $crmCustomer->save(); // * Enregistrement du Hashcode /** @var \App\Models\Customer $customer */ $customer = Customer::withTrashed()->firstOrNew([ 'email' => $data['email'], ]); $customer->fill(Arr::only($data, $customer->getFillable())); $customer->hashcode = $crmCustomer->hashcode; if ($customer->trashed()) { $customer->restore(); } $customer->email_verified_at = $crmCustomer->status ? now() : null; // ! Last connection sera null, pour identifier la deuxième connexion, // ! Pour accéder au partie du Klub. if ($customer->saveOrFail()) { // phpcs:ignore Generic.Files.LineLength.TooLong Session::flash('success', trans('front.messages.account_created_email_confirmation_sent')); } return $customer; }); } catch (ApiErrorException $e) { if ($e->getApiError()->equals(ApiError::customerExists)) { throw IlluminateValidationException::withMessages([ 'error' => trans('front.messages.email_already_in_use'), ]); } if ($e->getApiError()->equals(ApiError::validationFailed)) { throw IlluminateValidationException::withMessages([ 'error' => $e->getMessage(), ]); } report($e); Log::error(self::class . '::create reached end of possibilities.'); throw new RuntimeException(self::class . '::create reached end of possibilities.', $e->getCode(), $e); } catch (CrmValidationException $e) { throw IlluminateValidationException::withMessages([ 'error' => $e->getMessage(), ]); } // end try } /** * Get the post register / login redirect path. */ public function redirectPath(): string { return $this->authLoggedRedirectPath(); } }