diff --git a/app/Http/Livewire/BillingPortalPurchasev2.php b/app/Http/Livewire/BillingPortalPurchasev2.php index 35933f13d043..b8073c5b203d 100644 --- a/app/Http/Livewire/BillingPortalPurchasev2.php +++ b/app/Http/Livewire/BillingPortalPurchasev2.php @@ -17,6 +17,7 @@ use App\Jobs\Mail\NinjaMailerJob; use App\Jobs\Mail\NinjaMailerObject; use App\Libraries\MultiDB; use App\Mail\ContactPasswordlessLogin; +use App\Mail\Subscription\OtpCode; use App\Models\Client; use App\Models\ClientContact; use App\Models\Invoice; @@ -229,12 +230,22 @@ class BillingPortalPurchasev2 extends Component $this->resetValidation('login'); } - public function handleLogin() + public function handleLogin($user_code) { + $this->resetErrorBag('login'); + $this->resetValidation('login'); + $code = Cache::get("subscriptions:otp:{$this->email}"); - $this->validateOnly('login', ['login' => ['required',Rule::in([$code])]], ['login' => ctrans('texts.invalid_code')]); + // $this->validateOnly('login', ['login' => 'required'], ['login' => ctrans('texts.invalid_code')]); + + if($user_code != $code){ + nlog($code); + nlog($user_code); + $errors = $this->getErrorBag(); + $errors->add('login', ctrans('texts.invalid_code')); + } $contact = ClientContact::where('email', $this->email)->first(); @@ -243,9 +254,13 @@ class BillingPortalPurchasev2 extends Component $this->contact = $contact; } else { - + $this->createClientContact(); } + } + + public function showClientRequiredFields() + { } @@ -259,8 +274,25 @@ class BillingPortalPurchasev2 extends Component Cache::put($email_hash, $rand, 120); + $this->emailOtpCode($rand); } + private function emailOtpCode($code) + { + + $cc = new ClientContact(); + $cc->email = $this->email; + + $nmo = new NinjaMailerObject; + $nmo->mailable = new OtpCode($this->subscription->company, $this->contact, $code); + $nmo->company = $this->subscription->company; + $nmo->settings = $this->subscription->company->settings; + $nmo->to_user = $cc; + NinjaMailerJob::dispatch($nmo); + + } + + /** * Handle a coupon being entered into the checkout */ @@ -411,9 +443,9 @@ class BillingPortalPurchasev2 extends Component $this->contact = $client->fresh()->contacts()->first(); Auth::guard('contact')->loginUsingId($this->contact->id, true); + return $this; } - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public function updated($propertyName) { @@ -424,6 +456,8 @@ class BillingPortalPurchasev2 extends Component } + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + public function rules() { $rules = [ diff --git a/app/Http/Requests/Report/GenericReportRequest.php b/app/Http/Requests/Report/GenericReportRequest.php index 9cfddf60f433..d7ad07152b8f 100644 --- a/app/Http/Requests/Report/GenericReportRequest.php +++ b/app/Http/Requests/Report/GenericReportRequest.php @@ -28,7 +28,6 @@ class GenericReportRequest extends Request public function rules() { - nlog($this->date_range); return [ 'date_range' => 'bail|required|string', diff --git a/app/Mail/Subscription/OtpCode.php b/app/Mail/Subscription/OtpCode.php new file mode 100644 index 000000000000..8f7424f34547 --- /dev/null +++ b/app/Mail/Subscription/OtpCode.php @@ -0,0 +1,63 @@ +company = $company; + $this->contact = $contact; + $this->code = $code; + } + + /** + * Build the message. + * + * @return $this + */ + public function build() + { + App::setLocale($this->company->locale()); + + return $this->from(config('mail.from.address'), config('mail.from.name')) + ->subject(ctrans('texts.otp_code_subject')) + ->text('email.admin.generic_text') + ->view('email.admin.generic') + ->with([ + 'settings' => $this->company->settings, + 'logo' => $this->company->present()->logo(), + 'title' => ctrans('texts.otp_code_subject'), + 'content' => ctrans('texts.otp_code_body', ['code' => $this->code]), + 'whitelabel' => $this->company->account->isPaid(), + ]); + } +} diff --git a/lang/en/texts.php b/lang/en/texts.php index 090ba0f2dde9..a92f17bb603f 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -4895,7 +4895,9 @@ $LANG = array( 'delete_bank_account' => 'Delete Bank Account', 'archive_transaction' => 'Archive Transaction', 'delete_transaction' => 'Delete Transaction', - 'otp_code_message' => 'Enter the code emailed.' + 'otp_code_message' => 'Enter the code emailed.', + 'otp_code_subject' => 'Your one time passcode code', + 'otp_code_body' => 'Your one time passcode is :code', ); return $LANG;