2017-05-15 22:22:03 +02:00
|
|
|
import { values } from 'lodash'
|
2017-06-05 21:53:49 +02:00
|
|
|
import * as validator from 'validator'
|
2016-07-31 20:58:43 +02:00
|
|
|
|
2017-05-15 22:22:03 +02:00
|
|
|
import { CONSTRAINTS_FIELDS, USER_ROLES } from '../../initializers'
|
|
|
|
const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS
|
2016-07-31 20:58:43 +02:00
|
|
|
|
2016-08-04 22:32:36 +02:00
|
|
|
function isUserPasswordValid (value) {
|
|
|
|
return validator.isLength(value, USERS_CONSTRAINTS_FIELDS.PASSWORD)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isUserRoleValid (value) {
|
2017-05-15 22:22:03 +02:00
|
|
|
return values(USER_ROLES).indexOf(value) !== -1
|
2016-08-04 22:32:36 +02:00
|
|
|
}
|
|
|
|
|
2016-07-31 20:58:43 +02:00
|
|
|
function isUserUsernameValid (value) {
|
2016-08-04 22:32:36 +02:00
|
|
|
const max = USERS_CONSTRAINTS_FIELDS.USERNAME.max
|
|
|
|
const min = USERS_CONSTRAINTS_FIELDS.USERNAME.min
|
|
|
|
return validator.matches(value, new RegExp(`^[a-zA-Z0-9._]{${min},${max}}$`))
|
2016-07-31 20:58:43 +02:00
|
|
|
}
|
|
|
|
|
2017-04-03 21:24:36 +02:00
|
|
|
function isUserDisplayNSFWValid (value) {
|
|
|
|
return validator.isBoolean(value)
|
|
|
|
}
|
|
|
|
|
2016-07-31 20:58:43 +02:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-05-15 22:22:03 +02:00
|
|
|
export {
|
|
|
|
isUserPasswordValid,
|
|
|
|
isUserRoleValid,
|
|
|
|
isUserUsernameValid,
|
|
|
|
isUserDisplayNSFWValid
|
|
|
|
}
|