From 1942f11d5ee6926ad93dc1b79fae18325ba5de18 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Jun 2020 14:49:20 +0200 Subject: Lazy load all routes --- .../+reset-password/reset-password.component.ts | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 client/src/app/+reset-password/reset-password.component.ts (limited to 'client/src/app/+reset-password/reset-password.component.ts') diff --git a/client/src/app/+reset-password/reset-password.component.ts b/client/src/app/+reset-password/reset-password.component.ts new file mode 100644 index 000000000..8d50e9839 --- /dev/null +++ b/client/src/app/+reset-password/reset-password.component.ts @@ -0,0 +1,61 @@ +import { Component, OnInit } from '@angular/core' +import { ActivatedRoute, Router } from '@angular/router' +import { Notifier, UserService } from '@app/core' +import { FormReactive, FormValidatorService, ResetPasswordValidatorsService, UserValidatorsService } from '@app/shared/shared-forms' +import { I18n } from '@ngx-translate/i18n-polyfill' + +@Component({ + selector: 'my-login', + templateUrl: './reset-password.component.html', + styleUrls: [ './reset-password.component.scss' ] +}) + +export class ResetPasswordComponent extends FormReactive implements OnInit { + private userId: number + private verificationString: string + + constructor ( + protected formValidatorService: FormValidatorService, + private resetPasswordValidatorsService: ResetPasswordValidatorsService, + private userValidatorsService: UserValidatorsService, + private userService: UserService, + private notifier: Notifier, + private router: Router, + private route: ActivatedRoute, + private i18n: I18n + ) { + super() + } + + ngOnInit () { + this.buildForm({ + password: this.userValidatorsService.USER_PASSWORD, + 'password-confirm': this.resetPasswordValidatorsService.RESET_PASSWORD_CONFIRM + }) + + this.userId = this.route.snapshot.queryParams['userId'] + this.verificationString = this.route.snapshot.queryParams['verificationString'] + + if (!this.userId || !this.verificationString) { + this.notifier.error(this.i18n('Unable to find user id or verification string.')) + this.router.navigate([ '/' ]) + } + } + + resetPassword () { + this.userService.resetPassword(this.userId, this.verificationString, this.form.value.password) + .subscribe( + () => { + this.notifier.success(this.i18n('Your password has been successfully reset!')) + this.router.navigate([ '/login' ]) + }, + + err => this.notifier.error(err.message) + ) + } + + isConfirmedPasswordValid () { + const values = this.form.value + return values.password === values['password-confirm'] + } +} -- cgit v1.2.3