From b91af0dc690a86447820da4933216cd63b9d5928 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 29 Jul 2021 12:19:56 +1000 Subject: [PATCH 1/2] Client Contact password reset links --- .../Auth/ContactForgotPasswordController.php | 2 +- .../Auth/ContactResetPasswordController.php | 25 +++++++++++++++++++ app/Models/ClientContact.php | 4 +++ app/Repositories/BaseRepository.php | 4 +-- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Auth/ContactForgotPasswordController.php b/app/Http/Controllers/Auth/ContactForgotPasswordController.php index a3f515cdc2e9..be9e54b2a711 100644 --- a/app/Http/Controllers/Auth/ContactForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ContactForgotPasswordController.php @@ -76,7 +76,7 @@ class ContactForgotPasswordController extends Controller public function sendResetLinkEmail(ContactPasswordResetRequest $request) { - + $user = MultiDB::hasContact($request->input('email')); $this->validateEmail($request); diff --git a/app/Http/Controllers/Auth/ContactResetPasswordController.php b/app/Http/Controllers/Auth/ContactResetPasswordController.php index 7f6b0e047e1c..6de7c2972933 100644 --- a/app/Http/Controllers/Auth/ContactResetPasswordController.php +++ b/app/Http/Controllers/Auth/ContactResetPasswordController.php @@ -71,6 +71,31 @@ class ContactResetPasswordController extends Controller ); } + public function reset(Request $request) + { + $request->validate($this->rules(), $this->validationErrorMessages()); + + // Here we will attempt to reset the user's password. If it is successful we + // will update the password on an actual user model and persist it to the + // database. Otherwise we will parse the error and return the response. + $response = $this->broker()->reset( + $this->credentials($request), function ($user, $password) { + $this->resetPassword($user, $password); + } + ); + + // Added this because it collides the session between + // client & main portal giving unlimited redirects. + auth()->logout(); + + // If the password was successfully reset, we will redirect the user back to + // the application's home authenticated view. If there is an error we can + // redirect them back to where they came from with their error message. + return $response == Password::PASSWORD_RESET + ? $this->sendResetResponse($request, $response) + : $this->sendResetFailedResponse($request, $response); + } + protected function guard() { return Auth::guard('contact'); diff --git a/app/Models/ClientContact.php b/app/Models/ClientContact.php index 1e5d1ee75011..7e532178c555 100644 --- a/app/Models/ClientContact.php +++ b/app/Models/ClientContact.php @@ -198,6 +198,10 @@ class ClientContact extends Authenticatable implements HasLocalePreference public function sendPasswordResetNotification($token) { + + $this->token = $token; + $this->save(); + $nmo = new NinjaMailerObject; $nmo->mailable = new NinjaMailer((new ClientContactResetPasswordObject($token, $this))->build()); $nmo->to_user = $this; diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 6e9906037166..574153e94631 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -299,8 +299,8 @@ class BaseRepository if((int)$model->balance != 0 && $model->partial > $model->amount) $model->partial = min($model->amount, $model->balance); - /* Update product details if necessary */ - if ($model->company->update_products && $model->id) + /* Update product details if necessary - if we are inside a transaction - do nothing */ + if ($model->company->update_products && $model->id && \DB::transactionLevel() == 0) UpdateOrCreateProduct::dispatch($model->line_items, $model, $model->company); /* Perform model specific tasks */ From 6d8ac6aa35043b8dd77cb405e5f360cc840ba8ab Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 29 Jul 2021 13:37:23 +1000 Subject: [PATCH 2/2] Minor fixes --- app/Http/Controllers/Auth/ContactForgotPasswordController.php | 1 - app/Http/Controllers/PreviewController.php | 1 + app/PaymentDrivers/StripePaymentDriver.php | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Auth/ContactForgotPasswordController.php b/app/Http/Controllers/Auth/ContactForgotPasswordController.php index be9e54b2a711..1e65bd2ff838 100644 --- a/app/Http/Controllers/Auth/ContactForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ContactForgotPasswordController.php @@ -76,7 +76,6 @@ class ContactForgotPasswordController extends Controller public function sendResetLinkEmail(ContactPasswordResetRequest $request) { - $user = MultiDB::hasContact($request->input('email')); $this->validateEmail($request); diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index 1b6d5dbbe1b8..8861ca321aad 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -31,6 +31,7 @@ use App\Repositories\InvoiceRepository; use App\Repositories\QuoteRepository; use App\Repositories\RecurringInvoiceRepository; use App\Services\PdfMaker\Design as PdfMakerDesign; +use App\Services\PdfMaker\Design as PdfDesignModel; use App\Services\PdfMaker\Design; use App\Services\PdfMaker\PdfMaker; use App\Utils\HostedPDF\NinjaPdf; diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index b5d030377416..e0cc6af1e117 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -312,7 +312,7 @@ class StripePaymentDriver extends BaseDriver $data['name'] = $this->client->present()->name(); $data['phone'] = $this->client->present()->phone(); - + if (filter_var($this->client->present()->email(), FILTER_VALIDATE_EMAIL)) { $data['email'] = $this->client->present()->email(); }