PeerTube/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.ts
Chocobozzz 66357162f8
Migrate to $localize
* Remove i18n polyfill to translate things in components
 * Reduce bundle sizes
 * Improve runtime perf
 * Reduce a lot the time to make a full client build
 * Reduce client build complexity
 * We don't need a service to translate things anymore (so we will be able to translate title pages etc)

Unfortunately we may loose some translations in the migration process.
I'll put a message on weblate to notify translators
2020-08-14 10:28:30 +02:00

69 lines
2 KiB
TypeScript

import { forkJoin } from 'rxjs'
import { tap } from 'rxjs/operators'
import { Component, OnInit } from '@angular/core'
import { AuthService, ServerService, UserService } from '@app/core'
import { FormReactive, FormValidatorService, UserValidatorsService } from '@app/shared/shared-forms'
import { User } from '@shared/models'
@Component({
selector: 'my-account-change-email',
templateUrl: './my-account-change-email.component.html',
styleUrls: [ './my-account-change-email.component.scss' ]
})
export class MyAccountChangeEmailComponent extends FormReactive implements OnInit {
error: string = null
success: string = null
user: User = null
constructor (
protected formValidatorService: FormValidatorService,
private userValidatorsService: UserValidatorsService,
private authService: AuthService,
private userService: UserService,
private serverService: ServerService
) {
super()
}
ngOnInit () {
this.buildForm({
'new-email': this.userValidatorsService.USER_EMAIL,
'password': this.userValidatorsService.USER_PASSWORD
})
this.user = this.authService.getUser()
}
changeEmail () {
this.error = null
this.success = null
const password = this.form.value[ 'password' ]
const email = this.form.value[ 'new-email' ]
forkJoin([
this.serverService.getConfig(),
this.userService.changeEmail(password, email)
]).pipe(tap(() => this.authService.refreshUserInformation()))
.subscribe(
([ config ]) => {
this.form.reset()
if (config.signup.requiresEmailVerification) {
this.success = $localize`Please check your emails to verify your new email.`
} else {
this.success = $localize`Email updated.`
}
},
err => {
if (err.status === 401) {
this.error = $localize`You current password is invalid.`
return
}
this.error = err.message
}
)
}
}