Skip to content

Commit 15c2d06

Browse files
prefill HUB_INITIAL_ID & HUB_INITIAL_LICENSE
1 parent 2759fc9 commit 15c2d06

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

assets/js/hubsetup.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class HubSetup {
3434
adminUser: 'admin',
3535
adminPw: 'admin',
3636
systemClientSecret: HubSetup.uuid(),
37+
hubId: null,
38+
licenseKey: null,
3739
}
3840
}
3941
}
@@ -43,7 +45,9 @@ class HubSetup {
4345
* @param {*} cfg The customized config
4446
* @returns output
4547
*/
46-
static generateOutput(cfg) {
48+
static generateOutput(cfg, trialData) {
49+
cfg.hub.hubId = trialData.hubId;
50+
cfg.hub.licenseKey = trialData.licenseKey;
4751
return {
4852
k8s: HubSetup.writeHeader(cfg) + HubSetup.writeK8sConfig(cfg),
4953
compose: HubSetup.writeHeader(cfg) + HubSetup.writeComposeConfig(cfg),
@@ -482,6 +486,8 @@ EOF`;
482486
restart: 'unless-stopped',
483487
environment: {
484488
HUB_PUBLIC_ROOT_PATH: this.getPathnameWithTrailingSlash(this.cfg.hub.publicUrl),
489+
HUB_INITIAL_ID: this.cfg.hub.hubId,
490+
HUB_INITIAL_LICENSE: this.cfg.hub.licenseKey,
485491
HUB_KEYCLOAK_PUBLIC_URL: this.cfg.keycloak.publicUrl,
486492
HUB_KEYCLOAK_LOCAL_URL: !this.cfg.keycloak.useExternal ? `http://keycloak:8080${this.getPathname(this.cfg.keycloak.publicUrl)}` : this.cfg.keycloak.publicUrl,
487493
HUB_KEYCLOAK_REALM: this.cfg.keycloak.realmId,
@@ -676,6 +682,8 @@ class KubernetesConfigBuilder extends ConfigBuilder {
676682
},
677683
env: [
678684
{name: 'HUB_PUBLIC_ROOT_PATH', value: this.getPathnameWithTrailingSlash(this.cfg.hub.publicUrl)},
685+
{name: 'HUB_INITIAL_ID', value: this.cfg.hub.hubId},
686+
{name: 'HUB_INITIAL_LICENSE', value: this.cfg.hub.licenseKey},
679687
{name: 'HUB_KEYCLOAK_PUBLIC_URL', value: this.cfg.keycloak.publicUrl},
680688
{name: 'HUB_KEYCLOAK_LOCAL_URL', value: !this.cfg.keycloak.useExternal ? `http://keycloak-svc:8080${this.getPathname(this.cfg.keycloak.publicUrl)}` : this.cfg.keycloak.publicUrl},
681689
{name: 'HUB_KEYCLOAK_REALM', value: this.cfg.keycloak.realmId},

assets/js/hubsubscription.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,46 @@
11
"use strict";
22

3+
const TRIAL_APPLY_URL = API_BASE_URL + '/licenses/hub/trial';
4+
35
const BILLING_PORTAL_SESSION_URL = LEGACY_STORE_URL + '/hub/billing-portal-session';
46
const CUSTOM_BILLING_URL = LEGACY_STORE_URL + '/hub/custom-billing';
57
const GENERATE_PAY_LINK_URL = LEGACY_STORE_URL + '/hub/generate-pay-link';
68
const MANAGE_SUBSCRIPTION_URL = LEGACY_STORE_URL + '/hub/manage-subscription';
79
const UPDATE_PAYMENT_METHOD_URL = LEGACY_STORE_URL + '/hub/update-payment-method';
810

11+
class HubTrial {
12+
13+
constructor(trialData) {
14+
this._trialData = trialData;
15+
}
16+
17+
getTrialLicense() {
18+
if (!this._trialData.captcha) {
19+
this._trialData.errorMessage = 'Please complete the CAPTCHA challenge.';
20+
return;
21+
}
22+
23+
this._trialData.inProgress = true;
24+
this._trialData.errorMessage = '';
25+
return $.ajax({
26+
url: TRIAL_APPLY_URL,
27+
type: 'POST',
28+
data: {
29+
captcha: this._trialData.captcha
30+
}
31+
}).done(data => {
32+
this._trialData.hubId = data.hubId;
33+
this._trialData.licenseKey = data.licenseKey;
34+
this._trialData.inProgress = false;
35+
}).fail((xhr, textStatus, error) => {
36+
console.error('Trial registration failed:', error);
37+
this._trialData.errorMessage = textStatus;
38+
this._trialData.inProgress = false;
39+
});
40+
}
41+
42+
}
43+
944
class HubSubscription {
1045

1146
constructor(form, subscriptionData, searchParams) {

layouts/hub-self-hosted/single.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{ define "main" }}
2-
<div class="container space-y-6 py-12" x-data="{cfg: HubSetup.defaultConfig(), deploymentType: '', output: ''}" x-init="output = HubSetup.generateOutput(cfg); $watch('cfg', _ => output = HubSetup.generateOutput(cfg))">
2+
<div class="container space-y-6 py-12" x-data="{cfg: HubSetup.defaultConfig(), deploymentType: '', output: '', trialData: {hubId: null, licenseKey: null, captcha: null, captchaState: null, inProgress: false, errorMessage: null}, hubTrial: null}" x-init="output = HubSetup.generateOutput(cfg, trialData); hubTrial = new HubTrial(trialData); $watch('trialData.captcha', _ => hubTrial.getTrialLicense()); $watch('trialData', () => output = HubSetup.generateOutput(cfg, trialData)); $watch('cfg', () => output = HubSetup.generateOutput(cfg, trialData))">
33
<header class="mb-6">
44
<h1 class="font-h1 mb-8">{{ .Title }}</h1>
55
<p class="lead mb-8">{{ i18n "hub_setup_description" . }}</p>
@@ -284,6 +284,8 @@ <h2 class="text-lg font-medium leading-6 text-gray-900">
284284
<p class="mt-1 text-sm text-gray-500">
285285
{{ i18n "hub_setup_output_header_description" . }}
286286
</p>
287+
{{ $challengeUrl := printf "%s/licenses/hub/challenge" .Site.Params.apiBaseUrl }}
288+
{{ partial "captcha.html" (dict "challengeUrl" $challengeUrl "captchaPayload" "trialData.captcha" "captchaState" "trialData.captchaState" "auto" "onload") }}
287289
</header>
288290
<div class="mt-5 md:mt-0 md:col-span-2 grid grid-cols-6 gap-6">
289291
<div class="col-span-6" x-show="deploymentType == 'kubernetes'">
@@ -319,10 +321,22 @@ <h2 class="font-h2 mb-4">{{ i18n "hub_setup_contact_us_title" . }}</h2>
319321
{{ $jsYaml := resources.Get "js/js-yaml/js-yaml.min.js" | fingerprint }}
320322
<script type="text/javascript" src="{{ $jsYaml.RelPermalink }}" integrity="{{ $jsYaml.Data.Integrity }}"></script>
321323
{{ if hugo.IsDevelopment }}
324+
{{ $hubSubscriptionJs := resources.Get "js/hubsubscription.js" }}
325+
<script type="text/javascript" src="{{ $hubSubscriptionJs.RelPermalink }}" defer></script>
322326
{{ $setupJs := resources.Get "js/hubsetup.js" }}
323327
<script type="text/javascript" src="{{ $setupJs.RelPermalink }}" defer></script>
328+
{{ $altchaJs := resources.Get "js/altcha/altcha.js" }}
329+
<script type="module" src="{{ $altchaJs.RelPermalink }}" defer></script>
330+
{{ $altchaWorkerJs := resources.Get "js/altcha/worker.js" }}
331+
<script type="module" src="{{ $altchaWorkerJs.RelPermalink }}" defer></script>
324332
{{ else }}
333+
{{ $hubSubscriptionJs := resources.Get "js/hubsubscription.js" | minify | fingerprint }}
334+
<script type="text/javascript" src="{{ $hubSubscriptionJs.RelPermalink }}" integrity="{{ $hubSubscriptionJs.Data.Integrity }}" defer></script>
325335
{{ $setupJs := resources.Get "js/hubsetup.js" | minify | fingerprint }}
326336
<script type="text/javascript" src="{{ $setupJs.RelPermalink }}" integrity="{{ $setupJs.Data.Integrity }}" defer></script>
337+
{{ $altchaJs := resources.Get "js/altcha/altcha.js" }}
338+
<script type="module" src="{{ $altchaJs.RelPermalink }}" integrity="{{ $altchaJs.Data.Integrity }}" defer></script>
339+
{{ $altchaWorkerJs := resources.Get "js/altcha/worker.js" }}
340+
<script type="module" src="{{ $altchaWorkerJs.RelPermalink }}" integrity="{{ $altchaWorkerJs.Data.Integrity }}" defer></script>
327341
{{ end }}
328342
{{ end }}

layouts/partials/captcha.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<altcha-widget
22
challengeurl="{{ .challengeUrl }}"
3+
{{ if .auto }}auto="{{ .auto }}"{{ end }}
34
hidelogo
45
hidefooter
56
floating="auto"

0 commit comments

Comments
 (0)