diff options
author | BRAINS YUM <43896676+McFlat@users.noreply.github.com> | 2018-12-07 07:54:33 -0600 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-12-07 14:54:33 +0100 |
commit | d0ce42c1c17054b7e0c5081243152c32ecb1c193 (patch) | |
tree | b68c434203b2cd43f8b739e9d540b174faebb27e | |
parent | f3e4d594080e2ae727da07e9d3febf5b6ce5cb75 (diff) | |
download | PeerTube-d0ce42c1c17054b7e0c5081243152c32ecb1c193.tar.gz PeerTube-d0ce42c1c17054b7e0c5081243152c32ecb1c193.tar.zst PeerTube-d0ce42c1c17054b7e0c5081243152c32ecb1c193.zip |
username/display_name/video_channel_name min length 1 and max length 50 (#1265)
* make username, display_name and video_channel_name min length 1 and max length 50; (fixes #1263);
! still some bug on the frontend complains but if you remove the disabled property it creates the account just fine;
allow for usernames to start with a number;
fix test, since username can be 1 char now make test check empty;
fix test, Should fail with a too long username;
fix test, Should fail with a too small username;
fix regular expression for username and videoChannel;
change username, videoChannel to be lowercase and fix message;
* change 1 characters to 1 character
4 files changed, 27 insertions, 27 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 d14fa4777..66543657a 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 | |||
@@ -23,15 +23,15 @@ export class UserValidatorsService { | |||
23 | this.USER_USERNAME = { | 23 | this.USER_USERNAME = { |
24 | VALIDATORS: [ | 24 | VALIDATORS: [ |
25 | Validators.required, | 25 | Validators.required, |
26 | Validators.minLength(3), | 26 | Validators.minLength(1), |
27 | Validators.maxLength(20), | 27 | Validators.maxLength(50), |
28 | Validators.pattern(/^[a-z0-9._]+$/) | 28 | Validators.pattern(/^[a-z0-9][a-z0-9-._]*$/) |
29 | ], | 29 | ], |
30 | MESSAGES: { | 30 | MESSAGES: { |
31 | 'required': this.i18n('Username is required.'), | 31 | 'required': this.i18n('Username is required.'), |
32 | 'minlength': this.i18n('Username must be at least 3 characters long.'), | 32 | 'minlength': this.i18n('Username must be at least 1 character long.'), |
33 | 'maxlength': this.i18n('Username cannot be more than 20 characters long.'), | 33 | 'maxlength': this.i18n('Username cannot be more than 50 characters long.'), |
34 | 'pattern': this.i18n('Username should be only lowercase alphanumeric characters.') | 34 | 'pattern': this.i18n('Username should be lowercase alphanumeric; dots, dashes and underscores are allowed.') |
35 | } | 35 | } |
36 | } | 36 | } |
37 | 37 | ||
@@ -88,13 +88,13 @@ export class UserValidatorsService { | |||
88 | this.USER_DISPLAY_NAME = { | 88 | this.USER_DISPLAY_NAME = { |
89 | VALIDATORS: [ | 89 | VALIDATORS: [ |
90 | Validators.required, | 90 | Validators.required, |
91 | Validators.minLength(3), | 91 | Validators.minLength(1), |
92 | Validators.maxLength(120) | 92 | Validators.maxLength(50) |
93 | ], | 93 | ], |
94 | MESSAGES: { | 94 | MESSAGES: { |
95 | 'required': this.i18n('Display name is required.'), | 95 | 'required': this.i18n('Display name is required.'), |
96 | 'minlength': this.i18n('Display name must be at least 3 characters long.'), | 96 | 'minlength': this.i18n('Display name must be at least 1 character long.'), |
97 | 'maxlength': this.i18n('Display name cannot be more than 120 characters long.') | 97 | 'maxlength': this.i18n('Display name cannot be more than 50 characters long.') |
98 | } | 98 | } |
99 | } | 99 | } |
100 | 100 | ||
diff --git a/client/src/app/shared/forms/form-validators/video-channel-validators.service.ts b/client/src/app/shared/forms/form-validators/video-channel-validators.service.ts index f62ff65f7..7df4f6adf 100644 --- a/client/src/app/shared/forms/form-validators/video-channel-validators.service.ts +++ b/client/src/app/shared/forms/form-validators/video-channel-validators.service.ts | |||
@@ -14,28 +14,28 @@ export class VideoChannelValidatorsService { | |||
14 | this.VIDEO_CHANNEL_NAME = { | 14 | this.VIDEO_CHANNEL_NAME = { |
15 | VALIDATORS: [ | 15 | VALIDATORS: [ |
16 | Validators.required, | 16 | Validators.required, |
17 | Validators.minLength(3), | 17 | Validators.minLength(1), |
18 | Validators.maxLength(20), | 18 | Validators.maxLength(50), |
19 | Validators.pattern(/^[a-z0-9._]+$/) | 19 | Validators.pattern(/^[a-z0-9][a-z0-9-._]*$/) |
20 | ], | 20 | ], |
21 | MESSAGES: { | 21 | MESSAGES: { |
22 | 'required': this.i18n('Name is required.'), | 22 | 'required': this.i18n('Name is required.'), |
23 | 'minlength': this.i18n('Name must be at least 3 characters long.'), | 23 | 'minlength': this.i18n('Name must be at least 1 character long.'), |
24 | 'maxlength': this.i18n('Name cannot be more than 20 characters long.'), | 24 | 'maxlength': this.i18n('Name cannot be more than 50 characters long.'), |
25 | 'pattern': this.i18n('Name should be only lowercase alphanumeric characters.') | 25 | 'pattern': this.i18n('Name should be lowercase alphanumeric; dots, dashes and underscores are allowed.') |
26 | } | 26 | } |
27 | } | 27 | } |
28 | 28 | ||
29 | this.VIDEO_CHANNEL_DISPLAY_NAME = { | 29 | this.VIDEO_CHANNEL_DISPLAY_NAME = { |
30 | VALIDATORS: [ | 30 | VALIDATORS: [ |
31 | Validators.required, | 31 | Validators.required, |
32 | Validators.minLength(3), | 32 | Validators.minLength(1), |
33 | Validators.maxLength(120) | 33 | Validators.maxLength(50) |
34 | ], | 34 | ], |
35 | MESSAGES: { | 35 | MESSAGES: { |
36 | 'required': i18n('Display name is required.'), | 36 | 'required': i18n('Display name is required.'), |
37 | 'minlength': i18n('Display name must be at least 3 characters long.'), | 37 | 'minlength': i18n('Display name must be at least 1 character long.'), |
38 | 'maxlength': i18n('Display name cannot be more than 120 characters long.') | 38 | 'maxlength': i18n('Display name cannot be more than 50 characters long.') |
39 | } | 39 | } |
40 | } | 40 | } |
41 | 41 | ||
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 6b798875c..d4496bc34 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -300,9 +300,9 @@ const CONFIG = { | |||
300 | 300 | ||
301 | const CONSTRAINTS_FIELDS = { | 301 | const CONSTRAINTS_FIELDS = { |
302 | USERS: { | 302 | USERS: { |
303 | NAME: { min: 3, max: 120 }, // Length | 303 | NAME: { min: 1, max: 50 }, // Length |
304 | DESCRIPTION: { min: 3, max: 1000 }, // Length | 304 | DESCRIPTION: { min: 3, max: 1000 }, // Length |
305 | USERNAME: { min: 3, max: 20 }, // Length | 305 | USERNAME: { min: 1, max: 50 }, // Length |
306 | PASSWORD: { min: 6, max: 255 }, // Length | 306 | PASSWORD: { min: 6, max: 255 }, // Length |
307 | VIDEO_QUOTA: { min: -1 }, | 307 | VIDEO_QUOTA: { min: -1 }, |
308 | VIDEO_QUOTA_DAILY: { min: -1 }, | 308 | VIDEO_QUOTA_DAILY: { min: -1 }, |
@@ -316,7 +316,7 @@ const CONSTRAINTS_FIELDS = { | |||
316 | REASON: { min: 2, max: 300 } // Length | 316 | REASON: { min: 2, max: 300 } // Length |
317 | }, | 317 | }, |
318 | VIDEO_CHANNELS: { | 318 | VIDEO_CHANNELS: { |
319 | NAME: { min: 3, max: 120 }, // Length | 319 | NAME: { min: 1, max: 50 }, // Length |
320 | DESCRIPTION: { min: 3, max: 1000 }, // Length | 320 | DESCRIPTION: { min: 3, max: 1000 }, // Length |
321 | SUPPORT: { min: 3, max: 1000 }, // Length | 321 | SUPPORT: { min: 3, max: 1000 }, // Length |
322 | URL: { min: 3, max: 2000 } // Length | 322 | URL: { min: 3, max: 2000 } // Length |
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 273be1679..ee225dc2e 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts | |||
@@ -99,13 +99,13 @@ describe('Test users API validators', function () { | |||
99 | } | 99 | } |
100 | 100 | ||
101 | it('Should fail with a too small username', async function () { | 101 | it('Should fail with a too small username', async function () { |
102 | const fields = immutableAssign(baseCorrectParams, { username: 'fi' }) | 102 | const fields = immutableAssign(baseCorrectParams, { username: '' }) |
103 | 103 | ||
104 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 104 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
105 | }) | 105 | }) |
106 | 106 | ||
107 | it('Should fail with a too long username', async function () { | 107 | it('Should fail with a too long username', async function () { |
108 | const fields = immutableAssign(baseCorrectParams, { username: 'my_super_username_which_is_very_long' }) | 108 | const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(11) }) |
109 | 109 | ||
110 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 110 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
111 | }) | 111 | }) |
@@ -550,13 +550,13 @@ describe('Test users API validators', function () { | |||
550 | } | 550 | } |
551 | 551 | ||
552 | it('Should fail with a too small username', async function () { | 552 | it('Should fail with a too small username', async function () { |
553 | const fields = immutableAssign(baseCorrectParams, { username: 'ji' }) | 553 | const fields = immutableAssign(baseCorrectParams, { username: '' }) |
554 | 554 | ||
555 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | 555 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) |
556 | }) | 556 | }) |
557 | 557 | ||
558 | it('Should fail with a too long username', async function () { | 558 | it('Should fail with a too long username', async function () { |
559 | const fields = immutableAssign(baseCorrectParams, { username: 'my_super_username_which_is_very_long' }) | 559 | const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(11) }) |
560 | 560 | ||
561 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | 561 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) |
562 | }) | 562 | }) |