From b426edd4854adc6e65844d8c54b8998e792b5778 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 11 Feb 2019 09:30:29 +0100 Subject: Cleanup reset user password by admin And add some tests --- client/package.json | 3 +- .../users/user-edit/user-edit.component.html | 16 ++++++---- .../users/user-edit/user-edit.component.scss | 13 ++++++++ client/src/app/+admin/users/user-edit/user-edit.ts | 5 ++++ .../users/user-edit/user-password.component.html | 16 ++++------ .../users/user-edit/user-password.component.scss | 1 + .../users/user-edit/user-password.component.ts | 35 ++++------------------ .../users/user-edit/user-update.component.ts | 5 ++-- client/src/app/shared/users/user.service.ts | 5 ---- 9 files changed, 43 insertions(+), 56 deletions(-) (limited to 'client') diff --git a/client/package.json b/client/package.json index 9e5e87d4a..3eea661f1 100644 --- a/client/package.json +++ b/client/package.json @@ -164,7 +164,6 @@ "webpack-cli": "^3.0.8", "webtorrent": "https://github.com/webtorrent/webtorrent#e9b209c7970816fc29e0cc871157a4918d66001d", "whatwg-fetch": "^3.0.0", - "zone.js": "~0.8.5", - "generate-password-browser": "^1.0.2" + "zone.js": "~0.8.5" } } diff --git a/client/src/app/+admin/users/user-edit/user-edit.component.html b/client/src/app/+admin/users/user-edit/user-edit.component.html index 3ce246771..c6566da24 100644 --- a/client/src/app/+admin/users/user-edit/user-edit.component.html +++ b/client/src/app/+admin/users/user-edit/user-edit.component.html @@ -82,12 +82,16 @@ -
+
-

Send a link to reset the password by mail to the user.

- +
+ + +
-

Manually set the user password

