mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Add form request for enable two factor
This commit is contained in:
parent
6a3b447395
commit
b28aa5d1cd
@ -143,8 +143,8 @@ class EmailController extends BaseController
|
||||
}
|
||||
});
|
||||
|
||||
$entity_obj = $entity_obj->fresh();
|
||||
$entity_obj->last_sent_date = now();
|
||||
|
||||
$entity_obj->save();
|
||||
|
||||
/*Only notify the admin ONCE, not once per contact/invite*/
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\TwoFactor\EnableTwoFactorRequest;
|
||||
use App\Models\User;
|
||||
use App\Transformers\UserTransformer;
|
||||
use Crypt;
|
||||
@ -51,17 +52,16 @@ class TwoFactorController extends BaseController
|
||||
return response()->json(['data' => $data], 200);
|
||||
}
|
||||
|
||||
public function enableTwoFactor()
|
||||
public function enableTwoFactor(EnableTwoFactorRequest $request)
|
||||
{
|
||||
$google2fa = new Google2FA();
|
||||
|
||||
$user = auth()->user();
|
||||
$secret = request()->input('secret');
|
||||
$oneTimePassword = request()->input('one_time_password');
|
||||
$secret = $request->input('secret');
|
||||
$oneTimePassword = $request->input('one_time_password');
|
||||
|
||||
if ($google2fa->verifyKey($secret, $oneTimePassword) && $user->phone && $user->email_verified_at) {
|
||||
$user->google_2fa_secret = encrypt($secret);
|
||||
|
||||
$user->save();
|
||||
|
||||
return response()->json(['message' => ctrans('texts.enabled_two_factor')], 200);
|
||||
@ -72,6 +72,11 @@ class TwoFactorController extends BaseController
|
||||
return response()->json(['message' => 'No phone record or user is not confirmed'], 400);
|
||||
}
|
||||
|
||||
/*
|
||||
* @param App\Models\User $user
|
||||
* @param App\Models\User auth()->user()
|
||||
*/
|
||||
|
||||
public function disableTwoFactor()
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
41
app/Http/Requests/TwoFactor/EnableTwoFactorRequest.php
Normal file
41
app/Http/Requests/TwoFactor/EnableTwoFactorRequest.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?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\Http\Requests\TwoFactor;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class EnableTwoFactorRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize() : bool
|
||||
{
|
||||
return true;;
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'secret' => 'bail|required|string',
|
||||
'one_time_password' => 'bail|required|string',
|
||||
];
|
||||
}
|
||||
|
||||
public function prepareForValidation()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -40,7 +40,7 @@ class CreditEmailedNotification implements ShouldQueue
|
||||
|
||||
// $first_notification_sent = true;
|
||||
|
||||
$credit = $event->invitation->credit;
|
||||
$credit = $event->invitation->credit->fresh();
|
||||
$credit->last_sent_date = now();
|
||||
$credit->saveQuietly();
|
||||
|
||||
|
@ -42,7 +42,7 @@ class InvoiceEmailedNotification implements ShouldQueue
|
||||
|
||||
$first_notification_sent = true;
|
||||
|
||||
$invoice = $event->invitation->invoice;
|
||||
$invoice = $event->invitation->invoice->fresh();
|
||||
$invoice->last_sent_date = now();
|
||||
$invoice->saveQuietly();
|
||||
|
||||
|
@ -42,7 +42,7 @@ class QuoteEmailedNotification implements ShouldQueue
|
||||
|
||||
// $first_notification_sent = true;
|
||||
|
||||
$quote = $event->invitation->quote;
|
||||
$quote = $event->invitation->quote->fresh();
|
||||
$quote->last_sent_date = now();
|
||||
$quote->saveQuietly();
|
||||
|
||||
|
@ -300,10 +300,10 @@ class InvoiceService
|
||||
} elseif ($this->invoice->balance > 0 && $this->invoice->balance < $this->invoice->amount) {
|
||||
$this->setStatus(Invoice::STATUS_PARTIAL);
|
||||
}
|
||||
elseif($this->invoice->balance < 0) {
|
||||
$this->setStatus(Invoice::STATUS_PARTIAL);
|
||||
elseif ($this->invoice->balance < 0 || $this->invoice->balance > 0) {
|
||||
$this->invoice->status_id = Invoice::STATUS_SENT;
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -318,7 +318,7 @@ class InvoiceService
|
||||
} elseif ($this->invoice->balance > 0 && $this->invoice->balance < $this->invoice->amount) {
|
||||
$this->invoice->status_id = Invoice::STATUS_PARTIAL;
|
||||
}
|
||||
elseif ($this->invoice->balance < 0) {
|
||||
elseif ($this->invoice->balance < 0 || $this->invoice->balance > 0) {
|
||||
$this->invoice->status_id = Invoice::STATUS_SENT;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user