mirror of https://github.com/Chocobozzz/PeerTube
Usernames are case insensitive now
parent
f735448395
commit
563d032e97
|
@ -1,11 +1,17 @@
|
||||||
import { Validators } from '@angular/forms'
|
import { Validators } from '@angular/forms'
|
||||||
|
|
||||||
export const USER_USERNAME = {
|
export const USER_USERNAME = {
|
||||||
VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(20) ],
|
VALIDATORS: [
|
||||||
|
Validators.required,
|
||||||
|
Validators.minLength(3),
|
||||||
|
Validators.maxLength(20),
|
||||||
|
Validators.pattern(/^[a-z0-9._]+$/)
|
||||||
|
],
|
||||||
MESSAGES: {
|
MESSAGES: {
|
||||||
'required': 'Username is required.',
|
'required': 'Username is required.',
|
||||||
'minlength': 'Username must be at least 3 characters long.',
|
'minlength': 'Username must be at least 3 characters long.',
|
||||||
'maxlength': 'Username cannot be more than 20 characters long.'
|
'maxlength': 'Username cannot be more than 20 characters long.',
|
||||||
|
'pattern': 'Username should be only lowercase alphanumeric characters.'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export const USER_EMAIL = {
|
export const USER_EMAIL = {
|
||||||
|
|
|
@ -18,7 +18,7 @@ function isUserVideoQuotaValid (value: string) {
|
||||||
function isUserUsernameValid (value: string) {
|
function isUserUsernameValid (value: string) {
|
||||||
const max = USERS_CONSTRAINTS_FIELDS.USERNAME.max
|
const max = USERS_CONSTRAINTS_FIELDS.USERNAME.max
|
||||||
const min = USERS_CONSTRAINTS_FIELDS.USERNAME.min
|
const min = USERS_CONSTRAINTS_FIELDS.USERNAME.min
|
||||||
return exists(value) && validator.matches(value, new RegExp(`^[a-zA-Z0-9._]{${min},${max}}$`))
|
return exists(value) && validator.matches(value, new RegExp(`^[a-z0-9._]{${min},${max}}$`))
|
||||||
}
|
}
|
||||||
|
|
||||||
function isUserDisplayNSFWValid (value: any) {
|
function isUserDisplayNSFWValid (value: any) {
|
||||||
|
|
|
@ -19,7 +19,7 @@ import {
|
||||||
import { UserInstance, VideoInstance } from '../../models'
|
import { UserInstance, VideoInstance } from '../../models'
|
||||||
|
|
||||||
const usersAddValidator = [
|
const usersAddValidator = [
|
||||||
body('username').custom(isUserUsernameValid).withMessage('Should have a valid username'),
|
body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'),
|
||||||
body('password').custom(isUserPasswordValid).withMessage('Should have a valid password'),
|
body('password').custom(isUserPasswordValid).withMessage('Should have a valid password'),
|
||||||
body('email').isEmail().withMessage('Should have a valid email'),
|
body('email').isEmail().withMessage('Should have a valid email'),
|
||||||
body('videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'),
|
body('videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'),
|
||||||
|
@ -196,7 +196,7 @@ function checkUserDoesNotAlreadyExist (username: string, email: string, res: exp
|
||||||
.then(user => {
|
.then(user => {
|
||||||
if (user) {
|
if (user) {
|
||||||
return res.status(409)
|
return res.status(409)
|
||||||
.send({ error: 'User already exists.' })
|
.send({ error: 'User with this username of email already exists.' })
|
||||||
.end()
|
.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,18 @@ describe('Test users API validators', function () {
|
||||||
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
|
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Should fail with a not lowercase username', async function () {
|
||||||
|
const fields = {
|
||||||
|
username: 'Toto',
|
||||||
|
email: 'test@example.com',
|
||||||
|
password: 'my_super_password',
|
||||||
|
videoQuota: 42000000,
|
||||||
|
role: UserRole.USER
|
||||||
|
}
|
||||||
|
|
||||||
|
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
|
||||||
|
})
|
||||||
|
|
||||||
it('Should fail with an incorrect username', async function () {
|
it('Should fail with an incorrect username', async function () {
|
||||||
const fields = {
|
const fields = {
|
||||||
username: 'my username',
|
username: 'my username',
|
||||||
|
|
Loading…
Reference in New Issue