2018-07-12 20:19:47 +02:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
OnInit,
|
|
|
|
} from '@angular/core';
|
|
|
|
import {
|
|
|
|
ActivatedRoute,
|
|
|
|
Router,
|
|
|
|
} from '@angular/router';
|
|
|
|
|
2021-10-15 00:59:43 +02:00
|
|
|
import { first } from 'rxjs/operators';
|
|
|
|
|
2018-07-12 20:19:47 +02:00
|
|
|
import { ToasterService } from 'angular2-toaster';
|
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { ApiService } from 'jslib-common/abstractions/api.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 { UserService } from 'jslib-common/abstractions/user.service';
|
2018-07-12 20:19:47 +02:00
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { VerifyEmailRequest } from 'jslib-common/models/request/verifyEmailRequest';
|
2018-07-12 20:19:47 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-verify-email-token',
|
|
|
|
templateUrl: 'verify-email-token.component.html',
|
|
|
|
})
|
|
|
|
export class VerifyEmailTokenComponent implements OnInit {
|
|
|
|
constructor(private router: Router, private toasterService: ToasterService,
|
|
|
|
private i18nService: I18nService, private route: ActivatedRoute,
|
2021-10-20 18:30:04 +02:00
|
|
|
private apiService: ApiService, private userService: UserService,
|
|
|
|
private logService: LogService) { }
|
2018-07-12 20:19:47 +02:00
|
|
|
|
|
|
|
ngOnInit() {
|
2021-10-15 00:59:43 +02:00
|
|
|
this.route.queryParams.pipe(first()).subscribe(async qParams => {
|
2018-07-12 20:19:47 +02:00
|
|
|
if (qParams.userId != null && qParams.token != null) {
|
|
|
|
try {
|
|
|
|
await this.apiService.postAccountVerifyEmailToken(
|
|
|
|
new VerifyEmailRequest(qParams.userId, qParams.token));
|
|
|
|
const authed = await this.userService.isAuthenticated();
|
|
|
|
if (authed) {
|
|
|
|
await this.apiService.refreshIdentityToken();
|
|
|
|
}
|
|
|
|
this.toasterService.popAsync('success', null, this.i18nService.t('emailVerified'));
|
|
|
|
this.router.navigate(['/']);
|
|
|
|
return;
|
2021-10-20 18:30:04 +02:00
|
|
|
} catch (e) {
|
|
|
|
this.logService.error(e);
|
|
|
|
}
|
2018-07-12 20:19:47 +02:00
|
|
|
}
|
|
|
|
this.toasterService.popAsync('error', null, this.i18nService.t('emailVerifiedFailed'));
|
|
|
|
this.router.navigate(['/']);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|