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 { FormReactive, FormValidatorService, UserValidatorsService } from '@app/shared/shared-forms'
6 import { I18n } from '@ngx-translate/i18n-polyfill'
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 userValidatorsService: UserValidatorsService,
22 private authService: AuthService,
23 private userService: UserService,
24 private serverService: ServerService,
32 'new-email': this.userValidatorsService.USER_EMAIL,
33 'password': this.userValidatorsService.USER_PASSWORD
36 this.user = this.authService.getUser()
43 const password = this.form.value[ 'password' ]
44 const email = this.form.value[ 'new-email' ]
47 this.serverService.getConfig(),
48 this.userService.changeEmail(password, email)
49 ]).pipe(tap(() => this.authService.refreshUserInformation()))
54 if (config.signup.requiresEmailVerification) {
55 this.success = this.i18n('Please check your emails to verify your new email.')
57 this.success = this.i18n('Email updated.')
62 if (err.status === 401) {
63 this.error = this.i18n('You current password is invalid.')
67 this.error = err.message