From e6eb899f796486365a8a5527b2785f856d991b38 Mon Sep 17 00:00:00 2001 From: = Date: Sat, 5 Jun 2021 20:12:10 +1000 Subject: [PATCH] Fixes for contact registration --- app/Http/Middleware/ContactRegister.php | 33 ++++++++++++++++++++++--- routes/client.php | 4 +-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/app/Http/Middleware/ContactRegister.php b/app/Http/Middleware/ContactRegister.php index b19840b74f..640ef0f1c7 100644 --- a/app/Http/Middleware/ContactRegister.php +++ b/app/Http/Middleware/ContactRegister.php @@ -19,10 +19,36 @@ class ContactRegister */ public function handle($request, Closure $next) { - // Resolving based on subdomain. Used in version 5 hosted platform. - if ($request->subdomain) { - $company = Company::where('subdomain', $request->subdomain)->firstOrFail(); + if (strpos($request->getHost(), 'invoicing.co') !== false) + { + $subdomain = explode('.', $request->getHost())[0]; + + $query = [ + 'subdomain' => $subdomain, + 'portal_mode' => 'subdomain', + ]; + + $company = Company::where($query)->first(); + + if($company) + { + abort_unless($company->getSetting('enable_client_registration'), 404); + + $request->merge(['key' => $company->company_key]); + + return $next($request); + } + + } + + $query = [ + 'portal_domain' => $request->getSchemeAndHttpHost(), + 'portal_mode' => 'domain', + ]; + + if($company = Company::where($query)->first()) + { abort_unless($company->getSetting('enable_client_registration'), 404); $request->merge(['key' => $company->company_key]); @@ -30,6 +56,7 @@ class ContactRegister return $next($request); } + // For self-hosted platforms with multiple companies, resolving is done using company key // if it doesn't resolve using a domain. if ($request->route()->parameter('company_key') && Ninja::isSelfHost()) { diff --git a/routes/client.php b/routes/client.php index 65a643cced..8fadbf5415 100644 --- a/routes/client.php +++ b/routes/client.php @@ -1,4 +1,4 @@ -name('c Route::post('client/login', 'Auth\ContactLoginController@login')->name('client.login.submit'); Route::get('client/register/{company_key?}', 'Auth\ContactRegisterController@showRegisterForm')->name('client.register')->middleware(['domain_db', 'contact_account','locale']); -Route::post('client/register/{company_key?}', 'Auth\ContactRegisterController@register'); +Route::post('client/register/{company_key?}', 'Auth\ContactRegisterController@register')->middleware(['domain_db', 'contact_account','locale']); Route::get('client/password/reset', 'Auth\ContactForgotPasswordController@showLinkRequestForm')->name('client.password.request')->middleware(['domain_db', 'contact_account','locale']); Route::post('client/password/email', 'Auth\ContactForgotPasswordController@sendResetLinkEmail')->name('client.password.email')->middleware('locale');