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'
11 selector: 'my-account-change-email',
12 templateUrl: './my-account-change-email.component.html',
13 styleUrls: [ './my-account-change-email.component.scss' ]
15 export class MyAccountChangeEmailComponent extends FormReactive implements OnInit {
17 success: string = null
21 protected formValidatorService: FormValidatorService,
22 private userValidatorsService: UserValidatorsService,
23 private notifier: Notifier,
24 private authService: AuthService,
25 private userService: UserService,
26 private serverService: ServerService,
34 'new-email': this.userValidatorsService.USER_EMAIL,
35 'password': this.userValidatorsService.USER_PASSWORD
38 this.user = this.authService.getUser()
45 const password = this.form.value[ 'password' ]
46 const email = this.form.value[ 'new-email' ]
48 this.userService.changeEmail(password, email)
50 tap(() => this.authService.refreshUserInformation())
56 if (this.serverService.getConfig().signup.requiresEmailVerification) {
57 this.success = this.i18n('Please check your emails to verify your new email.')
59 this.success = this.i18n('Email updated.')
64 if (err.status === 401) {
65 this.error = this.i18n('You current password is invalid.')
69 this.error = err.message