2018-06-05 21:02:53 +02:00
|
|
|
import { Component } from '@angular/core';
|
2018-07-13 16:51:52 +02:00
|
|
|
import {
|
|
|
|
ActivatedRoute,
|
|
|
|
Router,
|
|
|
|
} from '@angular/router';
|
2018-06-05 21:02:53 +02:00
|
|
|
|
|
|
|
import { ApiService } from 'jslib/abstractions/api.service';
|
|
|
|
import { AuthService } from 'jslib/abstractions/auth.service';
|
|
|
|
import { CryptoService } from 'jslib/abstractions/crypto.service';
|
|
|
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
2018-11-13 04:54:40 +01:00
|
|
|
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
|
2018-07-25 19:59:55 +02:00
|
|
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
2020-03-03 17:20:28 +01:00
|
|
|
import { PolicyService } from 'jslib/abstractions/policy.service';
|
2018-07-13 17:09:24 +02:00
|
|
|
import { StateService } from 'jslib/abstractions/state.service';
|
2018-06-05 21:02:53 +02:00
|
|
|
|
|
|
|
import { RegisterComponent as BaseRegisterComponent } from 'jslib/angular/components/register.component';
|
|
|
|
|
2020-03-03 17:20:28 +01:00
|
|
|
import { MasterPasswordPolicyOptions } from 'jslib/models/domain/masterPasswordPolicyOptions';
|
2020-03-02 17:51:05 +01:00
|
|
|
import { Policy } from 'jslib/models/domain/policy';
|
|
|
|
|
|
|
|
import { PolicyData } from 'jslib/models/data/policyData';
|
|
|
|
|
2018-06-05 21:02:53 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'app-register',
|
|
|
|
templateUrl: 'register.component.html',
|
|
|
|
})
|
|
|
|
export class RegisterComponent extends BaseRegisterComponent {
|
2018-07-20 16:29:40 +02:00
|
|
|
showCreateOrgMessage = false;
|
2018-07-25 19:59:55 +02:00
|
|
|
showTerms = true;
|
2020-06-04 20:12:37 +02:00
|
|
|
layout = '';
|
2020-03-03 22:37:54 +01:00
|
|
|
enforcedPolicyOptions: MasterPasswordPolicyOptions;
|
2018-07-20 16:29:40 +02:00
|
|
|
|
2020-03-02 17:51:05 +01:00
|
|
|
private policies: Policy[];
|
|
|
|
|
2018-06-05 21:02:53 +02:00
|
|
|
constructor(authService: AuthService, router: Router,
|
|
|
|
i18nService: I18nService, cryptoService: CryptoService,
|
2018-07-13 17:09:24 +02:00
|
|
|
apiService: ApiService, private route: ActivatedRoute,
|
2018-11-13 04:54:40 +01:00
|
|
|
stateService: StateService, platformUtilsService: PlatformUtilsService,
|
2020-03-03 17:20:28 +01:00
|
|
|
passwordGenerationService: PasswordGenerationService, private policyService: PolicyService) {
|
2018-11-13 04:54:40 +01:00
|
|
|
super(authService, router, i18nService, cryptoService, apiService, stateService, platformUtilsService,
|
|
|
|
passwordGenerationService);
|
2018-07-25 19:59:55 +02:00
|
|
|
this.showTerms = !platformUtilsService.isSelfHost();
|
2018-06-05 21:02:53 +02:00
|
|
|
}
|
2018-07-13 16:51:52 +02:00
|
|
|
|
2020-03-03 22:37:54 +01:00
|
|
|
getPasswordScoreAlertDisplay() {
|
|
|
|
if (this.enforcedPolicyOptions == null) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
let str: string;
|
|
|
|
switch (this.enforcedPolicyOptions.minComplexity) {
|
|
|
|
case 4:
|
|
|
|
str = this.i18nService.t('strong');
|
2020-03-04 16:21:52 +01:00
|
|
|
break;
|
2020-03-03 22:37:54 +01:00
|
|
|
case 3:
|
|
|
|
str = this.i18nService.t('good');
|
2020-03-04 16:21:52 +01:00
|
|
|
break;
|
2020-03-03 22:37:54 +01:00
|
|
|
default:
|
|
|
|
str = this.i18nService.t('weak');
|
2020-03-04 16:21:52 +01:00
|
|
|
break;
|
2020-03-03 22:37:54 +01:00
|
|
|
}
|
|
|
|
return str + ' (' + this.enforcedPolicyOptions.minComplexity + ')';
|
|
|
|
}
|
|
|
|
|
2020-03-02 17:51:05 +01:00
|
|
|
async ngOnInit() {
|
2018-12-20 16:06:40 +01:00
|
|
|
const queryParamsSub = this.route.queryParams.subscribe((qParams) => {
|
2018-07-13 16:51:52 +02:00
|
|
|
if (qParams.email != null && qParams.email.indexOf('@') > -1) {
|
|
|
|
this.email = qParams.email;
|
|
|
|
}
|
2018-07-20 16:29:40 +02:00
|
|
|
if (qParams.premium != null) {
|
|
|
|
this.stateService.save('loginRedirect', { route: '/settings/premium' });
|
|
|
|
} else if (qParams.org != null) {
|
|
|
|
this.showCreateOrgMessage = true;
|
|
|
|
this.stateService.save('loginRedirect',
|
|
|
|
{ route: '/settings/create-organization', qParams: { plan: qParams.org } });
|
|
|
|
}
|
2020-06-04 20:12:37 +02:00
|
|
|
if (qParams.layout != null) {
|
|
|
|
this.layout = qParams.layout;
|
|
|
|
}
|
2019-01-17 05:30:32 +01:00
|
|
|
if (queryParamsSub != null) {
|
|
|
|
queryParamsSub.unsubscribe();
|
|
|
|
}
|
2018-07-13 16:51:52 +02:00
|
|
|
});
|
2020-03-02 17:51:05 +01:00
|
|
|
const invite = await this.stateService.get<any>('orgInvitation');
|
|
|
|
if (invite != null) {
|
|
|
|
try {
|
|
|
|
const policies = await this.apiService.getPoliciesByToken(invite.organizationId, invite.token,
|
|
|
|
invite.email, invite.organizationUserId);
|
|
|
|
if (policies.data != null) {
|
|
|
|
const policiesData = policies.data.map((p) => new PolicyData(p));
|
|
|
|
this.policies = policiesData.map((p) => new Policy(p));
|
|
|
|
}
|
|
|
|
} catch { }
|
|
|
|
}
|
2020-03-03 17:20:28 +01:00
|
|
|
|
|
|
|
if (this.policies != null) {
|
|
|
|
this.enforcedPolicyOptions = await this.policyService.getMasterPasswordPolicyOptions(this.policies);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async submit() {
|
|
|
|
if (this.enforcedPolicyOptions != null &&
|
|
|
|
!this.policyService.evaluateMasterPassword(this.masterPasswordScore, this.masterPassword,
|
|
|
|
this.enforcedPolicyOptions)) {
|
|
|
|
this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
|
|
|
|
this.i18nService.t('masterPasswordPolicyRequirementsNotMet'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await super.submit();
|
2018-07-13 16:51:52 +02:00
|
|
|
}
|
2018-06-05 21:02:53 +02:00
|
|
|
}
|