diff --git a/app/Libraries/Utils.php b/app/Libraries/Utils.php index 58e1eb1333c6..b0468d9f836d 100644 --- a/app/Libraries/Utils.php +++ b/app/Libraries/Utils.php @@ -89,6 +89,11 @@ class Utils return env('NINJA_DEV') == 'true'; } + public static function isTimeTracker() + { + return array_get($_SERVER, 'HTTP_USER_AGENT') == TIME_TRACKER_USER_AGENT; + } + public static function requireHTTPS() { if (Request::root() === 'http://ninja.dev' || Request::root() === 'http://ninja.dev:8000') { diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index aae68f215384..adfc27a1a03f 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2519,6 +2519,9 @@ $LANG = array( 'add_product' => 'Add Product', 'email_will_be_sent_on' => 'Note: the email will be sent on :date.', 'invoice_product' => 'Invoice Product', + 'self_host_login' => 'Self-Host Login', + 'set_self_hoat_url' => 'Self-Host URL', + 'local_storage_required' => 'Error: local storage is not available.', ); diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 15c87890b8ef..0f229e85daba 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -83,7 +83,11 @@ {!! link_to('/recover_password', trans('texts.recover_password')) !!}
- {!! link_to(NINJA_WEB_URL.'/knowledgebase/', trans('texts.knowledge_base'), ['target' => '_blank']) !!} + @if (Utils::isTimeTracker()) + {!! link_to('#', trans('texts.self_host_login'), ['onclick' => 'setSelfHostUrl()']) !!} + @else + {!! link_to(NINJA_WEB_URL.'/knowledgebase/', trans('texts.knowledge_base'), ['target' => '_blank']) !!} + @endif
@endif @@ -111,8 +115,13 @@ $('#email').focus(); } - @if (array_get($_SERVER, 'HTTP_USER_AGENT') == TIME_TRACKER_USER_AGENT) + @if (Utils::isTimeTracker()) if (isStorageSupported()) { + var selfHostUrl = localStorage.getItem('last:time_tracker:url'); + if (selfHostUrl) { + location.href = selfHostUrl; + return; + } $('#email').change(function() { localStorage.setItem('last:time_tracker:email', $('#email').val()); }) @@ -124,6 +133,29 @@ } @endif }) + + @if (Utils::isTimeTracker()) + function setSelfHostUrl() { + if (! isStorageSupported()) { + swal("{{ trans('texts.local_storage_required') }}"); + return; + } + swal({ + title: "{{ trans('texts.set_self_hoat_url') }}", + input: 'text', + showCancelButton: true, + confirmButtonText: 'Save', + }).then(function (value) { + if (!value) { + return; + } + value = value.replace(/\/+$/, '') + '/time_tracker'; + localStorage.setItem('last:time_tracker:url', value); + location.reload(); + }) + } + @endif + @endsection