From fb749092b2b22c908a949b1c7368f288f5d1b8d1 Mon Sep 17 00:00:00 2001 From: Joshua Dwire Date: Wed, 15 Feb 2017 22:26:55 -0500 Subject: [PATCH] Reorganize Client Portal Fonts/CSS to allow styling client auth screens --- .../Controllers/ClientAuth/AuthController.php | 11 ----- .../ClientAuth/PasswordController.php | 14 +------ .../Controllers/ClientPortalController.php | 10 ----- app/Libraries/Utils.php | 40 +++++++++++++++++++ .../PaymentDrivers/BasePaymentDriver.php | 1 - .../views/clientauth/sessionexpired.blade.php | 2 +- resources/views/emails/master.blade.php | 4 +- resources/views/login.blade.php | 12 +++--- resources/views/public/header.blade.php | 2 +- 9 files changed, 53 insertions(+), 43 deletions(-) diff --git a/app/Http/Controllers/ClientAuth/AuthController.php b/app/Http/Controllers/ClientAuth/AuthController.php index 664ba906fe5c..f48934b06826 100644 --- a/app/Http/Controllers/ClientAuth/AuthController.php +++ b/app/Http/Controllers/ClientAuth/AuthController.php @@ -32,17 +32,6 @@ class AuthController extends Controller 'clientauth' => true, ]; - $contactKey = session('contact_key'); - if ($contactKey) { - $contact = Contact::where('contact_key', '=', $contactKey)->first(); - if ($contact && ! $contact->is_deleted) { - $account = $contact->account; - - $data['account'] = $account; - $data['clientFontUrl'] = $account->getFontsUrl(); - } - } - return view('clientauth.login')->with($data); } diff --git a/app/Http/Controllers/ClientAuth/PasswordController.php b/app/Http/Controllers/ClientAuth/PasswordController.php index 38290f318883..707208276f2f 100644 --- a/app/Http/Controllers/ClientAuth/PasswordController.php +++ b/app/Http/Controllers/ClientAuth/PasswordController.php @@ -52,14 +52,7 @@ class PasswordController extends Controller 'clientauth' => true, ]; $contactKey = session('contact_key'); - if ($contactKey) { - $contact = Contact::where('contact_key', '=', $contactKey)->first(); - if ($contact && ! $contact->is_deleted) { - $account = $contact->account; - $data['account'] = $account; - $data['clientFontUrl'] = $account->getFontsUrl(); - } - } else { + if (!$contactKey) { return \Redirect::to('/client/sessionexpired'); } @@ -136,10 +129,7 @@ class PasswordController extends Controller } } - if (! empty($account)) { - $data['account'] = $account; - $data['clientFontUrl'] = $account->getFontsUrl(); - } else { + if ( empty($account)) { return \Redirect::to('/client/sessionexpired'); } } diff --git a/app/Http/Controllers/ClientPortalController.php b/app/Http/Controllers/ClientPortalController.php index 3040c6b06cd8..d86f77cd128b 100644 --- a/app/Http/Controllers/ClientPortalController.php +++ b/app/Http/Controllers/ClientPortalController.php @@ -131,7 +131,6 @@ class ClientPortalController extends BaseController 'account' => $account, 'showApprove' => $showApprove, 'showBreadcrumbs' => false, - 'clientFontUrl' => $account->getFontsUrl(), 'invoice' => $invoice->hidePrivateFields(), 'invitation' => $invitation, 'invoiceLabels' => $account->getInvoiceLabels(), @@ -252,7 +251,6 @@ class ClientPortalController extends BaseController 'contact' => $contact, 'account' => $account, 'client' => $client, - 'clientFontUrl' => $account->getFontsUrl(), 'gateway' => $account->getTokenGateway(), 'paymentMethods' => $customer ? $customer->payment_methods : false, 'transactionToken' => $paymentDriver ? $paymentDriver->createTransactionToken() : false, @@ -318,7 +316,6 @@ class ClientPortalController extends BaseController 'color' => $color, 'account' => $account, 'client' => $contact->client, - 'clientFontUrl' => $account->getFontsUrl(), 'title' => trans('texts.recurring_invoices'), 'entityType' => ENTITY_RECURRING_INVOICE, 'columns' => Utils::trans(['frequency', 'start_date', 'end_date', 'invoice_total', 'auto_bill']), @@ -346,7 +343,6 @@ class ClientPortalController extends BaseController 'color' => $color, 'account' => $account, 'client' => $contact->client, - 'clientFontUrl' => $account->getFontsUrl(), 'title' => trans('texts.invoices'), 'entityType' => ENTITY_INVOICE, 'columns' => Utils::trans(['invoice_number', 'invoice_date', 'invoice_total', 'balance_due', 'due_date']), @@ -391,7 +387,6 @@ class ClientPortalController extends BaseController $data = [ 'color' => $color, 'account' => $account, - 'clientFontUrl' => $account->getFontsUrl(), 'entityType' => ENTITY_PAYMENT, 'title' => trans('texts.payments'), 'columns' => Utils::trans(['invoice', 'transaction_reference', 'method', 'payment_amount', 'payment_date', 'status']), @@ -476,7 +471,6 @@ class ClientPortalController extends BaseController $data = [ 'color' => $color, 'account' => $account, - 'clientFontUrl' => $account->getFontsUrl(), 'title' => trans('texts.quotes'), 'entityType' => ENTITY_QUOTE, 'columns' => Utils::trans(['quote_number', 'quote_date', 'quote_total', 'due_date']), @@ -512,7 +506,6 @@ class ClientPortalController extends BaseController $data = [ 'color' => $color, 'account' => $account, - 'clientFontUrl' => $account->getFontsUrl(), 'title' => trans('texts.credits'), 'entityType' => ENTITY_CREDIT, 'columns' => Utils::trans(['credit_date', 'credit_amount', 'credit_balance']), @@ -548,7 +541,6 @@ class ClientPortalController extends BaseController $data = [ 'color' => $color, 'account' => $account, - 'clientFontUrl' => $account->getFontsUrl(), 'title' => trans('texts.documents'), 'entityType' => ENTITY_DOCUMENT, 'columns' => Utils::trans(['invoice_number', 'name', 'document_date', 'document_size']), @@ -757,8 +749,6 @@ class ClientPortalController extends BaseController 'contact' => $contact, 'color' => $account->primary_color ? $account->primary_color : '#0b4d78', 'client' => $client, - 'clientViewCSS' => $account->clientViewCSS(), - 'clientFontUrl' => $account->getFontsUrl(), 'paymentMethods' => $customer ? $customer->payment_methods : false, 'gateway' => $account->getTokenGateway(), 'title' => trans('texts.payment_methods'), diff --git a/app/Libraries/Utils.php b/app/Libraries/Utils.php index ed67356c6ca9..676a7cfa8881 100644 --- a/app/Libraries/Utils.php +++ b/app/Libraries/Utils.php @@ -102,6 +102,46 @@ class Utils return self::getResllerType() ? true : false; } + public static function clientViewCSS() + { + $account = false; + + if (Auth::check()) { + $account = Auth::user()->account; + } elseif ($contactKey = session('contact_key')) { + if ($contact = \App\Models\Contact::whereContactKey($contactKey)->first()) { + $account = $contact->account; + } + } + + if ( !$account && ! self::isNinja()) { + // For self-hosted accounts, pick the first account + $account = \App\Models\Account::first(); + } + + return $account ? $account->clientViewCSS() : ''; + } + + public static function getAccountFontsUrl($protocol = '') + { + $account = false; + + if (Auth::check()) { + $account = Auth::user()->account; + } elseif ($contactKey = session('contact_key')) { + if ($contact = \App\Models\Contact::whereContactKey($contactKey)->first()) { + $account = $contact->account; + } + } + + if ( !$account && ! self::isNinja()) { + // For self-hosted accounts, pick the first account + $account = \App\Models\Account::first(); + } + + return $account ? $account->getFontsUrl($protocol) : false; + } + public static function isWhiteLabel() { $account = false; diff --git a/app/Ninja/PaymentDrivers/BasePaymentDriver.php b/app/Ninja/PaymentDrivers/BasePaymentDriver.php index fd3cb6ea055d..15846f75dc9d 100644 --- a/app/Ninja/PaymentDrivers/BasePaymentDriver.php +++ b/app/Ninja/PaymentDrivers/BasePaymentDriver.php @@ -166,7 +166,6 @@ class BasePaymentDriver 'currencyCode' => $this->client()->getCurrencyCode(), 'account' => $this->account(), 'sourceId' => $sourceId, - 'clientFontUrl' => $this->account()->getFontsUrl(), 'tokenize' => $this->tokenize(), 'transactionToken' => $this->createTransactionToken(), ]; diff --git a/resources/views/clientauth/sessionexpired.blade.php b/resources/views/clientauth/sessionexpired.blade.php index bd5a62854caa..e592ba71001d 100644 --- a/resources/views/clientauth/sessionexpired.blade.php +++ b/resources/views/clientauth/sessionexpired.blade.php @@ -3,6 +3,6 @@

-

{{ trans('texts.client_session_expired_message') }}

+
{{ trans('texts.client_session_expired_message') }}
@endsection \ No newline at end of file diff --git a/resources/views/emails/master.blade.php b/resources/views/emails/master.blade.php index ee15ef001c3a..c96bae0d78d4 100644 --- a/resources/views/emails/master.blade.php +++ b/resources/views/emails/master.blade.php @@ -3,7 +3,9 @@ - + @if($fontsUrl = Utils::getAccountFontsUrl()) + + @endif + @if (!empty($clientauth) && $fontsUrl = Utils::getAccountFontsUrl()) + @endif - @if (!empty($clientauth) && !empty($account)) - - @endif - + + @if (!empty($clientauth)) + + @endif @endsection @section('body') diff --git a/resources/views/public/header.blade.php b/resources/views/public/header.blade.php index 1f0290c69561..c274f91cf995 100644 --- a/resources/views/public/header.blade.php +++ b/resources/views/public/header.blade.php @@ -5,7 +5,7 @@ @endif - + @stop @section('body')