middleware('guest:frontend'); } /** * Get the guard to be used during authentication. * * @return \Illuminate\Contracts\Auth\StatefulGuard */ protected function guard() { return Auth::guard('frontend'); } /** * Show the application registration form. * * @return \Illuminate\View\View */ public function showRegistrationForm() { return view('theme::auth.register'); } /** * Get a validator for an incoming registration request. * * @param array $data * @return \Illuminate\Contracts\Validation\Validator * @throws \Illuminate\Validation\ValidationException If data is incorrect. */ protected function validator(array $data): ValidationValidator { $data['ok_cgv'] = \request()->boolean('ok_cgv'); $data['phone'] = $data['phone'] ?? null; $data['opt_in'] = ($data['opt_in'] ?? false) ? true : false; $request = new CreateAccountRequest(); $validateData = Validator::make( $data, $request->rules(), $request->messages(), $request->attributes() ); if ($validateData) { return $validateData; } else { try { (new CrmCustomer())->fill($this->getOnlyCrmData($data)); } catch (ExceptionsValidationException $e) { throw ValidationException::withMessages([ 'error' => $e->getMessage() ]); } } } /** * Create a new user instance after a valid registration. * * @param array $data * @return \App\Models\Customer * @throws \Illuminate\Validation\ValidationException 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['phone'] = $data['phone'] ?? null; $data['opt_in'] = ($data['opt_in'] ?? false) ? true : false; try { return DB::transaction(function () use ($data) { $crmCustomer = new CrmCustomer($this->getOnlyCrmData($data)); // * Country Is forced to france $crmCustomer->country = Country::france(); $crmCustomer->save(); // * Enregistrement du Hashcode /** @var \App\Models\Customer $customer */ $customer = new Customer( Arr::only($data, (new \ReflectionClass(\App\Models\Customer::class)) ->getProperty('fillable')->getDefaultValue()) ); $customer->hashcode = $crmCustomer->hashcode; // ! 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('Votre compte à bien été crée, vous devez valider votre adresse email, un email de confirmation vous à été envoyé.')); } return $customer; }); } catch (ApiErrorException $e) { if ($e->getApiError()->equals(ApiError::customerExists())) { throw ValidationException::withMessages([ 'error' => trans('Un compte est déjà associé à cette adresse email.') ]); } if ($e->getApiError()->equals(ApiError::validationFailed())) { throw ValidationException::withMessages([ 'error' => $e->getMessage() ]); } report($e); Log::error(__CLASS__ . '::create reached end of possibilities.'); throw new \RuntimeException(__CLASS__ . '::create reached end of possibilities.'); } catch (ExceptionsValidationException $e) { throw ValidationException::withMessages([ 'error' => $e->getMessage() ]); } //end try } /** * Get the post register / login redirect path. * * @return string */ public function redirectPath() { return $this->authLoggedRedirectPath(); } /** * Get only data used in crm * * @param array $data * @return array */ private function getOnlyCrmData(array $data): array { return \array_intersect_key( $data, [ 'firstname' => '', 'lastname' => '', 'birth_date' => '', 'address' => '', 'postcode' => '', 'country' => '', 'city' => '', 'phone' => '', 'email' => '', 'password' => '', 'opt_in' => '', ] ); } }