added username validation to setup script
This commit is contained in:
parent
e27f27f7f0
commit
c97f207699
@ -98,6 +98,7 @@ var constants = module.exports = {
|
|||||||
userRoleTypes: ['user', 'admin', 'superuser'],
|
userRoleTypes: ['user', 'admin', 'superuser'],
|
||||||
|
|
||||||
regex: {
|
regex: {
|
||||||
|
username: /^[a-zA-Z0-9\-]+$/,
|
||||||
url: /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/,
|
url: /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/,
|
||||||
hexCode: /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,
|
hexCode: /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,
|
||||||
email: /^(([^<>()\[\]\\.,;:\s@']+(\.[^<>()\[\]\\.,;:\s@']+)*)|('.+'))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
|
email: /^(([^<>()\[\]\\.,;:\s@']+(\.[^<>()\[\]\\.,;:\s@']+)*)|('.+'))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
|
||||||
|
|||||||
@ -38,7 +38,7 @@ var UserSchema = new Schema({
|
|||||||
type: String,
|
type: String,
|
||||||
unique: true,
|
unique: true,
|
||||||
lowercase: true,
|
lowercase: true,
|
||||||
match: [/^[a-zA-Z0-9\-]+$/, 'Username can only contain alphanumeric characters and \'-\''],
|
match: [constants.regex.username, 'Username can only contain alphanumeric characters and \'-\''],
|
||||||
required: [true, 'Username is required']
|
required: [true, 'Username is required']
|
||||||
},
|
},
|
||||||
passwordHash: {
|
passwordHash: {
|
||||||
|
|||||||
@ -1,15 +1,20 @@
|
|||||||
var constants = require('../app/libs/constants');
|
var constants = require('../app/libs/constants');
|
||||||
|
|
||||||
var validateEmail = function(value) {
|
var createRegexValidator = function(regex){
|
||||||
var isValidEmail = new RegExp(constants.regex.email, 'g').test(value);
|
return function(value) {
|
||||||
|
var isValid = new RegExp(regex, 'g').test(value);
|
||||||
|
|
||||||
if(!isValidEmail){
|
if(!isValid){
|
||||||
return 'Please enter a valid email'
|
return 'Please enter a valid email'
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var validateEmail = createRegexValidator(constants.regex.email);
|
||||||
|
var validateUsername = createRegexValidator(constants.regex.username);
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
replaceENVQuestion: {
|
replaceENVQuestion: {
|
||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
@ -181,7 +186,8 @@ module.exports = {
|
|||||||
{
|
{
|
||||||
type: 'input',
|
type: 'input',
|
||||||
name: 'username',
|
name: 'username',
|
||||||
message: 'What should be the username for your admin account?'
|
message: 'What should be the username for your admin account?',
|
||||||
|
validate: validateUsername
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'password',
|
type: 'password',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user