_config = request('_config'); $this->customerRepository = $customerRepository; $this->customerGroupRepository = $customerGroupRepository; $this->subscriptionRepository = $subscriptionRepository; } /** * Opens up the user's sign up form. * * @return \Illuminate\View\View */ public function show() { return view($this->_config['view']); } /** * Method to store user's sign up form data to DB. * * @return \Illuminate\Http\Response */ public function create() { $this->validate(request(), [ 'first_name' => 'string|required', 'last_name' => 'string|required', 'email' => 'email|required|unique:customers,email', 'password' => 'confirmed|min:6|required', ]); $data = array_merge(request()->input(), [ 'password' => bcrypt(request()->input('password')), 'api_token' => Str::random(80), 'is_verified' => core()->getConfigData('customer.settings.email.verification') ? 0 : 1, 'customer_group_id' => $this->customerGroupRepository->findOneWhere(['code' => 'general'])->id, 'token' => md5(uniqid(rand(), true)), ]); Event::dispatch('customer.registration.before'); $customer = $this->customerRepository->create($data); Event::dispatch('customer.registration.after', $customer); if (! $customer) { session()->flash('error', trans('shop::app.customer.signup-form.failed')); return redirect()->back(); } if (isset($data['is_subscribed'])) { $subscription = $this->subscriptionRepository->findOneWhere(['email' => $data['email']]); if ($subscription) { $this->subscriptionRepository->update([ 'customer_id' => $customer->id, ], $subscription->id); } else { $this->subscriptionRepository->create([ 'email' => $data['email'], 'customer_id' => $customer->id, 'channel_id' => core()->getCurrentChannel()->id, 'is_subscribed' => 1, 'token' => $token = uniqid(), ]); try { Mail::queue(new SubscriptionEmail([ 'email' => $data['email'], 'token' => $token, ])); } catch (\Exception $e) { } } } if (core()->getConfigData('customer.settings.email.verification')) { try { if (core()->getConfigData('emails.general.notifications.emails.general.notifications.verification')) { Mail::queue(new VerificationEmail(['email' => $data['email'], 'token' => $data['token']])); } session()->flash('success', trans('shop::app.customer.signup-form.success-verify')); } catch (\Exception $e) { report($e); session()->flash('info', trans('shop::app.customer.signup-form.success-verify-email-unsent')); } } else { try { if (core()->getConfigData('emails.general.notifications.emails.general.notifications.registration')) { Mail::queue(new RegistrationEmail(request()->all())); } session()->flash('success', trans('shop::app.customer.signup-form.success-verify')); } catch (\Exception $e) { report($e); session()->flash('info', trans('shop::app.customer.signup-form.success-verify-email-unsent')); } session()->flash('success', trans('shop::app.customer.signup-form.success')); } return redirect()->route($this->_config['redirect']); } /** * Method to verify account * * @param string $token * @return \Illuminate\Http\Response */ public function verifyAccount($token) { $customer = $this->customerRepository->findOneByField('token', $token); if ($customer) { $customer->update(['is_verified' => 1, 'token' => 'NULL']); session()->flash('success', trans('shop::app.customer.signup-form.verified')); } else { session()->flash('warning', trans('shop::app.customer.signup-form.verify-failed')); } return redirect()->route('customer.session.index'); } /** * @param string $email * @return \Illuminate\Http\Response */ public function resendVerificationEmail($email) { $verificationData = [ 'email' => $email, 'token' => md5(uniqid(rand(), true)), ]; $customer = $this->customerRepository->findOneByField('email', $email); $this->customerRepository->update(['token' => $verificationData['token']], $customer->id); try { Mail::queue(new VerificationEmail($verificationData)); if (Cookie::has('enable-resend')) { \Cookie::queue(\Cookie::forget('enable-resend')); } if (Cookie::has('email-for-resend')) { \Cookie::queue(\Cookie::forget('email-for-resend')); } } catch (\Exception $e) { report($e); session()->flash('error', trans('shop::app.customer.signup-form.verification-not-sent')); return redirect()->back(); } session()->flash('success', trans('shop::app.customer.signup-form.verification-sent')); return redirect()->back(); } }