diff options
author | John Livingston <38844060+JohnXLivingston@users.noreply.github.com> | 2020-02-17 10:16:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-17 10:16:52 +0100 |
commit | 45f1bd72a08998c60a9dd68ff069cea9de39161c (patch) | |
tree | 79e484bd7fd38fe97c84fdb00a164534f43941e9 /client/src/app | |
parent | c5621bd23bce038671cd81149a0aa5e238558b67 (diff) | |
download | PeerTube-45f1bd72a08998c60a9dd68ff069cea9de39161c.tar.gz PeerTube-45f1bd72a08998c60a9dd68ff069cea9de39161c.tar.zst PeerTube-45f1bd72a08998c60a9dd68ff069cea9de39161c.zip |
Creating a user with an empty password will send an email to let him set his password (#2479)
* Creating a user with an empty password will send an email to let him set his password
* Consideration of Chocobozzz's comments
* Tips for optional password
* API documentation
* Fix circular imports
* Tests
Diffstat (limited to 'client/src/app')
5 files changed, 35 insertions, 2 deletions
diff --git a/client/src/app/+admin/users/user-edit/user-create.component.ts b/client/src/app/+admin/users/user-edit/user-create.component.ts index e726ec4d7..1769c0de0 100644 --- a/client/src/app/+admin/users/user-edit/user-create.component.ts +++ b/client/src/app/+admin/users/user-edit/user-create.component.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { Component, OnInit } from '@angular/core' | 1 | import { Component, OnInit } from '@angular/core' |
2 | import { Router } from '@angular/router' | 2 | import { Router, ActivatedRoute } from '@angular/router' |
3 | import { AuthService, Notifier, ServerService } from '@app/core' | 3 | import { AuthService, Notifier, ServerService } from '@app/core' |
4 | import { UserCreate, UserRole } from '../../../../../../shared' | 4 | import { UserCreate, UserRole } from '../../../../../../shared' |
5 | import { UserEdit } from './user-edit' | 5 | import { UserEdit } from './user-edit' |
@@ -23,6 +23,7 @@ export class UserCreateComponent extends UserEdit implements OnInit { | |||
23 | protected configService: ConfigService, | 23 | protected configService: ConfigService, |
24 | protected auth: AuthService, | 24 | protected auth: AuthService, |
25 | private userValidatorsService: UserValidatorsService, | 25 | private userValidatorsService: UserValidatorsService, |
26 | private route: ActivatedRoute, | ||
26 | private router: Router, | 27 | private router: Router, |
27 | private notifier: Notifier, | 28 | private notifier: Notifier, |
28 | private userService: UserService, | 29 | private userService: UserService, |
@@ -45,7 +46,7 @@ export class UserCreateComponent extends UserEdit implements OnInit { | |||
45 | this.buildForm({ | 46 | this.buildForm({ |
46 | username: this.userValidatorsService.USER_USERNAME, | 47 | username: this.userValidatorsService.USER_USERNAME, |
47 | email: this.userValidatorsService.USER_EMAIL, | 48 | email: this.userValidatorsService.USER_EMAIL, |
48 | password: this.userValidatorsService.USER_PASSWORD, | 49 | password: this.isPasswordOptional() ? this.userValidatorsService.USER_PASSWORD_OPTIONAL : this.userValidatorsService.USER_PASSWORD, |
49 | role: this.userValidatorsService.USER_ROLE, | 50 | role: this.userValidatorsService.USER_ROLE, |
50 | videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA, | 51 | videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA, |
51 | videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY, | 52 | videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY, |
@@ -78,6 +79,11 @@ export class UserCreateComponent extends UserEdit implements OnInit { | |||
78 | return true | 79 | return true |
79 | } | 80 | } |
80 | 81 | ||
82 | isPasswordOptional () { | ||
83 | const serverConfig = this.route.snapshot.data.serverConfig | ||
84 | return serverConfig.email.enabled | ||
85 | } | ||
86 | |||
81 | getFormButtonTitle () { | 87 | getFormButtonTitle () { |
82 | return this.i18n('Create user') | 88 | return this.i18n('Create user') |
83 | } | 89 | } |
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 4ff4d0d12..2aca5ddca 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 | |||
@@ -29,6 +29,13 @@ | |||
29 | 29 | ||
30 | <div class="form-group" *ngIf="isCreation()"> | 30 | <div class="form-group" *ngIf="isCreation()"> |
31 | <label i18n for="password">Password</label> | 31 | <label i18n for="password">Password</label> |
32 | <my-help *ngIf="isPasswordOptional()"> | ||
33 | <ng-template ptTemplate="customHtml"> | ||
34 | <ng-container i18n> | ||
35 | If you leave the password empty, an email will be sent to the user. | ||
36 | </ng-container> | ||
37 | </ng-template> | ||
38 | </my-help> | ||
32 | <input | 39 | <input |
33 | type="password" id="password" autocomplete="new-password" | 40 | type="password" id="password" autocomplete="new-password" |
34 | formControlName="password" [ngClass]="{ 'input-error': formErrors['password'] }" | 41 | formControlName="password" [ngClass]="{ 'input-error': formErrors['password'] }" |
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 d1682a99d..1ab2e9dbf 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 | |||
@@ -92,6 +92,10 @@ export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy { | |||
92 | return false | 92 | return false |
93 | } | 93 | } |
94 | 94 | ||
95 | isPasswordOptional () { | ||
96 | return false | ||
97 | } | ||
98 | |||
95 | getFormButtonTitle () { | 99 | getFormButtonTitle () { |
96 | return this.i18n('Update user') | 100 | return this.i18n('Update user') |
97 | } | 101 | } |
diff --git a/client/src/app/+admin/users/users.routes.ts b/client/src/app/+admin/users/users.routes.ts index 8b3791bd3..2d4f9305e 100644 --- a/client/src/app/+admin/users/users.routes.ts +++ b/client/src/app/+admin/users/users.routes.ts | |||
@@ -5,6 +5,7 @@ import { UserRight } from '../../../../../shared' | |||
5 | import { UsersComponent } from './users.component' | 5 | import { UsersComponent } from './users.component' |
6 | import { UserCreateComponent, UserUpdateComponent } from './user-edit' | 6 | import { UserCreateComponent, UserUpdateComponent } from './user-edit' |
7 | import { UserListComponent } from './user-list' | 7 | import { UserListComponent } from './user-list' |
8 | import { ServerConfigResolver } from '@app/core/routing/server-config-resolver.service' | ||
8 | 9 | ||
9 | export const UsersRoutes: Routes = [ | 10 | export const UsersRoutes: Routes = [ |
10 | { | 11 | { |
@@ -36,6 +37,9 @@ export const UsersRoutes: Routes = [ | |||
36 | meta: { | 37 | meta: { |
37 | title: 'Create a user' | 38 | title: 'Create a user' |
38 | } | 39 | } |
40 | }, | ||
41 | resolve: { | ||
42 | serverConfig: ServerConfigResolver | ||
39 | } | 43 | } |
40 | }, | 44 | }, |
41 | { | 45 | { |
diff --git a/client/src/app/shared/forms/form-validators/user-validators.service.ts b/client/src/app/shared/forms/form-validators/user-validators.service.ts index 4dff3e422..13b9228d4 100644 --- a/client/src/app/shared/forms/form-validators/user-validators.service.ts +++ b/client/src/app/shared/forms/form-validators/user-validators.service.ts | |||
@@ -8,6 +8,7 @@ export class UserValidatorsService { | |||
8 | readonly USER_USERNAME: BuildFormValidator | 8 | readonly USER_USERNAME: BuildFormValidator |
9 | readonly USER_EMAIL: BuildFormValidator | 9 | readonly USER_EMAIL: BuildFormValidator |
10 | readonly USER_PASSWORD: BuildFormValidator | 10 | readonly USER_PASSWORD: BuildFormValidator |
11 | readonly USER_PASSWORD_OPTIONAL: BuildFormValidator | ||
11 | readonly USER_CONFIRM_PASSWORD: BuildFormValidator | 12 | readonly USER_CONFIRM_PASSWORD: BuildFormValidator |
12 | readonly USER_VIDEO_QUOTA: BuildFormValidator | 13 | readonly USER_VIDEO_QUOTA: BuildFormValidator |
13 | readonly USER_VIDEO_QUOTA_DAILY: BuildFormValidator | 14 | readonly USER_VIDEO_QUOTA_DAILY: BuildFormValidator |
@@ -56,6 +57,17 @@ export class UserValidatorsService { | |||
56 | } | 57 | } |
57 | } | 58 | } |
58 | 59 | ||
60 | this.USER_PASSWORD_OPTIONAL = { | ||
61 | VALIDATORS: [ | ||
62 | Validators.minLength(6), | ||
63 | Validators.maxLength(255) | ||
64 | ], | ||
65 | MESSAGES: { | ||
66 | 'minlength': this.i18n('Password must be at least 6 characters long.'), | ||
67 | 'maxlength': this.i18n('Password cannot be more than 255 characters long.') | ||
68 | } | ||
69 | } | ||
70 | |||
59 | this.USER_CONFIRM_PASSWORD = { | 71 | this.USER_CONFIRM_PASSWORD = { |
60 | VALIDATORS: [], | 72 | VALIDATORS: [], |
61 | MESSAGES: { | 73 | MESSAGES: { |