Add form request for enable two factor

This commit is contained in:
David Bomba 2022-12-01 15:33:40 +11:00
parent 6a3b447395
commit b28aa5d1cd
7 changed files with 58 additions and 12 deletions

View File

@ -143,8 +143,8 @@ class EmailController extends BaseController
} }
}); });
$entity_obj = $entity_obj->fresh();
$entity_obj->last_sent_date = now(); $entity_obj->last_sent_date = now();
$entity_obj->save(); $entity_obj->save();
/*Only notify the admin ONCE, not once per contact/invite*/ /*Only notify the admin ONCE, not once per contact/invite*/

View File

@ -11,6 +11,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Http\Requests\TwoFactor\EnableTwoFactorRequest;
use App\Models\User; use App\Models\User;
use App\Transformers\UserTransformer; use App\Transformers\UserTransformer;
use Crypt; use Crypt;
@ -51,17 +52,16 @@ class TwoFactorController extends BaseController
return response()->json(['data' => $data], 200); return response()->json(['data' => $data], 200);
} }
public function enableTwoFactor() public function enableTwoFactor(EnableTwoFactorRequest $request)
{ {
$google2fa = new Google2FA(); $google2fa = new Google2FA();
$user = auth()->user(); $user = auth()->user();
$secret = request()->input('secret'); $secret = $request->input('secret');
$oneTimePassword = request()->input('one_time_password'); $oneTimePassword = $request->input('one_time_password');
if ($google2fa->verifyKey($secret, $oneTimePassword) && $user->phone && $user->email_verified_at) { if ($google2fa->verifyKey($secret, $oneTimePassword) && $user->phone && $user->email_verified_at) {
$user->google_2fa_secret = encrypt($secret); $user->google_2fa_secret = encrypt($secret);
$user->save(); $user->save();
return response()->json(['message' => ctrans('texts.enabled_two_factor')], 200); 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); 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() public function disableTwoFactor()
{ {
$user = auth()->user(); $user = auth()->user();

View 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()
{
}
}

View File

@ -40,7 +40,7 @@ class CreditEmailedNotification implements ShouldQueue
// $first_notification_sent = true; // $first_notification_sent = true;
$credit = $event->invitation->credit; $credit = $event->invitation->credit->fresh();
$credit->last_sent_date = now(); $credit->last_sent_date = now();
$credit->saveQuietly(); $credit->saveQuietly();

View File

@ -42,7 +42,7 @@ class InvoiceEmailedNotification implements ShouldQueue
$first_notification_sent = true; $first_notification_sent = true;
$invoice = $event->invitation->invoice; $invoice = $event->invitation->invoice->fresh();
$invoice->last_sent_date = now(); $invoice->last_sent_date = now();
$invoice->saveQuietly(); $invoice->saveQuietly();

View File

@ -42,7 +42,7 @@ class QuoteEmailedNotification implements ShouldQueue
// $first_notification_sent = true; // $first_notification_sent = true;
$quote = $event->invitation->quote; $quote = $event->invitation->quote->fresh();
$quote->last_sent_date = now(); $quote->last_sent_date = now();
$quote->saveQuietly(); $quote->saveQuietly();

View File

@ -300,10 +300,10 @@ class InvoiceService
} elseif ($this->invoice->balance > 0 && $this->invoice->balance < $this->invoice->amount) { } elseif ($this->invoice->balance > 0 && $this->invoice->balance < $this->invoice->amount) {
$this->setStatus(Invoice::STATUS_PARTIAL); $this->setStatus(Invoice::STATUS_PARTIAL);
} }
elseif($this->invoice->balance < 0) { elseif ($this->invoice->balance < 0 || $this->invoice->balance > 0) {
$this->setStatus(Invoice::STATUS_PARTIAL); $this->invoice->status_id = Invoice::STATUS_SENT;
} }
return $this; return $this;
} }
@ -318,7 +318,7 @@ class InvoiceService
} elseif ($this->invoice->balance > 0 && $this->invoice->balance < $this->invoice->amount) { } elseif ($this->invoice->balance > 0 && $this->invoice->balance < $this->invoice->amount) {
$this->invoice->status_id = Invoice::STATUS_PARTIAL; $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; $this->invoice->status_id = Invoice::STATUS_SENT;
} }