1 import { forkJoin } from 'rxjs'
2 import { tap } from 'rxjs/operators'
3 import { Component, OnInit } from '@angular/core'
4 import { AuthService, ServerService, UserService } from '@app/core'
5 import { USER_EMAIL_VALIDATOR, USER_PASSWORD_VALIDATOR } from '@app/shared/form-validators/user-validators'
6 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
7 import { User } from '@shared/models'
10 selector: 'my-account-change-email',
11 templateUrl: './my-account-change-email.component.html',
12 styleUrls: [ './my-account-change-email.component.scss' ]
14 export class MyAccountChangeEmailComponent extends FormReactive implements OnInit {
16 success: string = null
20 protected formValidatorService: FormValidatorService,
21 private authService: AuthService,
22 private userService: UserService,
23 private serverService: ServerService
30 'new-email': USER_EMAIL_VALIDATOR,
31 password: USER_PASSWORD_VALIDATOR
34 this.user = this.authService.getUser()
41 const password = this.form.value['password']
42 const email = this.form.value['new-email']
45 this.serverService.getConfig(),
46 this.userService.changeEmail(password, email)
47 ]).pipe(tap(() => this.authService.refreshUserInformation()))
49 next: ([ config ]) => {
52 if (config.signup.requiresEmailVerification) {
53 this.success = $localize`Please check your emails to verify your new email.`
55 this.success = $localize`Email updated.`
60 if (err.status === 401) {
61 this.error = $localize`You current password is invalid.`
65 this.error = err.message