diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index ad0a849c85..ca48a17faf 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -589,7 +589,7 @@ class CompanySettings extends BaseSettings '$credit.po_number', '$credit.date', '$credit.balance', - '$credit.amount', + '$credit.total', ], 'product_columns' => [ '$product.product_key', diff --git a/app/Designs/Designer.php b/app/Designs/Designer.php index 309c764b25..14510e3777 100644 --- a/app/Designs/Designer.php +++ b/app/Designs/Designer.php @@ -336,7 +336,7 @@ class Designer '$credit.po_number' => '$credit.po_number_label$credit.po_number', '$credit.date' => '$credit.date_label$credit.date', '$credit.balance' => '$credit.balance_label$credit.balance', - '$credit.amount' => '$credit.amount_label$credit.amount', + '$credit.total' => '$credit.total_label$credit.total', '$credit.partial_due' => '$credit.partial_due_label$credit.partial_due', '$credit.custom1' => '$credit.custom1_label$credit.custom1', '$credit.custom2' => '$credit.custom2_label$credit.custom2', diff --git a/app/Http/Middleware/ContactKeyLogin.php b/app/Http/Middleware/ContactKeyLogin.php index 120c03d730..b718f775ae 100644 --- a/app/Http/Middleware/ContactKeyLogin.php +++ b/app/Http/Middleware/ContactKeyLogin.php @@ -12,16 +12,21 @@ namespace App\Http\Middleware; use App\Libraries\MultiDB; +use App\Models\Client; use App\Models\ClientContact; use App\Models\CompanyToken; -use Closure; use Auth; +use Closure; class ContactKeyLogin { /** * Handle an incoming request. * + * Sets a contact LOGGED IN if an appropriate client_hash is provided as a query parameter + * OR + * If the contact_key is provided in the route + * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed @@ -47,6 +52,25 @@ class ContactKeyLogin return redirect()->to('client/dashboard'); } + } + else if($request->has('client_hash') && config('ninja.db.multi_db_enabled')){ + + if (MultiDB::findAndSetDbByClientHash($request->input('client_hash'))) { + + $client = Client::where('client_hash', $request->input('client_hash'))->first(); + Auth::guard('contact')->login($client->primary_contact()->first(), true); + return redirect()->to('client/dashboard'); + + } + + } + else if($request->has('client_hash')){ + + if($client = Client::where('client_hash', $request->input('client_hash'))->first()){ + Auth::guard('contact')->login($client->primary_contact()->first(), true); + return redirect()->to('client/dashboard'); + } + } return $next($request); diff --git a/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php b/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php index 3e290847fe..f92ef7dd3d 100644 --- a/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php +++ b/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php @@ -100,7 +100,7 @@ class StoreRecurringInvoiceRequest extends Request if(isset($input['auto_bill'])) $input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']); else{ - $client = Client::find($this->decodePrimaryKey($input['client_id'])); + $client = Client::find($input['client_id']); $input['auto_bill'] = $client->getSetting('auto_bill'); } diff --git a/app/Libraries/MultiDB.php b/app/Libraries/MultiDB.php index 7aebf248f0..ad997d15c2 100644 --- a/app/Libraries/MultiDB.php +++ b/app/Libraries/MultiDB.php @@ -11,6 +11,7 @@ namespace App\Libraries; +use App\Models\Client; use App\Models\ClientContact; use App\Models\Company; use App\Models\CompanyToken; @@ -200,7 +201,6 @@ class MultiDB foreach (self::$dbs as $db) { if ($client_contact = ClientContact::on($db)->where('contact_key', $contact_key)->first()) { self::setDb($client_contact->company->db); - return true; } } @@ -208,6 +208,17 @@ class MultiDB return false; } + public static function findAndSetDbByClientHash($client_hash) :bool + { + foreach (self::$dbs as $db) { + if ($client = Client::on($db)->where('client_hash', $client_hash)->first()) { + self::setDb($client->company->db); + return true; + } + } + + return false; + } public static function findAndSetDbByDomain($subdomain) :bool { diff --git a/app/Models/ClientContact.php b/app/Models/ClientContact.php index b6403d9672..88a6103f46 100644 --- a/app/Models/ClientContact.php +++ b/app/Models/ClientContact.php @@ -198,4 +198,20 @@ class ClientContact extends Authenticatable implements HasLocalePreference return asset('images/svg/user.svg'); } + + /** + * Provides a convenience login click for contacts to bypass the + * contact authentication layer + * + * @return string URL + */ + public function getLoginLink() + { + + $domain = isset($this->company->portal_domain) ?: $this->company->domain(); + + return $domain . 'client/key_login/' . $this->contact_key; + + } + } diff --git a/app/Models/Company.php b/app/Models/Company.php index 54b9c7d7f9..176c6139a6 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -426,7 +426,7 @@ class Company extends BaseModel public function domain() { if (Ninja::isNinja()) { - return $this->subdomain.config('ninja.app_domain'); + return $this->subdomain . config('ninja.app_domain'); } return config('ninja.app_url'); diff --git a/app/Transformers/ClientContactTransformer.php b/app/Transformers/ClientContactTransformer.php index 6161c383f4..738a90d5ee 100644 --- a/app/Transformers/ClientContactTransformer.php +++ b/app/Transformers/ClientContactTransformer.php @@ -47,6 +47,7 @@ class ClientContactTransformer extends EntityTransformer 'send_email' => (bool) $contact->send_email, 'last_login' => (int) $contact->last_login, 'password' => empty($contact->password) ? '' : '**********', + 'link' => $contact->getLoginLink(), ]; } } diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index abe051a35c..933306424b 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -162,7 +162,7 @@ class HtmlEngine $data['$quote.amount'] = ['value' => Number::formatMoney($this->entity_calc->getTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.quote_total')]; $data['$credit.total'] = ['value' => Number::formatMoney($this->entity_calc->getTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.credit_total')]; $data['$credit.number'] = ['value' => $this->entity->number ?: ' ', 'label' => ctrans('texts.credit_number')]; - $data['$credit.amount'] = &$data['$credit.total']; + $data['$credit.total'] = &$data['$credit.total']; $data['$credit.po_number'] = &$data['$invoice.po_number']; $data['$credit.date'] = ['value' => $this->entity->date, 'label' => ctrans('texts.credit_date')]; $data['$balance'] = ['value' => Number::formatMoney($this->entity_calc->getBalance(), $this->client) ?: ' ', 'label' => ctrans('texts.balance')]; diff --git a/app/Utils/Traits/MakesInvoiceValues.php b/app/Utils/Traits/MakesInvoiceValues.php index b958be54a0..bc1f50d469 100644 --- a/app/Utils/Traits/MakesInvoiceValues.php +++ b/app/Utils/Traits/MakesInvoiceValues.php @@ -253,7 +253,7 @@ trait MakesInvoiceValues $data['$quote.amount'] = ['value' => Number::formatMoney($calc->getTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.quote_total')]; $data['$credit.total'] = ['value' => Number::formatMoney($calc->getTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.credit_total')]; $data['$credit.number'] = ['value' => $this->number ?: ' ', 'label' => ctrans('texts.credit_number')]; - $data['$credit.amount'] = &$data['$credit.total']; + $data['$credit.total'] = &$data['$credit.total']; $data['$credit.po_number'] = &$data['$invoice.po_number']; $data['$credit.date'] = ['value' => $this->date, 'label' => ctrans('texts.credit_date')]; $data['$balance'] = ['value' => Number::formatMoney($calc->getBalance(), $this->client) ?: ' ', 'label' => ctrans('texts.balance')]; diff --git a/app/Utils/Traits/MakesTemplateData.php b/app/Utils/Traits/MakesTemplateData.php index dc8e63ca12..edf69302ed 100644 --- a/app/Utils/Traits/MakesTemplateData.php +++ b/app/Utils/Traits/MakesTemplateData.php @@ -96,7 +96,7 @@ trait MakesTemplateData $data['$quote_total'] = ['value' => '$100.00', 'label' => ctrans('texts.quote_total')]; $data['$quote.amount'] = &$data['$quote_total']; $data['$credit_total'] = ['value' => '$100.00', 'label' => ctrans('texts.credit_total')]; - $data['$credit.amount'] = &$data['$credit_total']; + $data['$credit.total'] = &$data['$credit_total']; $data['$balance'] = ['value' => '$100.00', 'label' => ctrans('texts.balance')]; $data['$invoice.balance'] = &$data['$balance']; $data['$taxes'] = ['value' => '$10.00', 'label' => ctrans('texts.taxes')];