- -
\ No newline at end of file +
+ + +
+
diff --git a/client/src/app/+admin/users/user-edit/user-edit.component.scss b/client/src/app/+admin/users/user-edit/user-edit.component.scss index 2b4aae83c..c1cc4ca45 100644 --- a/client/src/app/+admin/users/user-edit/user-edit.component.scss +++ b/client/src/app/+admin/users/user-edit/user-edit.component.scss @@ -32,3 +32,16 @@ input[type=submit], button { margin-top: 55px; margin-bottom: 30px; } + +.danger-zone { + .reset-password-email { + margin-bottom: 30px; + padding-bottom: 30px; + border-bottom: 1px solid rgba(0, 0, 0, 0.1); + + button { + display: block; + margin-top: 0; + } + } +} diff --git a/client/src/app/+admin/users/user-edit/user-edit.ts b/client/src/app/+admin/users/user-edit/user-edit.ts index 021b1feb4..649b35b0c 100644 --- a/client/src/app/+admin/users/user-edit/user-edit.ts +++ b/client/src/app/+admin/users/user-edit/user-edit.ts @@ -8,6 +8,7 @@ export abstract class UserEdit extends FormReactive { videoQuotaDailyOptions: { value: string, label: string }[] = [] roles = Object.keys(USER_ROLE_LABELS).map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] })) username: string + userId: number protected abstract serverService: ServerService protected abstract configService: ConfigService @@ -37,6 +38,10 @@ export abstract class UserEdit extends FormReactive { return multiplier * parseInt(this.form.value['videoQuota'], 10) } + resetPassword () { + return + } + protected buildQuotaOptions () { // These are used by a HTML select, so convert key into strings this.videoQuotaOptions = this.configService diff --git a/client/src/app/+admin/users/user-edit/user-password.component.html b/client/src/app/+admin/users/user-edit/user-password.component.html index 822e4688e..a1e1f6216 100644 --- a/client/src/app/+admin/users/user-edit/user-password.component.html +++ b/client/src/app/+admin/users/user-edit/user-password.component.html @@ -1,19 +1,15 @@
-
-
-
- -
-
- +
- +
diff --git a/client/src/app/+admin/users/user-edit/user-password.component.scss b/client/src/app/+admin/users/user-edit/user-password.component.scss index 9185e787c..217d585af 100644 --- a/client/src/app/+admin/users/user-edit/user-password.component.scss +++ b/client/src/app/+admin/users/user-edit/user-password.component.scss @@ -3,6 +3,7 @@ input:not([type=submit]):not([type=checkbox]) { @include peertube-input-text(340px); + display: block; border-top-right-radius: 0; border-bottom-right-radius: 0; diff --git a/client/src/app/+admin/users/user-edit/user-password.component.ts b/client/src/app/+admin/users/user-edit/user-password.component.ts index 30cd21ccd..5b3040440 100644 --- a/client/src/app/+admin/users/user-edit/user-password.component.ts +++ b/client/src/app/+admin/users/user-edit/user-password.component.ts @@ -1,14 +1,11 @@ -import { Component, OnDestroy, OnInit, Input } from '@angular/core' +import { Component, Input, OnInit } from '@angular/core' import { ActivatedRoute, Router } from '@angular/router' -import * as generator from 'generate-password-browser' -import { NotificationsService } from 'angular2-notifications' import { UserService } from '@app/shared/users/user.service' -import { ServerService } from '../../../core' +import { Notifier } from '../../../core' import { User, UserUpdate } 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 { ConfigService } from '@app/+admin/config/shared/config.service' import { FormReactive } from '../../../shared' @Component({ @@ -16,7 +13,7 @@ import { FormReactive } from '../../../shared' templateUrl: './user-password.component.html', styleUrls: [ './user-password.component.scss' ] }) -export class UserPasswordComponent extends FormReactive implements OnInit, OnDestroy { +export class UserPasswordComponent extends FormReactive implements OnInit { error: string username: string showPassword = false @@ -25,12 +22,10 @@ export class UserPasswordComponent extends FormReactive implements OnInit, OnDes constructor ( protected formValidatorService: FormValidatorService, - protected serverService: ServerService, - protected configService: ConfigService, private userValidatorsService: UserValidatorsService, private route: ActivatedRoute, private router: Router, - private notificationsService: NotificationsService, + private notifier: Notifier, private userService: UserService, private i18n: I18n ) { @@ -43,10 +38,6 @@ export class UserPasswordComponent extends FormReactive implements OnInit, OnDes }) } - ngOnDestroy () { - // - } - formValidated () { this.error = undefined @@ -54,8 +45,7 @@ export class UserPasswordComponent extends FormReactive implements OnInit, OnDes this.userService.updateUser(this.userId, userUpdate).subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), + this.notifier.success( this.i18n('Password changed for user {{username}}.', { username: this.username }) ) }, @@ -64,16 +54,6 @@ export class UserPasswordComponent extends FormReactive implements OnInit, OnDes ) } - generatePassword () { - this.form.patchValue({ - password: generator.generate({ - length: 16, - excludeSimilarCharacters: true, - strict: true - }) - }) - } - togglePasswordVisibility () { this.showPassword = !this.showPassword } @@ -81,9 +61,4 @@ export class UserPasswordComponent extends FormReactive implements OnInit, OnDes getFormButtonTitle () { return this.i18n('Update user password') } - - private onUserFetched (userJson: User) { - this.userId = userJson.id - this.username = userJson.username - } } diff --git a/client/src/app/+admin/users/user-edit/user-update.component.ts b/client/src/app/+admin/users/user-edit/user-update.component.ts index 4e4002a73..94ef87b08 100644 --- a/client/src/app/+admin/users/user-edit/user-update.component.ts +++ b/client/src/app/+admin/users/user-edit/user-update.component.ts @@ -1,4 +1,4 @@ -import { Component, OnDestroy, OnInit, Input } from '@angular/core' +import { Component, OnDestroy, OnInit } from '@angular/core' import { ActivatedRoute, Router } from '@angular/router' import { Subscription } from 'rxjs' import { Notifier } from '@app/core' @@ -93,8 +93,7 @@ export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy { resetPassword () { this.userService.askResetPassword(this.userEmail).subscribe( () => { - this.notificationsService.success( - this.i18n('Success'), + this.notifier.success( this.i18n('An email asking for password reset has been sent to {{username}}.', { username: this.username }) ) }, diff --git a/client/src/app/shared/users/user.service.ts b/client/src/app/shared/users/user.service.ts index d0abc7def..cc5c051f1 100644 --- a/client/src/app/shared/users/user.service.ts +++ b/client/src/app/shared/users/user.service.ts @@ -103,11 +103,6 @@ export class UserService { ) } - resetUserPassword (userId: number) { - return this.authHttp.post(UserService.BASE_USERS_URL + userId + '/reset-password', {}) - .pipe(catchError(err => this.restExtractor.handleError(err))) - } - verifyEmail (userId: number, verificationString: string) { const url = `${UserService.BASE_USERS_URL}/${userId}/verify-email` const body = { -- cgit v1.2.3