From d68e40433c78d0af3db37a2acfefb797fee9d50e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 8 Jun 2021 21:45:23 +1000 Subject: [PATCH] Fixes for client portal links --- .../ClientPortal/InvitationController.php | 11 +++++++---- app/Http/Middleware/ContactKeyLogin.php | 2 +- app/Jobs/Company/CompanyImport.php | 15 +++++++++------ app/Transformers/AccountTransformer.php | 1 + 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/InvitationController.php b/app/Http/Controllers/ClientPortal/InvitationController.php index ff38ab69a8..8d85ca5fde 100644 --- a/app/Http/Controllers/ClientPortal/InvitationController.php +++ b/app/Http/Controllers/ClientPortal/InvitationController.php @@ -55,18 +55,21 @@ class InvitationController extends Controller ->firstOrFail(); /* Return early if we have the correct client_hash embedded */ + $client_contact = $invitation->contact; + + if(empty($client_contact->email)) + $client_contact->email = Str::random(15) . "@example.com"; $client_contact->save(); if (request()->has('client_hash') && request()->input('client_hash') == $invitation->contact->client->client_hash) { - auth()->guard('contact')->loginUsingId($invitation->contact->id, true); + auth()->guard('contact')->login($client_contact, true); } elseif ((bool) $invitation->contact->client->getSetting('enable_client_portal_password') !== false) { - - //If no contact password is set - this will cause a 401 error - instead redirect to the client.login route $this->middleware('auth:contact'); return redirect()->route('client.login'); } else { - auth()->guard('contact')->loginUsingId($invitation->contact->id, true); + nlog("else - default - login contact"); + auth()->guard('contact')->login($client_contact, true); } diff --git a/app/Http/Middleware/ContactKeyLogin.php b/app/Http/Middleware/ContactKeyLogin.php index 92361e1c56..7105910b86 100644 --- a/app/Http/Middleware/ContactKeyLogin.php +++ b/app/Http/Middleware/ContactKeyLogin.php @@ -46,7 +46,7 @@ class ContactKeyLogin if($client_contact = ClientContact::where('email', $contact_email)->where('company_id', $payload['company_id'])->first()){ if(empty($client_contact->email)) - $client_contact->email = Str::random(6) . "@example.com"; $client_contact->save(); + $client_contact->email = Str::random(15) . "@example.com"; $client_contact->save(); auth()->guard('contact')->login($client_contact, true); diff --git a/app/Jobs/Company/CompanyImport.php b/app/Jobs/Company/CompanyImport.php index e04794db35..f3a1023094 100644 --- a/app/Jobs/Company/CompanyImport.php +++ b/app/Jobs/Company/CompanyImport.php @@ -212,12 +212,12 @@ class CompanyImport implements ShouldQueue if(count($backup_users) > 1){ $this->message = 'Only one user can be in the import for a Free Account'; - $this->pre_flight_checks_pass = false; + $this->pre_flight_checks_pass = false; } if(count($backup_users) == 1 && $company_owner->email != $backup_users[0]->email) { $this->message = 'Account emails do not match. Account owner email must match backup user email'; - $this->pre_flight_checks_pass = false; + $this->pre_flight_checks_pass = false; } $backup_users_emails = array_column($backup_users, 'email'); @@ -230,7 +230,7 @@ class CompanyImport implements ShouldQueue if($this->account->plan == 'pro'){ $this->message = 'Pro plan is limited to one user, you have multiple users in the backup file'; - $this->pre_flight_checks_pass = false; + $this->pre_flight_checks_pass = false; } if($this->account->plan == 'enterprise'){ @@ -241,7 +241,7 @@ class CompanyImport implements ShouldQueue if($total_import_users > $account_plan_num_user){ $this->message = "Total user count ({$total_import_users}) greater than your plan allows ({$account_plan_num_user})"; - $this->pre_flight_checks_pass = false; + $this->pre_flight_checks_pass = false; } } @@ -255,12 +255,15 @@ class CompanyImport implements ShouldQueue $this->message = "You are attempting to import ({$client_count}) clients, your current plan allows a total of ({$client_limit})"; - $this->pre_flight_checks_pass = false; + $this->pre_flight_checks_pass = false; } } + nlog($this->message); + nlog($this->pre_flight_checks_pass); + return $this; } @@ -278,7 +281,7 @@ class CompanyImport implements ShouldQueue //perform some magic here } - if(!$this->pre_flight_checks_pass) + if($this->pre_flight_checks_pass === false) { $nmo = new NinjaMailerObject; $nmo->mailable = new CompanyImportFailure($this->company, $this->message); diff --git a/app/Transformers/AccountTransformer.php b/app/Transformers/AccountTransformer.php index f8e93a4557..032b33ea3f 100644 --- a/app/Transformers/AccountTransformer.php +++ b/app/Transformers/AccountTransformer.php @@ -15,6 +15,7 @@ use App\Models\Account; use App\Models\Company; use App\Models\CompanyUser; use App\Models\User; +use App\Utils\Ninja; use App\Utils\Traits\MakesHash; /**