argos/dmp-frontend/src/app/ui/auth/login/email-confirmation/email-confirmation.componen...

69 lines
2.2 KiB
TypeScript

import { Component, OnInit } from "@angular/core";
import { ActivatedRoute, Params, Router } from "@angular/router";
import { takeUntil } from "rxjs/operators";
import { BaseComponent } from "../../../../core/common/base/base.component";
import { EmailConfirmationService } from "../../../../core/services/email-confirmation/email-confirmation.service";
import { UiNotificationService, SnackBarNotificationLevel } from "../../../../core/services/notification/ui-notification-service";
import { TranslateService } from "@ngx-translate/core";
import { FormControl } from "@angular/forms";
@Component({
selector: 'app-email-confirmation-component',
templateUrl: './email-confirmation.component.html'
})
export class EmailConfirmation extends BaseComponent implements OnInit {
private emailFormControl = new FormControl('');
private showForm: boolean = false;
private mailSent: boolean = false;
constructor(
private emailConfirmationService: EmailConfirmationService,
private route: ActivatedRoute,
private router: Router,
private language: TranslateService,
private uiNotificationService: UiNotificationService
) { super(); }
ngOnInit() {
this.route.params
.pipe(takeUntil(this._destroyed))
.subscribe(params => {
const token = params['token']
if (token != null) {
this.showForm = false;
this.emailConfirmationService.emailConfirmation(token)
.pipe(takeUntil(this._destroyed))
.subscribe(
result => this.onCallbackEmailConfirmationSuccess(),
error => this.onCallbackError(error)
)
} else {
this.showForm = true;
}
});
}
sendConfirmationEmail() {
this.emailConfirmationService.sendConfirmationEmail(this.emailFormControl.value)
.pipe(takeUntil(this._destroyed))
.subscribe(
result => this.onCallbackSuccess(),
error => this.onCallbackError(error)
)
}
onCallbackSuccess() {
this.mailSent = true;
}
onCallbackEmailConfirmationSuccess() {
this.router.navigate(['home']);
}
onCallbackError(error: any) {
this.uiNotificationService.snackBarNotification(this.language.instant('EMAIL-CONFIRMATION.EXPIRED-EMAIL'), SnackBarNotificationLevel.Error);
this.router.navigate(['login']);
}
}