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

95 lines
3.2 KiB
TypeScript

import { Component, OnInit } from "@angular/core";
import { UntypedFormControl } from '@angular/forms';
import { MatDialog } from "@angular/material/dialog";
import { ActivatedRoute, Router } from "@angular/router";
import { AuthService } from "@app/core/services/auth/auth.service";
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
import { UserService } from "@app/core/services/user/user.service";
import { PopupNotificationDialogComponent } from "@app/library/notification/popup/popup-notification.component";
import { BaseComponent } from '@common/base/base.component';
import { Guid } from "@common/types/guid";
import { TranslateService } from '@ngx-translate/core';
import { takeUntil } from "rxjs/operators";
@Component({
selector: 'app-email-confirmation-component',
templateUrl: './merge-email-confirmation.component.html',
styleUrls: ['./merge-email-confirmation.component.scss']
})
export class MergeEmailConfirmation extends BaseComponent implements OnInit {
private token: Guid;
public emailFormControl = new UntypedFormControl('');
public mailSent: boolean = false;
get showForm(): boolean {
return this.token != null;
}
constructor(
//TODO: refactor
// private emailConfirmationService: MergeEmailConfirmationService,
// private authService: AuthService,
private userService: UserService,
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.token = token;
// this.showForm = false;
//TODO: refactor
// this.emailConfirmationService.emailConfirmation(token)
// .pipe(takeUntil(this._destroyed))
// .subscribe(
// result => {
// const email = this.authService.getUserProfileEmail();
// if(!email || !result || (email == result))
// this.authService.clear();
// this.uiNotificationService.snackBarNotification(this.language.instant('USER-PROFILE.MERGING-SUCCESS'), SnackBarNotificationLevel.Success);
// this.onCallbackEmailConfirmationSuccess();
// },
// error => this.onCallbackError(error)
// )
} else {
// this.showForm = true;
}
});
}
onConfirm(): void {
console.log('onConfirm');
if (this.showForm === false) return;
console.log('active');
this.userService.confirmMergeAccount(this.token)
.subscribe(result => {
if (result) {
this.onCallbackEmailConfirmationSuccess();
}
},
error => this.onCallbackError(error));
}
onCallbackEmailConfirmationSuccess() {
this.router.navigate(['home']);
}
onCallbackError(error: any) {
if (error.status === 302) {
this.uiNotificationService.snackBarNotification(this.language.instant('EMAIL-CONFIRMATION.EMAIL-FOUND'), SnackBarNotificationLevel.Warning);
this.router.navigate(['home']);
} else {
this.uiNotificationService.snackBarNotification(this.language.instant('EMAIL-CONFIRMATION.EXPIRED-EMAIL'), SnackBarNotificationLevel.Error);
}
}
}