From 0ba5f5baade94a051710d9d9d408ac8083c14ac6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 11 Jun 2019 14:30:49 +0200 Subject: Add ability to change email in client --- .../my-account-change-email/index.ts | 1 + .../my-account-change-email.component.html | 36 +++++++++++ .../my-account-change-email.component.scss | 24 +++++++ .../my-account-change-email.component.ts | 73 ++++++++++++++++++++++ .../my-account-change-password.component.html | 2 +- .../my-account-settings.component.html | 3 + 6 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 client/src/app/+my-account/my-account-settings/my-account-change-email/index.ts create mode 100644 client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.html create mode 100644 client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.scss create mode 100644 client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.ts (limited to 'client/src/app/+my-account/my-account-settings') diff --git a/client/src/app/+my-account/my-account-settings/my-account-change-email/index.ts b/client/src/app/+my-account/my-account-settings/my-account-change-email/index.ts new file mode 100644 index 000000000..f42af361e --- /dev/null +++ b/client/src/app/+my-account/my-account-settings/my-account-change-email/index.ts @@ -0,0 +1 @@ +export * from './my-account-change-email.component' diff --git a/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.html b/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.html new file mode 100644 index 000000000..ebfe3126d --- /dev/null +++ b/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.html @@ -0,0 +1,36 @@ +
{{ error }}
+
{{ success }}
+ +
+ Your current email is +
+ +
+ is awaiting email verification +
+ +
+ +
+ + +
+ {{ formErrors['new-email'] }} +
+
+ +
+ +
+ {{ formErrors['password'] }} +
+
+ + +
diff --git a/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.scss b/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.scss new file mode 100644 index 000000000..81eba3ec9 --- /dev/null +++ b/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.scss @@ -0,0 +1,24 @@ +@import '_variables'; +@import '_mixins'; + +input[type=password], +input[type=email] { + @include peertube-input-text(340px); + + display: block; +} + +input[type=submit] { + @include peertube-button; + @include orange-button; +} + +.current-email, +.pending-email { + font-size: 16px; + margin: 15px 0; + + .email { + font-weight: $font-semibold; + } +} diff --git a/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.ts b/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.ts new file mode 100644 index 000000000..577c5b102 --- /dev/null +++ b/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.ts @@ -0,0 +1,73 @@ +import { Component, OnInit } from '@angular/core' +import { AuthService, Notifier, ServerService } from '@app/core' +import { FormReactive, UserService } from '../../../shared' +import { I18n } from '@ngx-translate/i18n-polyfill' +import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' +import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service' +import { User } from '../../../../../../shared' +import { switchMap, tap } from 'rxjs/operators' + +@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 notifier: Notifier, + private authService: AuthService, + private userService: UserService, + private serverService: ServerService, + private i18n: I18n + ) { + 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' ] + + this.userService.changeEmail(password, email) + .pipe( + tap(() => this.authService.refreshUserInformation()) + ) + .subscribe( + () => { + this.form.reset() + + if (this.serverService.getConfig().signup.requiresEmailVerification) { + this.success = this.i18n('Please check your emails to verify your new email.') + } else { + this.success = this.i18n('Email updated.') + } + }, + + err => { + if (err.status === 401) { + this.error = this.i18n('You current password is invalid.') + return + } + + this.error = err.message + } + ) + } +} diff --git a/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.html b/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.html index ae797d1bc..a39061ee3 100644 --- a/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.html +++ b/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.html @@ -2,7 +2,7 @@
- + Password + + + -- cgit v1.2.3