2018-06-05 21:02:53 +02:00
|
|
|
import { Component } from "@angular/core";
|
2022-07-26 14:48:11 +02:00
|
|
|
import { UntypedFormBuilder } from "@angular/forms";
|
2018-07-13 16:51:52 +02:00
|
|
|
import { ActivatedRoute, Router } from "@angular/router";
|
2021-10-15 00:59:43 +02:00
|
|
|
import { first } from "rxjs/operators";
|
|
|
|
|
2022-06-14 17:10:53 +02:00
|
|
|
import { RegisterComponent as BaseRegisterComponent } from "@bitwarden/angular/components/register.component";
|
|
|
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|
|
|
import { AuthService } from "@bitwarden/common/abstractions/auth.service";
|
|
|
|
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
|
|
|
|
import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service";
|
2022-07-05 21:25:14 +02:00
|
|
|
import { FormValidationErrorsService } from "@bitwarden/common/abstractions/formValidationErrors.service";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
|
|
|
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
|
|
|
import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwordGeneration.service";
|
|
|
|
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
2022-08-08 11:04:36 +02:00
|
|
|
import { PolicyApiServiceAbstraction } from "@bitwarden/common/abstractions/policy/policy-api.service.abstraction";
|
|
|
|
import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.service.abstraction";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { StateService } from "@bitwarden/common/abstractions/state.service";
|
|
|
|
import { PolicyData } from "@bitwarden/common/models/data/policyData";
|
|
|
|
import { MasterPasswordPolicyOptions } from "@bitwarden/common/models/domain/masterPasswordPolicyOptions";
|
|
|
|
import { Policy } from "@bitwarden/common/models/domain/policy";
|
|
|
|
import { ReferenceEventRequest } from "@bitwarden/common/models/request/referenceEventRequest";
|
2020-03-02 17:51:05 +01:00
|
|
|
|
2022-07-26 19:34:45 +02:00
|
|
|
import { RouterService } from "../core";
|
2022-04-25 15:41:44 +02:00
|
|
|
|
2018-06-05 21:02:53 +02:00
|
|
|
@Component({
|
|
|
|
selector: "app-register",
|
|
|
|
templateUrl: "register.component.html",
|
|
|
|
})
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
2018-06-05 21:02:53 +02:00
|
|
|
export class RegisterComponent extends BaseRegisterComponent {
|
2022-07-05 21:25:14 +02:00
|
|
|
email = "";
|
2018-07-20 16:29:40 +02:00
|
|
|
showCreateOrgMessage = false;
|
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(
|
2022-07-05 21:25:14 +02:00
|
|
|
formValidationErrorService: FormValidationErrorsService,
|
2022-07-26 14:48:11 +02:00
|
|
|
formBuilder: UntypedFormBuilder,
|
2018-06-05 21:02:53 +02:00
|
|
|
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,
|
2021-07-23 20:47:43 +02:00
|
|
|
passwordGenerationService: PasswordGenerationService,
|
2022-08-08 11:04:36 +02:00
|
|
|
private policyApiService: PolicyApiServiceAbstraction,
|
2021-07-23 20:47:43 +02:00
|
|
|
private policyService: PolicyService,
|
2021-10-20 18:30:04 +02:00
|
|
|
environmentService: EnvironmentService,
|
2022-04-25 15:41:44 +02:00
|
|
|
logService: LogService,
|
|
|
|
private routerService: RouterService
|
2021-10-20 18:30:04 +02:00
|
|
|
) {
|
2018-11-13 04:54:40 +01:00
|
|
|
super(
|
2022-07-05 21:25:14 +02:00
|
|
|
formValidationErrorService,
|
|
|
|
formBuilder,
|
2018-11-13 04:54:40 +01:00
|
|
|
authService,
|
|
|
|
router,
|
|
|
|
i18nService,
|
|
|
|
cryptoService,
|
|
|
|
apiService,
|
|
|
|
stateService,
|
|
|
|
platformUtilsService,
|
2021-10-20 18:30:04 +02:00
|
|
|
passwordGenerationService,
|
|
|
|
environmentService,
|
|
|
|
logService
|
|
|
|
);
|
2018-06-05 21:02:53 +02:00
|
|
|
}
|
2018-07-13 16:51:52 +02:00
|
|
|
|
2020-03-02 17:51:05 +01:00
|
|
|
async ngOnInit() {
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
2021-10-15 00:59:43 +02:00
|
|
|
this.route.queryParams.pipe(first()).subscribe((qParams) => {
|
2020-07-21 16:43:38 +02:00
|
|
|
this.referenceData = new ReferenceEventRequest();
|
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) {
|
2022-04-25 15:41:44 +02:00
|
|
|
this.routerService.setPreviousUrl("/settings/premium");
|
2020-06-25 21:18:21 +02:00
|
|
|
} else if (qParams.org != null) {
|
2020-07-21 16:43:38 +02:00
|
|
|
this.showCreateOrgMessage = true;
|
|
|
|
this.referenceData.flow = qParams.org;
|
2022-05-11 21:39:39 +02:00
|
|
|
const route = this.router.createUrlTree(["create-organization"], {
|
2022-04-25 15:41:44 +02:00
|
|
|
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
|
|
|
}
|
2021-12-14 17:10:26 +01:00
|
|
|
if (qParams.layout != null) {
|
|
|
|
this.layout = this.referenceData.layout = qParams.layout;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2021-11-22 14:41:40 +01:00
|
|
|
if (qParams.reference != null) {
|
2021-12-14 17:10:26 +01:00
|
|
|
this.referenceData.id = qParams.reference;
|
|
|
|
} else {
|
2020-07-21 16:43:38 +02:00
|
|
|
this.referenceData.id = ("; " + document.cookie)
|
2021-12-14 17:10:26 +01:00
|
|
|
.split("; reference=")
|
2021-12-17 15:57:11 +01:00
|
|
|
.pop()
|
2021-12-14 17:10:26 +01:00
|
|
|
.split(";")
|
|
|
|
.shift();
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2021-12-14 17:10:26 +01:00
|
|
|
// Are they coming from an email for sponsoring a families organization
|
2020-03-02 17:51:05 +01:00
|
|
|
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
|
|
|
}
|
2020-03-02 17:51:05 +01:00
|
|
|
if (this.referenceData.id === "") {
|
2020-07-21 16:43:38 +02:00
|
|
|
this.referenceData.id = null;
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
});
|
2020-03-02 17:51:05 +01:00
|
|
|
const invite = await this.stateService.getOrganizationInvitation();
|
|
|
|
if (invite != null) {
|
2021-12-17 15:57:11 +01:00
|
|
|
try {
|
2022-08-08 11:04:36 +02:00
|
|
|
const policies = await this.policyApiService.getPoliciesByToken(
|
2020-03-02 17:51:05 +01:00
|
|
|
invite.organizationId,
|
|
|
|
invite.token,
|
|
|
|
invite.email,
|
|
|
|
invite.organizationUserId
|
|
|
|
);
|
|
|
|
if (policies.data != null) {
|
2021-02-03 18:41:33 +01:00
|
|
|
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-10-20 18:30:04 +02:00
|
|
|
} catch (e) {
|
|
|
|
this.logService.error(e);
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
|
|
|
}
|
2021-07-23 21:30:04 +02:00
|
|
|
|
2020-03-03 17:20:28 +01:00
|
|
|
if (this.policies != null) {
|
2021-07-23 21:30:04 +02:00
|
|
|
this.enforcedPolicyOptions = await this.policyService.getMasterPasswordPolicyOptions(
|
2020-03-03 17:20:28 +01:00
|
|
|
this.policies
|
2021-07-23 21:30:04 +02:00
|
|
|
);
|
2020-03-03 17:20:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
await super.ngOnInit();
|
|
|
|
}
|
2018-06-05 21:02:53 +02:00
|
|
|
}
|