2021-11-29 01:14:49 +01:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
NgZone,
|
|
|
|
} from '@angular/core';
|
2018-07-13 15:13:37 +02:00
|
|
|
import {
|
|
|
|
ActivatedRoute,
|
|
|
|
Router,
|
|
|
|
} from '@angular/router';
|
2018-06-05 21:02:53 +02:00
|
|
|
|
2021-10-15 00:59:43 +02:00
|
|
|
import { first } from 'rxjs/operators';
|
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { ApiService } from 'jslib-common/abstractions/api.service';
|
|
|
|
import { AuthService } from 'jslib-common/abstractions/auth.service';
|
|
|
|
import { CryptoFunctionService } from 'jslib-common/abstractions/cryptoFunction.service';
|
|
|
|
import { EnvironmentService } from 'jslib-common/abstractions/environment.service';
|
|
|
|
import { I18nService } from 'jslib-common/abstractions/i18n.service';
|
2021-10-20 18:30:04 +02:00
|
|
|
import { LogService } from 'jslib-common/abstractions/log.service';
|
2021-06-07 20:13:58 +02:00
|
|
|
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';
|
2018-06-05 21:02:53 +02:00
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { LoginComponent as BaseLoginComponent } from 'jslib-angular/components/login.component';
|
2018-06-05 21:02:53 +02:00
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { Policy } from 'jslib-common/models/domain/policy';
|
2021-06-02 18:35:49 +02:00
|
|
|
|
2018-06-05 21:02:53 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'app-login',
|
|
|
|
templateUrl: 'login.component.html',
|
|
|
|
})
|
|
|
|
export class LoginComponent extends BaseLoginComponent {
|
2021-06-02 18:35:49 +02:00
|
|
|
|
|
|
|
showResetPasswordAutoEnrollWarning = false;
|
|
|
|
|
2018-06-05 21:02:53 +02:00
|
|
|
constructor(authService: AuthService, router: Router,
|
2021-12-14 17:10:26 +01:00
|
|
|
i18nService: I18nService, private route: ActivatedRoute, stateService: StateService,
|
2020-08-11 17:30:30 +02:00
|
|
|
platformUtilsService: PlatformUtilsService, environmentService: EnvironmentService,
|
2021-06-02 18:35:49 +02:00
|
|
|
passwordGenerationService: PasswordGenerationService, cryptoFunctionService: CryptoFunctionService,
|
2021-11-29 01:14:49 +01:00
|
|
|
private apiService: ApiService, private policyService: PolicyService, logService: LogService,
|
|
|
|
ngZone: NgZone) {
|
2020-08-11 17:30:30 +02:00
|
|
|
super(authService, router,
|
|
|
|
platformUtilsService, i18nService,
|
|
|
|
stateService, environmentService,
|
|
|
|
passwordGenerationService, cryptoFunctionService,
|
2021-12-14 17:10:26 +01:00
|
|
|
logService, ngZone);
|
2018-07-13 16:51:52 +02:00
|
|
|
this.onSuccessfulLoginNavigate = this.goAfterLogIn;
|
2018-06-05 21:02:53 +02:00
|
|
|
}
|
2018-07-13 15:13:37 +02:00
|
|
|
|
|
|
|
async ngOnInit() {
|
2021-10-15 00:59:43 +02:00
|
|
|
this.route.queryParams.pipe(first()).subscribe(async qParams => {
|
2018-07-13 15:13:37 +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) {
|
2021-12-14 17:10:26 +01:00
|
|
|
this.stateService.setLoginRedirect({ route: '/settings/premium' });
|
2018-07-20 16:29:40 +02:00
|
|
|
} else if (qParams.org != null) {
|
2021-12-14 17:10:26 +01:00
|
|
|
this.stateService.setLoginRedirect(
|
2018-07-20 16:29:40 +02:00
|
|
|
{ route: '/settings/create-organization', qParams: { plan: qParams.org } });
|
|
|
|
}
|
2021-11-22 14:41:40 +01:00
|
|
|
|
|
|
|
// 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
|
2021-12-14 17:10:26 +01:00
|
|
|
this.stateService.setLoginRedirect({
|
2021-11-22 14:41:40 +01:00
|
|
|
route: '/setup/families-for-enterprise',
|
|
|
|
qParams: { token: qParams.sponsorshipToken },
|
|
|
|
});
|
|
|
|
}
|
2018-07-13 15:13:37 +02:00
|
|
|
await super.ngOnInit();
|
|
|
|
});
|
2021-06-02 18:35:49 +02:00
|
|
|
|
2021-12-14 17:10:26 +01:00
|
|
|
const invite = await this.stateService.getOrganizationInvitation();
|
2021-06-02 18:35:49 +02:00
|
|
|
if (invite != null) {
|
|
|
|
let policyList: Policy[] = null;
|
|
|
|
try {
|
|
|
|
const policies = await this.apiService.getPoliciesByToken(invite.organizationId, invite.token,
|
|
|
|
invite.email, invite.organizationUserId);
|
|
|
|
policyList = this.policyService.mapPoliciesFromToken(policies);
|
2021-10-20 18:30:04 +02:00
|
|
|
} catch (e) {
|
|
|
|
this.logService.error(e);
|
|
|
|
}
|
2021-06-02 18:35:49 +02:00
|
|
|
|
|
|
|
if (policyList != null) {
|
|
|
|
const result = this.policyService.getResetPasswordPolicyOptions(policyList, invite.organizationId);
|
|
|
|
// Set to true if policy enabled and auto-enroll enabled
|
|
|
|
this.showResetPasswordAutoEnrollWarning = result[1] && result[0].autoEnrollEnabled;
|
|
|
|
}
|
|
|
|
}
|
2018-07-13 15:13:37 +02:00
|
|
|
}
|
2018-07-13 16:51:52 +02:00
|
|
|
|
|
|
|
async goAfterLogIn() {
|
2021-12-14 17:10:26 +01:00
|
|
|
const loginRedirect = await this.stateService.getLoginRedirect();
|
2021-06-15 21:02:04 +02:00
|
|
|
if (loginRedirect != null) {
|
|
|
|
this.router.navigate([loginRedirect.route], { queryParams: loginRedirect.qParams });
|
2021-12-14 17:10:26 +01:00
|
|
|
await this.stateService.setLoginRedirect(null);
|
2018-07-13 16:51:52 +02:00
|
|
|
} else {
|
2021-06-15 21:02:04 +02:00
|
|
|
this.router.navigate([this.successRoute]);
|
2018-07-13 16:51:52 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-05 21:02:53 +02:00
|
|
|
}
|