diff options
author | Chocobozzz <me@florianbigard.com> | 2019-06-07 16:59:53 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-06-07 17:05:42 +0200 |
commit | 1f20622f2b087eaf8738d60fae00a44b9c558ca3 (patch) | |
tree | 1c8554623665ca96b8a1e6f2a6bcb8c1b5a83c2e /client/src/app/shared | |
parent | 1a03bea0c42fa1064ce4770157b4fd2e3edd5565 (diff) | |
download | PeerTube-1f20622f2b087eaf8738d60fae00a44b9c558ca3.tar.gz PeerTube-1f20622f2b087eaf8738d60fae00a44b9c558ca3.tar.zst PeerTube-1f20622f2b087eaf8738d60fae00a44b9c558ca3.zip |
Improve registration
* Add ability to set the user display name
* Use display name to guess the username/channel name
* Add explanations about what is the purpose of a username/channel name
* Add a loader at the "done" step
Diffstat (limited to 'client/src/app/shared')
4 files changed, 44 insertions, 21 deletions
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 6589b2580..2dafb1816 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 | |||
@@ -12,7 +12,7 @@ export class UserValidatorsService { | |||
12 | readonly USER_VIDEO_QUOTA: BuildFormValidator | 12 | readonly USER_VIDEO_QUOTA: BuildFormValidator |
13 | readonly USER_VIDEO_QUOTA_DAILY: BuildFormValidator | 13 | readonly USER_VIDEO_QUOTA_DAILY: BuildFormValidator |
14 | readonly USER_ROLE: BuildFormValidator | 14 | readonly USER_ROLE: BuildFormValidator |
15 | readonly USER_DISPLAY_NAME: BuildFormValidator | 15 | readonly USER_DISPLAY_NAME_REQUIRED: BuildFormValidator |
16 | readonly USER_DESCRIPTION: BuildFormValidator | 16 | readonly USER_DESCRIPTION: BuildFormValidator |
17 | readonly USER_TERMS: BuildFormValidator | 17 | readonly USER_TERMS: BuildFormValidator |
18 | 18 | ||
@@ -85,18 +85,7 @@ export class UserValidatorsService { | |||
85 | } | 85 | } |
86 | } | 86 | } |
87 | 87 | ||
88 | this.USER_DISPLAY_NAME = { | 88 | this.USER_DISPLAY_NAME_REQUIRED = this.getDisplayName(true) |
89 | VALIDATORS: [ | ||
90 | Validators.required, | ||
91 | Validators.minLength(1), | ||
92 | Validators.maxLength(50) | ||
93 | ], | ||
94 | MESSAGES: { | ||
95 | 'required': this.i18n('Display name is required.'), | ||
96 | 'minlength': this.i18n('Display name must be at least 1 character long.'), | ||
97 | 'maxlength': this.i18n('Display name cannot be more than 50 characters long.') | ||
98 | } | ||
99 | } | ||
100 | 89 | ||
101 | this.USER_DESCRIPTION = { | 90 | this.USER_DESCRIPTION = { |
102 | VALIDATORS: [ | 91 | VALIDATORS: [ |
@@ -129,4 +118,22 @@ export class UserValidatorsService { | |||
129 | } | 118 | } |
130 | } | 119 | } |
131 | } | 120 | } |
121 | |||
122 | private getDisplayName (required: boolean) { | ||
123 | const control = { | ||
124 | VALIDATORS: [ | ||
125 | Validators.minLength(1), | ||
126 | Validators.maxLength(120) | ||
127 | ], | ||
128 | MESSAGES: { | ||
129 | 'required': this.i18n('Display name is required.'), | ||
130 | 'minlength': this.i18n('Display name must be at least 1 character long.'), | ||
131 | 'maxlength': this.i18n('Display name cannot be more than 50 characters long.') | ||
132 | } | ||
133 | } | ||
134 | |||
135 | if (required) control.VALIDATORS.push(Validators.required) | ||
136 | |||
137 | return control | ||
138 | } | ||
132 | } | 139 | } |
diff --git a/client/src/app/shared/misc/loader.component.html b/client/src/app/shared/misc/loader.component.html index b8b7ad343..ca8ed063e 100644 --- a/client/src/app/shared/misc/loader.component.html +++ b/client/src/app/shared/misc/loader.component.html | |||
@@ -1,5 +1,5 @@ | |||
1 | <div *ngIf="loading"> | 1 | <div *ngIf="loading"> |
2 | <div class="lds-ring"> | 2 | <div class="loader"> |
3 | <div></div> | 3 | <div></div> |
4 | <div></div> | 4 | <div></div> |
5 | <div></div> | 5 | <div></div> |
diff --git a/client/src/app/shared/misc/loader.component.scss b/client/src/app/shared/misc/loader.component.scss index ddb64f07a..ffac9c707 100644 --- a/client/src/app/shared/misc/loader.component.scss +++ b/client/src/app/shared/misc/loader.component.scss | |||
@@ -3,14 +3,14 @@ | |||
3 | 3 | ||
4 | // Thanks to https://loading.io/css/ (CC0 License) | 4 | // Thanks to https://loading.io/css/ (CC0 License) |
5 | 5 | ||
6 | .lds-ring { | 6 | .loader { |
7 | display: inline-block; | 7 | display: inline-block; |
8 | position: relative; | 8 | position: relative; |
9 | width: 50px; | 9 | width: 50px; |
10 | height: 50px; | 10 | height: 50px; |
11 | } | 11 | } |
12 | 12 | ||
13 | .lds-ring div { | 13 | .loader div { |
14 | box-sizing: border-box; | 14 | box-sizing: border-box; |
15 | display: block; | 15 | display: block; |
16 | position: absolute; | 16 | position: absolute; |
@@ -19,23 +19,23 @@ | |||
19 | margin: 6px; | 19 | margin: 6px; |
20 | border: 4px solid; | 20 | border: 4px solid; |
21 | border-radius: 50%; | 21 | border-radius: 50%; |
22 | animation: lds-ring 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite; | 22 | animation: loader 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite; |
23 | border-color: #999999 transparent transparent transparent; | 23 | border-color: #999999 transparent transparent transparent; |
24 | } | 24 | } |
25 | 25 | ||
26 | .lds-ring div:nth-child(1) { | 26 | .loader div:nth-child(1) { |
27 | animation-delay: -0.45s; | 27 | animation-delay: -0.45s; |
28 | } | 28 | } |
29 | 29 | ||
30 | .lds-ring div:nth-child(2) { | 30 | .loader div:nth-child(2) { |
31 | animation-delay: -0.3s; | 31 | animation-delay: -0.3s; |
32 | } | 32 | } |
33 | 33 | ||
34 | .lds-ring div:nth-child(3) { | 34 | .loader div:nth-child(3) { |
35 | animation-delay: -0.15s; | 35 | animation-delay: -0.15s; |
36 | } | 36 | } |
37 | 37 | ||
38 | @keyframes lds-ring { | 38 | @keyframes loader { |
39 | 0% { | 39 | 0% { |
40 | transform: rotate(0deg); | 40 | transform: rotate(0deg); |
41 | } | 41 | } |
diff --git a/client/src/app/shared/users/user.service.ts b/client/src/app/shared/users/user.service.ts index 20883456f..70ff9a058 100644 --- a/client/src/app/shared/users/user.service.ts +++ b/client/src/app/shared/users/user.service.ts | |||
@@ -136,6 +136,22 @@ export class UserService { | |||
136 | .pipe(catchError(res => this.restExtractor.handleError(res))) | 136 | .pipe(catchError(res => this.restExtractor.handleError(res))) |
137 | } | 137 | } |
138 | 138 | ||
139 | getNewUsername (oldDisplayName: string, newDisplayName: string, currentUsername: string) { | ||
140 | // Don't update display name, the user seems to have changed it | ||
141 | if (this.displayNameToUsername(oldDisplayName) !== currentUsername) return currentUsername | ||
142 | |||
143 | return this.displayNameToUsername(newDisplayName) | ||
144 | } | ||
145 | |||
146 | displayNameToUsername (displayName: string) { | ||
147 | if (!displayName) return '' | ||
148 | |||
149 | return displayName | ||
150 | .toLowerCase() | ||
151 | .replace(/\s/g, '_') | ||
152 | .replace(/[^a-z0-9_.]/g, '') | ||
153 | } | ||
154 | |||
139 | /* ###### Admin methods ###### */ | 155 | /* ###### Admin methods ###### */ |
140 | 156 | ||
141 | addUser (userCreate: UserCreate) { | 157 | addUser (userCreate: UserCreate) { |