From 738eaa6ca7b9020beb65548b989499225d66d6dc Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 3 Jul 2018 09:55:59 -0400 Subject: [PATCH] create by license moved from update license component --- .../create-organization.component.html | 14 ++++- .../settings/create-organization.component.ts | 60 ++++++++++++------- src/app/settings/premium.component.html | 12 +++- src/app/settings/premium.component.ts | 33 +++++++--- .../settings/update-license.component.html | 2 +- src/app/settings/update-license.component.ts | 31 ++++------ src/app/settings/user-billing.component.html | 2 +- src/locales/en/messages.json | 3 + 8 files changed, 103 insertions(+), 54 deletions(-) diff --git a/src/app/settings/create-organization.component.html b/src/app/settings/create-organization.component.html index b7b5210063..de76b539e4 100644 --- a/src/app/settings/create-organization.component.html +++ b/src/app/settings/create-organization.component.html @@ -3,8 +3,18 @@

{{'newOrganizationDesc' | i18n}}

-

{{'uploadLicenseFilePremium' | i18n}}

- +

{{'uploadLicenseFileOrg' | i18n}}

+
+
+ + + {{'licenseFileDesc' | i18n : 'bitwarden_organization_license.json'}} +
+ +

{{'generalInformation' | i18n}}

diff --git a/src/app/settings/create-organization.component.ts b/src/app/settings/create-organization.component.ts index 132e2d34e9..c8248da639 100644 --- a/src/app/settings/create-organization.component.ts +++ b/src/app/settings/create-organization.component.ts @@ -87,6 +87,17 @@ export class CreateOrganizationComponent { } async submit() { + let files: FileList = null; + if (this.selfHosted) { + const fileEl = document.getElementById('file') as HTMLInputElement; + files = fileEl.files; + if (files == null || files.length === 0) { + this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), + this.i18nService.t('selectFile')); + return; + } + } + let key: string = null; let collectionCt: string = null; @@ -96,34 +107,41 @@ export class CreateOrganizationComponent { return this.cryptoService.encrypt('Default Collection', shareKey[1]); }).then((collection) => { collectionCt = collection.encryptedString; - if (this.plan === 'free') { + if (this.selfHosted || this.plan === 'free') { return null; } else { return this.paymentComponent.createPaymentToken(); } }).then((token: string) => { - const request = new OrganizationCreateRequest(); - request.key = key; - request.collectionName = collectionCt; - request.name = this.name; - request.billingEmail = this.billingEmail; - - if (this.plan === 'free') { - request.planType = PlanType.Free; + if (this.selfHosted) { + const fd = new FormData(); + fd.append('license', files[0]); + fd.append('key', key); + fd.append('collectionName', collectionCt); + return this.apiService.postOrganizationLicense(fd); } else { - request.paymentToken = token; - request.businessName = this.ownedBusiness ? this.businessName : null; - request.additionalSeats = this.additionalSeats; - request.additionalStorageGb = this.additionalStorage; - request.country = this.paymentComponent.getCountry(); - if (this.interval === 'month') { - request.planType = this.plans[this.plan].monthPlanType; - } else { - request.planType = this.plans[this.plan].annualPlanType; - } - } + const request = new OrganizationCreateRequest(); + request.key = key; + request.collectionName = collectionCt; + request.name = this.name; + request.billingEmail = this.billingEmail; - return this.apiService.postOrganization(request); + if (this.plan === 'free') { + request.planType = PlanType.Free; + } else { + request.paymentToken = token; + request.businessName = this.ownedBusiness ? this.businessName : null; + request.additionalSeats = this.additionalSeats; + request.additionalStorageGb = this.additionalStorage; + request.country = this.paymentComponent.getCountry(); + if (this.interval === 'month') { + request.planType = this.plans[this.plan].monthPlanType; + } else { + request.planType = this.plans[this.plan].annualPlanType; + } + } + return this.apiService.postOrganization(request); + } }).then((response) => { return this.finalize(response.id); }); diff --git a/src/app/settings/premium.component.html b/src/app/settings/premium.component.html index 2c1ffc641e..c6c26587d1 100644 --- a/src/app/settings/premium.component.html +++ b/src/app/settings/premium.component.html @@ -33,7 +33,17 @@

{{'uploadLicenseFilePremium' | i18n}}

- + +
+ + + {{'licenseFileDesc' | i18n : 'bitwarden_premium_license.json'}} +
+ +

{{'addons' | i18n}}

diff --git a/src/app/settings/premium.component.ts b/src/app/settings/premium.component.ts index 7a8cd0834a..89f15f374e 100644 --- a/src/app/settings/premium.component.ts +++ b/src/app/settings/premium.component.ts @@ -46,15 +46,34 @@ export class PremiumComponent implements OnInit { } async submit() { + let files: FileList = null; + if (this.selfHosted) { + const fileEl = document.getElementById('file') as HTMLInputElement; + files = fileEl.files; + if (files == null || files.length === 0) { + this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), + this.i18nService.t('selectFile')); + return; + } + } + try { - this.formPromise = this.paymentComponent.createPaymentToken().then((token) => { + if (this.selfHosted) { const fd = new FormData(); - fd.append('paymentToken', token); - fd.append('additionalStorageGb', (this.additionalStorage || 0).toString()); - return this.apiService.postPremium(fd); - }).then(() => { - return this.finalizePremium(); - }); + fd.append('license', files[0]); + this.formPromise = this.apiService.postAccountLicense(fd).then(() => { + return this.finalizePremium(); + }); + } else { + this.formPromise = this.paymentComponent.createPaymentToken().then((token) => { + const fd = new FormData(); + fd.append('paymentToken', token); + fd.append('additionalStorageGb', (this.additionalStorage || 0).toString()); + return this.apiService.postPremium(fd); + }).then(() => { + return this.finalizePremium(); + }); + } await this.formPromise; } catch { } } diff --git a/src/app/settings/update-license.component.html b/src/app/settings/update-license.component.html index 9cf14d908f..9b67578dda 100644 --- a/src/app/settings/update-license.component.html +++ b/src/app/settings/update-license.component.html @@ -8,7 +8,7 @@ {{'submit' | i18n}} -
diff --git a/src/app/settings/update-license.component.ts b/src/app/settings/update-license.component.ts index 7ce70a6907..338c446b92 100644 --- a/src/app/settings/update-license.component.ts +++ b/src/app/settings/update-license.component.ts @@ -10,24 +10,20 @@ import { Angulartics2 } from 'angulartics2'; import { ApiService } from 'jslib/abstractions/api.service'; import { I18nService } from 'jslib/abstractions/i18n.service'; -import { TokenService } from 'jslib/abstractions/token.service'; @Component({ selector: 'app-update-license', templateUrl: 'update-license.component.html', }) export class UpdateLicenseComponent { - @Input() create = true; @Input() user = true; @Output() onUpdated = new EventEmitter(); @Output() onCanceled = new EventEmitter(); - storageAdjustment = 0; formPromise: Promise; constructor(private apiService: ApiService, private i18nService: I18nService, - private analytics: Angulartics2, private toasterService: ToasterService, - private tokenService: TokenService) { } + private analytics: Angulartics2, private toasterService: ToasterService) { } async submit() { const fileEl = document.getElementById('file') as HTMLInputElement; @@ -39,25 +35,18 @@ export class UpdateLicenseComponent { } try { + const fd = new FormData(); + fd.append('license', files[0]); + if (this.user) { - const fd = new FormData(); - fd.append('license', files[0]); - if (this.create) { - if (!this.tokenService.getEmailVerified()) { - this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), - this.i18nService.t('accountEmailMustBeVerified')); - return; - } - this.formPromise = this.apiService.postPremium(fd); - } else { - this.formPromise = this.apiService.postAccountLicense(fd); - } + this.formPromise = this.apiService.postAccountLicense(fd); + } else { + // TODO } + await this.formPromise; - if (!this.create) { - this.analytics.eventTrack.next({ action: 'Updated License' }); - this.toasterService.popAsync('success', null, this.i18nService.t('updatedLicense')); - } + this.analytics.eventTrack.next({ action: 'Updated License' }); + this.toasterService.popAsync('success', null, this.i18nService.t('updatedLicense')); this.onUpdated.emit(); } catch { } } diff --git a/src/app/settings/user-billing.component.html b/src/app/settings/user-billing.component.html index ad104f82a2..7f3669455a 100644 --- a/src/app/settings/user-billing.component.html +++ b/src/app/settings/user-billing.component.html @@ -64,7 +64,7 @@

{{'updateLicense' | i18n}}

- +
diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index f70af4e25b..39182ea1fa 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -1452,6 +1452,9 @@ "uploadLicenseFilePremium": { "message": "To upgrade your account to a premium membership you need to upload a valid license file." }, + "uploadLicenseFileOrg": { + "message": "To create an on-premise hosted organization you need to upload a valid license file." + }, "accountEmailMustBeVerified": { "message": "Your account's email address must be verified." },