Support custom domains

This commit is contained in:
Hillel Coren 2018-04-16 21:45:00 +03:00
parent e55e9977d4
commit fb71988112
4 changed files with 72 additions and 9 deletions

View File

@ -834,6 +834,7 @@ class AccountController extends BaseController
$account->client_view_css = $request->client_view_css; $account->client_view_css = $request->client_view_css;
$account->subdomain = $request->subdomain; $account->subdomain = $request->subdomain;
$account->iframe_url = $request->iframe_url; $account->iframe_url = $request->iframe_url;
$account->is_custom_domain = $request->is_custom_domain;
$account->save(); $account->save();
if ($fireUpdateSubdomainEvent) { if ($fireUpdateSubdomainEvent) {

View File

@ -42,7 +42,11 @@ trait Inviteable
} }
if ($iframe_url && ! $forceOnsite) { if ($iframe_url && ! $forceOnsite) {
return "{$iframe_url}?{$this->invitation_key}/{$type}"; if ($account->is_custom_domain) {
$url = $iframe_url;
} else {
return "{$iframe_url}?{$this->invitation_key}/{$type}";
}
} elseif ($this->account->subdomain && ! $forcePlain) { } elseif ($this->account->subdomain && ! $forcePlain) {
$url = Utils::replaceSubdomain($url, $account->subdomain); $url = Utils::replaceSubdomain($url, $account->subdomain);
} }

View File

@ -0,0 +1,30 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddCustomDomain extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('accounts', function ($table) {
$table->boolean('is_custom_domain')->default(false);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}

View File

@ -84,8 +84,9 @@
->label(trans('texts.customize')) ->label(trans('texts.customize'))
->radios([ ->radios([
trans('texts.subdomain') => ['value' => 'subdomain', 'name' => 'custom_link'], trans('texts.subdomain') => ['value' => 'subdomain', 'name' => 'custom_link'],
trans('texts.website') => ['value' => 'website', 'name' => 'custom_link'], 'iFrame' => ['value' => 'iframe', 'name' => 'custom_link'],
])->check($account->iframe_url ? 'website' : 'subdomain') !!} trans('texts.domain') => ['value' => 'domain', 'name' => 'custom_link'],
])->check($account->iframe_url ? ($account->is_custom_domain ? 'domain' : 'iframe') : 'subdomain') !!}
{{ Former::setOption('capitalize_translations', false) }} {{ Former::setOption('capitalize_translations', false) }}
{!! Former::text('subdomain') {!! Former::text('subdomain')
@ -97,12 +98,23 @@
@endif @endif
{!! Former::text('iframe_url') {!! Former::text('iframe_url')
->placeholder('https://www.example.com/invoice') ->placeholder('https://www.example.com')
->appendIcon('question-sign') ->appendIcon('question-sign')
->addGroupClass('iframe_url') ->addGroupClass('iframe_url')
->label(Utils::isNinja() ? ' ' : trans('texts.website')) ->label(Utils::isNinja() ? ' ' : trans('texts.website'))
->help(trans(Utils::isNinja() ? 'texts.subdomain_help' : 'texts.website_help')) !!} ->help(trans(Utils::isNinja() ? 'texts.subdomain_help' : 'texts.website_help')) !!}
@if (Utils::isNinja())
<div style="display:none">
{!! Former::text('is_custom_domain') !!}
</div>
@endif
<div id="domainHelp" style="display:none">
{!! Former::plaintext(' ')
->value('Using a custom domain requires an <a href="' . url('/settings/account_management?upgrade=true') . '" target="_blank">enterprise plan</a>') !!}
</div>
{!! Former::plaintext('preview') {!! Former::plaintext('preview')
->value($account->getSampleLink()) !!} ->value($account->getSampleLink()) !!}
@ -341,7 +353,7 @@
<div class="container" style="width: 100%; padding-bottom: 0px !important"> <div class="container" style="width: 100%; padding-bottom: 0px !important">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-body"> <div class="panel-body" id="iframeModalHelp">
<p>{{ trans('texts.iframe_url_help1') }}</p> <p>{{ trans('texts.iframe_url_help1') }}</p>
<pre>&lt;center&gt; <pre>&lt;center&gt;
&lt;iframe id="invoiceIFrame" width="100%" height="1200" style="max-width:1000px"&gt;&lt;/iframe&gt; &lt;iframe id="invoiceIFrame" width="100%" height="1200" style="max-width:1000px"&gt;&lt;/iframe&gt;
@ -355,7 +367,13 @@ iframe.src = '{{ rtrim(SITE_URL ,'/') }}/' + parts[1] + '/' + parts[0].substring
&lt;/script&gt;</pre> &lt;/script&gt;</pre>
<p>{{ trans('texts.iframe_url_help2') }}</p> <p>{{ trans('texts.iframe_url_help2') }}</p>
<p><b>{{ trans('texts.iframe_url_help3') }}</b></p> <p><b>{{ trans('texts.iframe_url_help3') }}</b></p>
</div> </div>
<div class="panel-body" id="domainModalHelp" style="display:none">
<p>Create a DNS A Record entry for your custom domain and point to the following IP address <code>96.126.107.105</code>.</p>
<p>Once this is setup please send an email to {{ env('CONTACT_EMAIL') }} and we'll complete the process.</p>
</div>
</div> </div>
</div> </div>
@ -471,13 +489,23 @@ iframe.src = '{{ rtrim(SITE_URL ,'/') }}/' + parts[1] + '/' + parts[0].substring
} }
function onCustomLinkChange() { function onCustomLinkChange() {
$('.iframe_url, .subdomain').hide();
$('.subdomain').hide();
$('#domainHelp, #iframeModalHelp, #domainModalHelp').hide();
$('#is_custom_domain').val(0);
var val = $('input[name=custom_link]:checked').val() var val = $('input[name=custom_link]:checked').val()
if (val == 'subdomain') { if (val == 'subdomain') {
$('.subdomain').show(); $('.subdomain').show();
$('.iframe_url').hide(); } else if (val == 'iframe') {
$('.iframe_url, #iframeModalHelp').show();
} else { } else {
$('.subdomain').hide(); @if (auth()->user()->isEnterprise())
$('.iframe_url').show(); $('.iframe_url, #domainModalHelp').show();
$('#is_custom_domain').val(1);
@else
$('#domainHelp').show();
@endif
} }
} }