1 import { Component, OnInit } from '@angular/core'
2 import { AuthService, Notifier, ServerService } from '@app/core'
3 import { FormReactive, UserService } from '../../../shared'
4 import { I18n } from '@ngx-translate/i18n-polyfill'
5 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
6 import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service'
7 import { User } from '../../../../../../shared'
8 import { tap } from 'rxjs/operators'
9 import { forkJoin } from 'rxjs'
12 selector: 'my-account-change-email',
13 templateUrl: './my-account-change-email.component.html',
14 styleUrls: [ './my-account-change-email.component.scss' ]
16 export class MyAccountChangeEmailComponent extends FormReactive implements OnInit {
18 success: string = null
22 protected formValidatorService: FormValidatorService,
23 private userValidatorsService: UserValidatorsService,
24 private notifier: Notifier,
25 private authService: AuthService,
26 private userService: UserService,
27 private serverService: ServerService,
35 'new-email': this.userValidatorsService.USER_EMAIL,
36 'password': this.userValidatorsService.USER_PASSWORD
39 this.user = this.authService.getUser()
46 const password = this.form.value[ 'password' ]
47 const email = this.form.value[ 'new-email' ]
50 this.serverService.getConfig(),
51 this.userService.changeEmail(password, email)
52 ]).pipe(tap(() => this.authService.refreshUserInformation()))
57 if (config.signup.requiresEmailVerification) {
58 this.success = this.i18n('Please check your emails to verify your new email.')
60 this.success = this.i18n('Email updated.')
65 if (err.status === 401) {
66 this.error = this.i18n('You current password is invalid.')
70 this.error = err.message