From cbcf0dc238d38b383ebff498bfe7b118f3ce9f6b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 3 Aug 2022 20:06:09 +1000 Subject: [PATCH 01/11] Update customers for stripe --- .../Requests/Client/UpdateClientRequest.php | 4 - .../Stripe/Jobs/UpdateCustomer.php | 86 +++++++++++++++++++ 2 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php diff --git a/app/Http/Requests/Client/UpdateClientRequest.php b/app/Http/Requests/Client/UpdateClientRequest.php index d263d11318b3..cf0da48a6926 100644 --- a/app/Http/Requests/Client/UpdateClientRequest.php +++ b/app/Http/Requests/Client/UpdateClientRequest.php @@ -97,10 +97,6 @@ class UpdateClientRequest extends Request { $input = $this->all(); - if (isset($input['group_settings_id'])) { - $input['group_settings_id'] = $this->decodePrimaryKey($input['group_settings_id']); - } - /* If the user removes the currency we must always set the default */ if (array_key_exists('settings', $input) && ! array_key_exists('currency_id', $input['settings'])) { $input['settings']['currency_id'] = (string) auth()->user()->company()->settings->currency_id; diff --git a/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php b/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php new file mode 100644 index 000000000000..083c1ab99217 --- /dev/null +++ b/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php @@ -0,0 +1,86 @@ +company_key = $company_key; + $this->company_gateway_id = $company_gateway_id; + $this->client_id = $client_id; + $this->customer_id = $customer_id; + } + + public function handle() + { + + MultiDB::findAndSetDbByCompanyKey($this->company_key); + + $company = Company::where('company_key', $this->company_key)->first(); + + $company_gateway = CompanyGateway::find($this->company_gateway_id); + + $stripe = $company_gateway->driver()->init(); + + $customer = $company_gateway->getCustomer($this->customer_id); + + $client = Client::withTrashed()->find($this->client_id); + + //Else create a new record + $data['name'] = $client->present()->name(); + $data['phone'] = substr($client->present()->phone(), 0, 20); + + $data['address']['line1'] = $client->address1; + $data['address']['line2'] = $client->address2; + $data['address']['city'] = $client->city; + $data['address']['postal_code'] = $client->postal_code; + $data['address']['state'] = $client->state; + $data['address']['country'] = $client->country ? $client->country->iso_3166_2 : ''; + + \Stripe\Customer::update($this->customer_id, $data, $stripe->stripe_connect_auth); + + } +} From 68fe664ad6cd58ac59eefef96811bfdd5f6d3d0c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 4 Aug 2022 09:29:30 +1000 Subject: [PATCH 02/11] Return early when deleting non existent filename --- app/Http/Middleware/SetDomainNameDb.php | 2 -- app/Models/Backup.php | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Http/Middleware/SetDomainNameDb.php b/app/Http/Middleware/SetDomainNameDb.php index 073cf03be88f..7596948867b8 100644 --- a/app/Http/Middleware/SetDomainNameDb.php +++ b/app/Http/Middleware/SetDomainNameDb.php @@ -50,7 +50,6 @@ class SetDomainNameDb ]; if ($company = MultiDB::findAndSetDbByDomain($query)) { - //$request->merge(['company_key' => $company->company_key]); session()->put('company_key', $company->company_key); } else { if ($request->json) { @@ -68,7 +67,6 @@ class SetDomainNameDb ]; if ($company = MultiDB::findAndSetDbByDomain($query)) { - //$request->merge(['company_key' => $company->company_key]); session()->put('company_key', $company->company_key); } else { if ($request->json) { diff --git a/app/Models/Backup.php b/app/Models/Backup.php index 65352994c90d..2ddc96a685ae 100644 --- a/app/Models/Backup.php +++ b/app/Models/Backup.php @@ -51,6 +51,9 @@ class Backup extends BaseModel { nlog('deleting => '.$this->filename); + if(!$this->filename) + return; + try { Storage::disk(config('filesystems.default'))->delete($this->filename); } catch (\Exception $e) { From 95d53ada6623ae5e61f54058cd95001ef8e3361a Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 4 Aug 2022 11:26:58 +1000 Subject: [PATCH 03/11] Minor fixes for PDF generation --- app/Http/Controllers/ClientPortal/InvitationController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ClientPortal/InvitationController.php b/app/Http/Controllers/ClientPortal/InvitationController.php index 790a75af08f1..d3e79873aea7 100644 --- a/app/Http/Controllers/ClientPortal/InvitationController.php +++ b/app/Http/Controllers/ClientPortal/InvitationController.php @@ -195,7 +195,7 @@ class InvitationController extends Controller $file_name = $invitation->{$entity}->numberFormatter().'.pdf'; - $file = CreateRawPdf::dispatchNow($invitation, $invitation->company->db); + $file = (new CreateRawPdf($invitation, $invitation->company->db))->handle(); $headers = ['Content-Type' => 'application/pdf']; From 24b37e278994ed08a02d3077bb80ce87133b32eb Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 4 Aug 2022 12:40:14 +1000 Subject: [PATCH 04/11] Minor fixes for PDF generation --- app/Http/ValidationRules/Account/BlackListRule.php | 3 ++- app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Http/ValidationRules/Account/BlackListRule.php b/app/Http/ValidationRules/Account/BlackListRule.php index 1bb968aaf17d..51fab56af44a 100644 --- a/app/Http/ValidationRules/Account/BlackListRule.php +++ b/app/Http/ValidationRules/Account/BlackListRule.php @@ -23,7 +23,8 @@ class BlackListRule implements Rule 'candassociates.com', 'vusra.com', 'fourthgenet.com', - 'arxxwalls.com' + 'arxxwalls.com', + 'superhostforumla.com' ]; /** diff --git a/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php b/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php index 083c1ab99217..bc4fd8e9a234 100644 --- a/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php +++ b/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php @@ -56,7 +56,9 @@ class UpdateCustomer implements ShouldQueue public function handle() { - + if($this->company->id !== config('ninja.ninja_default_company_id')) + return; + MultiDB::findAndSetDbByCompanyKey($this->company_key); $company = Company::where('company_key', $this->company_key)->first(); From 0ba05bc985ecb28a28302f40145410ee4e3e8797 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 4 Aug 2022 13:19:34 +1000 Subject: [PATCH 05/11] Update customer for stripe --- app/PaymentDrivers/Stripe/CreditCard.php | 3 +++ app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php | 11 ++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/PaymentDrivers/Stripe/CreditCard.php b/app/PaymentDrivers/Stripe/CreditCard.php index c4939c889e4b..1b8525c2f8a1 100644 --- a/app/PaymentDrivers/Stripe/CreditCard.php +++ b/app/PaymentDrivers/Stripe/CreditCard.php @@ -20,6 +20,7 @@ use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; use App\PaymentDrivers\StripePaymentDriver; +use App\PaymentDrivers\Stripe\Jobs\UpdateCustomer; use Stripe\PaymentIntent; use Stripe\PaymentMethod; @@ -129,6 +130,8 @@ class CreditCard public function processSuccessfulPayment() { + UpdateCustomer::dispatch($this->stripe->company->company_key, $this->stripe->company_gateway->id, $this->stripe->client->id); + $stripe_method = $this->stripe->getStripePaymentMethod($this->stripe->payment_hash->data->server_response->payment_method); $data = [ diff --git a/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php b/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php index bc4fd8e9a234..46c8646f562b 100644 --- a/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php +++ b/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php @@ -44,21 +44,18 @@ class UpdateCustomer implements ShouldQueue private int $client_id; - private string $customer_id; - - public function __construct(string $company_key, int $company_gateway_id, int $client_id, string $customer_id) + public function __construct(string $company_key, int $company_gateway_id, int $client_id) { $this->company_key = $company_key; $this->company_gateway_id = $company_gateway_id; $this->client_id = $client_id; - $this->customer_id = $customer_id; } public function handle() { if($this->company->id !== config('ninja.ninja_default_company_id')) return; - + MultiDB::findAndSetDbByCompanyKey($this->company_key); $company = Company::where('company_key', $this->company_key)->first(); @@ -67,7 +64,7 @@ class UpdateCustomer implements ShouldQueue $stripe = $company_gateway->driver()->init(); - $customer = $company_gateway->getCustomer($this->customer_id); + $customer = $stripe->findOrCreateCustomer(); $client = Client::withTrashed()->find($this->client_id); @@ -82,7 +79,7 @@ class UpdateCustomer implements ShouldQueue $data['address']['state'] = $client->state; $data['address']['country'] = $client->country ? $client->country->iso_3166_2 : ''; - \Stripe\Customer::update($this->customer_id, $data, $stripe->stripe_connect_auth); + \Stripe\Customer::update($customer->id, $data, $stripe->stripe_connect_auth); } } From 12febeadfef62bb0bb91cb2ac268d0fb6de06bf9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 4 Aug 2022 13:22:19 +1000 Subject: [PATCH 06/11] Update customer for stripe --- app/PaymentDrivers/Stripe/CreditCard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/PaymentDrivers/Stripe/CreditCard.php b/app/PaymentDrivers/Stripe/CreditCard.php index 1b8525c2f8a1..f0ca05eaa34d 100644 --- a/app/PaymentDrivers/Stripe/CreditCard.php +++ b/app/PaymentDrivers/Stripe/CreditCard.php @@ -130,7 +130,7 @@ class CreditCard public function processSuccessfulPayment() { - UpdateCustomer::dispatch($this->stripe->company->company_key, $this->stripe->company_gateway->id, $this->stripe->client->id); + UpdateCustomer::dispatch($this->stripe->company_gateway->company->company_key, $this->stripe->company_gateway->id, $this->stripe->client->id); $stripe_method = $this->stripe->getStripePaymentMethod($this->stripe->payment_hash->data->server_response->payment_method); From adcdd6917745f3b3708060d19b080b321e684dbd Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 4 Aug 2022 13:23:49 +1000 Subject: [PATCH 07/11] Update customer for stripe --- app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php b/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php index 46c8646f562b..47f349283dfd 100644 --- a/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php +++ b/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php @@ -53,13 +53,14 @@ class UpdateCustomer implements ShouldQueue public function handle() { - if($this->company->id !== config('ninja.ninja_default_company_id')) - return; MultiDB::findAndSetDbByCompanyKey($this->company_key); $company = Company::where('company_key', $this->company_key)->first(); + if($company->id !== config('ninja.ninja_default_company_id')) + return; + $company_gateway = CompanyGateway::find($this->company_gateway_id); $stripe = $company_gateway->driver()->init(); From 6b30b38e32fe518ea97e86e599b0b4acb41e4c9a Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 4 Aug 2022 13:37:16 +1000 Subject: [PATCH 08/11] Fixes for update customer --- .../Stripe/Jobs/UpdateCustomer.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php b/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php index 47f349283dfd..a9aadefde559 100644 --- a/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php +++ b/app/PaymentDrivers/Stripe/Jobs/UpdateCustomer.php @@ -62,13 +62,11 @@ class UpdateCustomer implements ShouldQueue return; $company_gateway = CompanyGateway::find($this->company_gateway_id); - - $stripe = $company_gateway->driver()->init(); - - $customer = $stripe->findOrCreateCustomer(); - $client = Client::withTrashed()->find($this->client_id); + $stripe = $company_gateway->driver($client)->init(); + + $customer = $stripe->findOrCreateCustomer(); //Else create a new record $data['name'] = $client->present()->name(); $data['phone'] = substr($client->present()->phone(), 0, 20); @@ -80,6 +78,14 @@ class UpdateCustomer implements ShouldQueue $data['address']['state'] = $client->state; $data['address']['country'] = $client->country ? $client->country->iso_3166_2 : ''; + $data['shipping']['name'] = $client->present()->name(); + $data['shipping']['address']['line1'] = $client->shipping_address1; + $data['shipping']['address']['line2'] = $client->shipping_address2; + $data['shipping']['address']['city'] = $client->shipping_city; + $data['shipping']['address']['postal_code'] = $client->shipping_postal_code; + $data['shipping']['address']['state'] = $client->shipping_state; + $data['shipping']['address']['country'] = $client->shipping_country ? $client->shipping_country->iso_3166_2 : ''; + \Stripe\Customer::update($customer->id, $data, $stripe->stripe_connect_auth); } From 54ba4de7adc0b64d11ee73ea16d28b27b1ab5923 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 4 Aug 2022 14:01:31 +1000 Subject: [PATCH 09/11] Fixes for update customer --- app/Http/Controllers/ClientPortal/InvitationController.php | 1 - app/Http/Controllers/VendorPortal/InvitationController.php | 1 - 2 files changed, 2 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/InvitationController.php b/app/Http/Controllers/ClientPortal/InvitationController.php index d3e79873aea7..5d421a2f026a 100644 --- a/app/Http/Controllers/ClientPortal/InvitationController.php +++ b/app/Http/Controllers/ClientPortal/InvitationController.php @@ -119,7 +119,6 @@ class InvitationController extends Controller return redirect()->route('client.login'); } else { - nlog("else - default - login contact"); request()->session()->invalidate(); auth()->guard('contact')->loginUsingId($client_contact->id, true); } diff --git a/app/Http/Controllers/VendorPortal/InvitationController.php b/app/Http/Controllers/VendorPortal/InvitationController.php index 9c20dab32620..4a295a6e646b 100644 --- a/app/Http/Controllers/VendorPortal/InvitationController.php +++ b/app/Http/Controllers/VendorPortal/InvitationController.php @@ -73,7 +73,6 @@ class InvitationController extends Controller auth()->guard('vendor')->loginUsingId($vendor_contact->id, true); } else { - nlog("else - default - login contact"); request()->session()->invalidate(); auth()->guard('vendor')->loginUsingId($vendor_contact->id, true); } From 92c236e7889a1fc94ddb749f6acf2bcc497d9f57 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 4 Aug 2022 16:22:48 +1000 Subject: [PATCH 10/11] Fixes for payment emails --- app/Http/Controllers/PaymentController.php | 1 - .../VendorContactHashLoginController.php | 42 +++++ app/Http/Kernel.php | 2 + app/Http/Middleware/VendorContactKeyLogin.php | 155 ++++++++++++++++++ app/Models/VendorContact.php | 9 + app/Services/Payment/SendEmail.php | 10 +- app/Transformers/VendorContactTransformer.php | 1 + routes/vendor.php | 2 + 8 files changed, 216 insertions(+), 6 deletions(-) create mode 100644 app/Http/Controllers/VendorPortal/VendorContactHashLoginController.php create mode 100644 app/Http/Middleware/VendorContactKeyLogin.php diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index 4c87d6dc1547..01f5354817ab 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -613,7 +613,6 @@ class PaymentController extends BaseController // code... break; case 'email': - //dispatch email to queue $payment->service()->sendEmail(); if (! $bulk) { diff --git a/app/Http/Controllers/VendorPortal/VendorContactHashLoginController.php b/app/Http/Controllers/VendorPortal/VendorContactHashLoginController.php new file mode 100644 index 000000000000..21e11a9c0932 --- /dev/null +++ b/app/Http/Controllers/VendorPortal/VendorContactHashLoginController.php @@ -0,0 +1,42 @@ +setRedirectPath()); + } + + public function errorPage() + { + return render('generic.error', ['title' => session()->get('title'), 'notification' => session()->get('notification')]); + } + + +} diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 135355c377ae..0590a73841a5 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -42,6 +42,7 @@ use App\Http\Middleware\TrimStrings; use App\Http\Middleware\TrustProxies; use App\Http\Middleware\UrlSetDb; use App\Http\Middleware\UserVerified; +use App\Http\Middleware\VendorContactKeyLogin; use App\Http\Middleware\VendorLocale; use App\Http\Middleware\VerifyCsrfToken; use App\Http\Middleware\VerifyHash; @@ -166,6 +167,7 @@ class Kernel extends HttpKernel 'shop_token_auth' => ShopTokenAuth::class, 'phantom_secret' => PhantomSecret::class, 'contact_key_login' => ContactKeyLogin::class, + 'vendor_contact_key_login' => VendorContactKeyLogin::class, 'check_client_existence' => CheckClientExistence::class, 'user_verified' => UserVerified::class, 'document_db' => SetDocumentDb::class, diff --git a/app/Http/Middleware/VendorContactKeyLogin.php b/app/Http/Middleware/VendorContactKeyLogin.php new file mode 100644 index 000000000000..2c5dc0a97438 --- /dev/null +++ b/app/Http/Middleware/VendorContactKeyLogin.php @@ -0,0 +1,155 @@ +check()) { + Auth::guard('vendor')->logout(); + $request->session()->invalidate(); + } + + if ($request->segment(2) && $request->segment(2) == 'magic_link' && $request->segment(3)) { + $payload = Cache::get($request->segment(3)); + + if (! $payload) { + abort(403, 'Link expired.'); + } + + $contact_email = $payload['email']; + + if ($vendor_contact = VendorContact::where('email', $contact_email)->where('company_id', $payload['company_id'])->first()) { + if (empty($vendor_contact->email)) { + $vendor_contact->email = Str::random(15).'@example.com'; + } + $vendor_contact->save(); + + auth()->guard('vendor')->loginUsingId($vendor_contact->id, true); + + if ($request->query('redirect') && ! empty($request->query('redirect'))) { + return redirect()->to($request->query('redirect')); + } + + return redirect($this->setRedirectPath()); + } + } elseif ($request->segment(3) && config('ninja.db.multi_db_enabled')) { + if (MultiDB::findAndSetDbByContactKey($request->segment(3))) { + if ($vendor_contact = VendorContact::where('contact_key', $request->segment(3))->first()) { + if (empty($vendor_contact->email)) { + $vendor_contact->email = Str::random(6).'@example.com'; + } + $vendor_contact->save(); + + auth()->guard('vendor')->loginUsingId($vendor_contact->id, true); + + if ($request->query('next')) { + return redirect()->to($request->query('next')); + } + + return redirect($this->setRedirectPath()); + } + } + } elseif ($request->segment(2) && $request->segment(2) == 'key_login' && $request->segment(3)) { + if ($vendor_contact = VendorContact::where('contact_key', $request->segment(3))->first()) { + if (empty($vendor_contact->email)) { + $vendor_contact->email = Str::random(6).'@example.com'; + $vendor_contact->save(); + } + + auth()->guard('vendor')->loginUsingId($vendor_contact->id, true); + + if ($request->query('next')) { + return redirect($request->query('next')); + } + + return redirect($this->setRedirectPath()); + } + } elseif ($request->has('vendor_hash') && config('ninja.db.multi_db_enabled')) { + if (MultiDB::findAndSetDbByClientHash($request->input('vendor_hash'))) { + if ($client = Vendor::where('vendor_hash', $request->input('vendor_hash'))->first()) { + $primary_contact = $client->primary_contact()->first(); + + if (empty($primary_contact->email)) { + $primary_contact->email = Str::random(6).'@example.com'; + } + $primary_contact->save(); + + auth()->guard('vendor')->loginUsingId($primary_contact->id, true); + + return redirect($this->setRedirectPath()); + } + } + } elseif ($request->has('vendor_hash')) { + if ($client = Vendor::where('vendor_hash', $request->input('vendor_hash'))->first()) { + $primary_contact = $client->primary_contact()->first(); + + if (empty($primary_contact->email)) { + $primary_contact->email = Str::random(6).'@example.com'; + } + $primary_contact->save(); + + auth()->guard('vendor')->loginUsingId($primary_contact->id, true); + + return redirect($this->setRedirectPath()); + } + } elseif ($request->segment(3)) { + if ($vendor_contact = VendorContact::where('contact_key', $request->segment(3))->first()) { + if (empty($vendor_contact->email)) { + $vendor_contact->email = Str::random(6).'@example.com'; + $vendor_contact->save(); + } + + auth()->guard('vendor')->loginUsingId($vendor_contact->id, true); + + if ($request->query('next')) { + return redirect($request->query('next')); + } + + return redirect($this->setRedirectPath()); + } + } + //28-02-2022 middleware should not allow this to progress as we should have redirected by this stage. + abort(404, 'Unable to authenticate.'); + + return $next($request); + } + + private function setRedirectPath() + { + + return 'vendors/purchase_orders'; + + } +} diff --git a/app/Models/VendorContact.php b/app/Models/VendorContact.php index 721ae7222213..4311b3320b3c 100644 --- a/app/Models/VendorContact.php +++ b/app/Models/VendorContact.php @@ -154,4 +154,13 @@ class VendorContact extends Authenticatable implements HasLocalePreference { return $this->hasMany(PurchaseOrderInvitation::class); } + + public function getLoginLink() + { + + $domain = isset($this->company->portal_domain) ? $this->company->portal_domain : $this->company->domain(); + + return $domain.'/vendors/key_login/'.$this->contact_key; + + } } diff --git a/app/Services/Payment/SendEmail.php b/app/Services/Payment/SendEmail.php index 598fd92f3dd9..39c3e063f7fc 100644 --- a/app/Services/Payment/SendEmail.php +++ b/app/Services/Payment/SendEmail.php @@ -34,10 +34,10 @@ class SendEmail { $this->payment->load('company', 'client.contacts'); - $this->payment->client->contacts->each(function ($contact) { - if ($contact->email) { - EmailPayment::dispatch($this->payment, $this->payment->company, $contact); - } - }); + $contact = $this->payment->client->contacts()->first(); + + if ($contact->email) + EmailPayment::dispatch($this->payment, $this->payment->company, $contact); + } } diff --git a/app/Transformers/VendorContactTransformer.php b/app/Transformers/VendorContactTransformer.php index da9f5a6f3e0e..dbbdf6daedc4 100644 --- a/app/Transformers/VendorContactTransformer.php +++ b/app/Transformers/VendorContactTransformer.php @@ -42,6 +42,7 @@ class VendorContactTransformer extends EntityTransformer 'custom_value2' => $vendor->custom_value2 ?: '', 'custom_value3' => $vendor->custom_value3 ?: '', 'custom_value4' => $vendor->custom_value4 ?: '', + 'link' => $vendor->getLoginLink(), ]; } } diff --git a/routes/vendor.php b/routes/vendor.php index 68056bf44bb9..d26ce90ee38e 100644 --- a/routes/vendor.php +++ b/routes/vendor.php @@ -15,9 +15,11 @@ use App\Http\Controllers\VendorPortal\InvitationController; use App\Http\Controllers\VendorPortal\PurchaseOrderController; use App\Http\Controllers\VendorPortal\UploadController; use App\Http\Controllers\VendorPortal\VendorContactController; +use App\Http\Controllers\VendorPortal\VendorContactHashLoginController; use Illuminate\Support\Facades\Route; Route::get('vendors', [VendorContactLoginController::class, 'catch'])->name('vendor.catchall')->middleware(['domain_db', 'contact_account','vendor_locale']); //catch all +Route::get('vendor/key_login/{contact_key}', [VendorContactHashLoginController::class, 'login'])->name('contact_login')->middleware(['domain_db','contact_key_login']); Route::group(['middleware' => ['invite_db'], 'prefix' => 'vendor', 'as' => 'vendor.'], function () { /*Invitation catches*/ From b9c198f38e5ff43aff82cae8eeabd3841ed70a98 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 4 Aug 2022 16:30:11 +1000 Subject: [PATCH 11/11] Vendor Contact key login --- app/Factory/VendorContactFactory.php | 2 ++ app/Http/Middleware/VendorContactKeyLogin.php | 4 ++-- app/Models/VendorContact.php | 2 +- routes/vendor.php | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/Factory/VendorContactFactory.php b/app/Factory/VendorContactFactory.php index 196694e36bc2..b46ce74de13d 100644 --- a/app/Factory/VendorContactFactory.php +++ b/app/Factory/VendorContactFactory.php @@ -12,6 +12,7 @@ namespace App\Factory; use App\Models\VendorContact; +use Illuminate\Support\Str; class VendorContactFactory { @@ -21,6 +22,7 @@ class VendorContactFactory $vendor_contact->first_name = ''; $vendor_contact->user_id = $user_id; $vendor_contact->company_id = $company_id; + $vendor_contact->contact_key = Str::random(40); $vendor_contact->id = 0; return $vendor_contact; diff --git a/app/Http/Middleware/VendorContactKeyLogin.php b/app/Http/Middleware/VendorContactKeyLogin.php index 2c5dc0a97438..334f6609c72f 100644 --- a/app/Http/Middleware/VendorContactKeyLogin.php +++ b/app/Http/Middleware/VendorContactKeyLogin.php @@ -149,7 +149,7 @@ class VendorContactKeyLogin private function setRedirectPath() { - return 'vendors/purchase_orders'; - + return 'vendor/purchase_orders'; + } } diff --git a/app/Models/VendorContact.php b/app/Models/VendorContact.php index 4311b3320b3c..72479d5a6939 100644 --- a/app/Models/VendorContact.php +++ b/app/Models/VendorContact.php @@ -160,7 +160,7 @@ class VendorContact extends Authenticatable implements HasLocalePreference $domain = isset($this->company->portal_domain) ? $this->company->portal_domain : $this->company->domain(); - return $domain.'/vendors/key_login/'.$this->contact_key; + return $domain.'/vendor/key_login/'.$this->contact_key; } } diff --git a/routes/vendor.php b/routes/vendor.php index d26ce90ee38e..59fa34049798 100644 --- a/routes/vendor.php +++ b/routes/vendor.php @@ -19,7 +19,7 @@ use App\Http\Controllers\VendorPortal\VendorContactHashLoginController; use Illuminate\Support\Facades\Route; Route::get('vendors', [VendorContactLoginController::class, 'catch'])->name('vendor.catchall')->middleware(['domain_db', 'contact_account','vendor_locale']); //catch all -Route::get('vendor/key_login/{contact_key}', [VendorContactHashLoginController::class, 'login'])->name('contact_login')->middleware(['domain_db','contact_key_login']); +Route::get('vendor/key_login/{contact_key}', [VendorContactHashLoginController::class, 'login'])->name('contact_login')->middleware(['domain_db','vendor_contact_key_login']); Route::group(['middleware' => ['invite_db'], 'prefix' => 'vendor', 'as' => 'vendor.'], function () { /*Invitation catches*/