]>
Commit | Line | Data |
---|---|---|
4d4e5cd4 | 1 | import * as validator from 'validator' |
fdbda9e3 | 2 | import 'express-validator' |
e4c55619 | 3 | |
69818c93 | 4 | import { exists } from './misc' |
954605a8 | 5 | import { CONSTRAINTS_FIELDS } from '../../initializers' |
ee9e7b61 C |
6 | import { UserRole } from '../../../shared' |
7 | ||
65fcc311 | 8 | const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS |
e4c55619 | 9 | |
69818c93 | 10 | function isUserPasswordValid (value: string) { |
9bd26629 C |
11 | return validator.isLength(value, USERS_CONSTRAINTS_FIELDS.PASSWORD) |
12 | } | |
13 | ||
b0f9f39e C |
14 | function isUserVideoQuotaValid (value: string) { |
15 | return exists(value) && validator.isInt(value + '', USERS_CONSTRAINTS_FIELDS.VIDEO_QUOTA) | |
16 | } | |
17 | ||
69818c93 | 18 | function isUserUsernameValid (value: string) { |
9bd26629 C |
19 | const max = USERS_CONSTRAINTS_FIELDS.USERNAME.max |
20 | const min = USERS_CONSTRAINTS_FIELDS.USERNAME.min | |
563d032e | 21 | return exists(value) && validator.matches(value, new RegExp(`^[a-z0-9._]{${min},${max}}$`)) |
e4c55619 C |
22 | } |
23 | ||
7efe153b | 24 | function isBoolean (value: any) { |
69818c93 | 25 | return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value)) |
1d49e1e2 C |
26 | } |
27 | ||
7efe153b AL |
28 | function isUserDisplayNSFWValid (value: any) { |
29 | return isBoolean(value) | |
30 | } | |
31 | ||
32 | function isUserAutoPlayVideoValid (value: any) { | |
33 | return isBoolean(value) | |
34 | } | |
35 | ||
954605a8 C |
36 | function isUserRoleValid (value: any) { |
37 | return exists(value) && validator.isInt('' + value) && UserRole[value] !== undefined | |
38 | } | |
39 | ||
e4c55619 C |
40 | // --------------------------------------------------------------------------- |
41 | ||
65fcc311 C |
42 | export { |
43 | isUserPasswordValid, | |
44 | isUserRoleValid, | |
b0f9f39e | 45 | isUserVideoQuotaValid, |
65fcc311 | 46 | isUserUsernameValid, |
7efe153b AL |
47 | isUserDisplayNSFWValid, |
48 | isUserAutoPlayVideoValid | |
65fcc311 | 49 | } |