2021-12-17 15:57:11 +01:00
|
|
|
import { Component } from "@angular/core";
|
|
|
|
import { ActivatedRoute, Router } from "@angular/router";
|
|
|
|
import { first } from "rxjs/operators";
|
2021-10-15 00:59:43 +02:00
|
|
|
|
2022-02-24 12:10:07 +01:00
|
|
|
import { RegisterComponent as BaseRegisterComponent } from "jslib-angular/components/register.component";
|
2021-12-17 15:57:11 +01:00
|
|
|
import { ApiService } from "jslib-common/abstractions/api.service";
|
|
|
|
import { AuthService } from "jslib-common/abstractions/auth.service";
|
|
|
|
import { CryptoService } from "jslib-common/abstractions/crypto.service";
|
|
|
|
import { EnvironmentService } from "jslib-common/abstractions/environment.service";
|
|
|
|
import { I18nService } from "jslib-common/abstractions/i18n.service";
|
|
|
|
import { LogService } from "jslib-common/abstractions/log.service";
|
|
|
|
import { PasswordGenerationService } from "jslib-common/abstractions/passwordGeneration.service";
|
|
|
|
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
|
|
|
|
import { PolicyService } from "jslib-common/abstractions/policy.service";
|
|
|
|
import { StateService } from "jslib-common/abstractions/state.service";
|
2022-02-24 12:10:07 +01:00
|
|
|
import { PolicyData } from "jslib-common/models/data/policyData";
|
2021-12-17 15:57:11 +01:00
|
|
|
import { MasterPasswordPolicyOptions } from "jslib-common/models/domain/masterPasswordPolicyOptions";
|
|
|
|
import { Policy } from "jslib-common/models/domain/policy";
|
|
|
|
import { ReferenceEventRequest } from "jslib-common/models/request/referenceEventRequest";
|
2020-03-02 17:51:05 +01:00
|
|
|
|
2022-04-25 15:41:44 +02:00
|
|
|
import { RouterService } from "../services/router.service";
|
|
|
|
|
2018-06-05 21:02:53 +02:00
|
|
|
@Component({
|
2021-12-17 15:57:11 +01:00
|
|
|
selector: "app-register",
|
|
|
|
templateUrl: "register.component.html",
|
2018-06-05 21:02:53 +02:00
|
|
|
})
|
|
|
|
export class RegisterComponent extends BaseRegisterComponent {
|
2021-12-17 15:57:11 +01:00
|
|
|
showCreateOrgMessage = false;
|
|
|
|
layout = "";
|
|
|
|
enforcedPolicyOptions: MasterPasswordPolicyOptions;
|
2018-07-20 16:29:40 +02:00
|
|
|
|
2021-12-17 15:57:11 +01:00
|
|
|
private policies: Policy[];
|
2020-03-02 17:51:05 +01:00
|
|
|
|
2021-12-17 15:57:11 +01:00
|
|
|
constructor(
|
|
|
|
authService: AuthService,
|
|
|
|
router: Router,
|
|
|
|
i18nService: I18nService,
|
|
|
|
cryptoService: CryptoService,
|
|
|
|
apiService: ApiService,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
stateService: StateService,
|
|
|
|
platformUtilsService: PlatformUtilsService,
|
|
|
|
passwordGenerationService: PasswordGenerationService,
|
|
|
|
private policyService: PolicyService,
|
|
|
|
environmentService: EnvironmentService,
|
2022-04-25 15:41:44 +02:00
|
|
|
logService: LogService,
|
|
|
|
private routerService: RouterService
|
2021-12-17 15:57:11 +01:00
|
|
|
) {
|
|
|
|
super(
|
|
|
|
authService,
|
|
|
|
router,
|
|
|
|
i18nService,
|
|
|
|
cryptoService,
|
|
|
|
apiService,
|
|
|
|
stateService,
|
|
|
|
platformUtilsService,
|
|
|
|
passwordGenerationService,
|
|
|
|
environmentService,
|
|
|
|
logService
|
|
|
|
);
|
|
|
|
}
|
2018-07-13 16:51:52 +02:00
|
|
|
|
2021-12-17 15:57:11 +01:00
|
|
|
async ngOnInit() {
|
|
|
|
this.route.queryParams.pipe(first()).subscribe((qParams) => {
|
|
|
|
this.referenceData = new ReferenceEventRequest();
|
|
|
|
if (qParams.email != null && qParams.email.indexOf("@") > -1) {
|
|
|
|
this.email = qParams.email;
|
|
|
|
}
|
|
|
|
if (qParams.premium != null) {
|
2022-04-25 15:41:44 +02:00
|
|
|
this.routerService.setPreviousUrl("/settings/premium");
|
2021-12-17 15:57:11 +01:00
|
|
|
} else if (qParams.org != null) {
|
|
|
|
this.showCreateOrgMessage = true;
|
|
|
|
this.referenceData.flow = qParams.org;
|
2022-04-25 15:41:44 +02:00
|
|
|
const route = this.router.createUrlTree(["settings/create-organization"], {
|
|
|
|
queryParams: { plan: qParams.org },
|
2018-07-13 16:51:52 +02:00
|
|
|
});
|
2022-04-25 15:41:44 +02:00
|
|
|
this.routerService.setPreviousUrl(route.toString());
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
if (qParams.layout != null) {
|
|
|
|
this.layout = this.referenceData.layout = qParams.layout;
|
|
|
|
}
|
|
|
|
if (qParams.reference != null) {
|
|
|
|
this.referenceData.id = qParams.reference;
|
|
|
|
} else {
|
|
|
|
this.referenceData.id = ("; " + document.cookie)
|
|
|
|
.split("; reference=")
|
|
|
|
.pop()
|
|
|
|
.split(";")
|
|
|
|
.shift();
|
|
|
|
}
|
|
|
|
// Are they coming from an email for sponsoring a families organization
|
|
|
|
if (qParams.sponsorshipToken != null) {
|
|
|
|
// After logging in redirect them to setup the families sponsorship
|
2022-04-25 15:41:44 +02:00
|
|
|
const route = this.router.createUrlTree(["setup/families-for-enterprise"], {
|
|
|
|
queryParams: { plan: qParams.sponsorshipToken },
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
2022-04-25 15:41:44 +02:00
|
|
|
this.routerService.setPreviousUrl(route.toString());
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
if (this.referenceData.id === "") {
|
|
|
|
this.referenceData.id = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const invite = await this.stateService.getOrganizationInvitation();
|
|
|
|
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));
|
2020-03-03 17:20:28 +01:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
} catch (e) {
|
|
|
|
this.logService.error(e);
|
|
|
|
}
|
|
|
|
}
|
2021-07-23 21:30:04 +02:00
|
|
|
|
2021-12-17 15:57:11 +01:00
|
|
|
if (this.policies != null) {
|
|
|
|
this.enforcedPolicyOptions = await this.policyService.getMasterPasswordPolicyOptions(
|
|
|
|
this.policies
|
|
|
|
);
|
2020-03-03 17:20:28 +01:00
|
|
|
}
|
|
|
|
|
2021-12-17 15:57:11 +01:00
|
|
|
await super.ngOnInit();
|
|
|
|
}
|
2020-03-03 17:20:28 +01:00
|
|
|
|
2021-12-17 15:57:11 +01:00
|
|
|
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;
|
2018-07-13 16:51:52 +02:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
|
|
|
|
await super.submit();
|
|
|
|
}
|
2018-06-05 21:02:53 +02:00
|
|
|
}
|