mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
OTP for subscriptions
This commit is contained in:
parent
81e8997e2c
commit
9a0a55d356
@ -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 = [
|
||||
|
@ -28,7 +28,6 @@ class GenericReportRequest extends Request
|
||||
|
||||
public function rules()
|
||||
{
|
||||
nlog($this->date_range);
|
||||
|
||||
return [
|
||||
'date_range' => 'bail|required|string',
|
||||
|
63
app/Mail/Subscription/OtpCode.php
Normal file
63
app/Mail/Subscription/OtpCode.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Mail\Subscription;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class OtpCode extends Mailable
|
||||
{
|
||||
// use Queueable, SerializesModels;
|
||||
|
||||
public $company;
|
||||
|
||||
public $contact;
|
||||
|
||||
public $code;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($company, $contact, $code)
|
||||
{
|
||||
$this->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(),
|
||||
]);
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user