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'],
|
||||
|
||||
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]*))?)/,
|
||||
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,}))$/,
|
||||
|
||||
@ -38,7 +38,7 @@ var UserSchema = new Schema({
|
||||
type: String,
|
||||
unique: 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']
|
||||
},
|
||||
passwordHash: {
|
||||
|
||||
@ -1,15 +1,20 @@
|
||||
var constants = require('../app/libs/constants');
|
||||
|
||||
var validateEmail = function(value) {
|
||||
var isValidEmail = new RegExp(constants.regex.email, 'g').test(value);
|
||||
var createRegexValidator = function(regex){
|
||||
return function(value) {
|
||||
var isValid = new RegExp(regex, 'g').test(value);
|
||||
|
||||
if(!isValidEmail){
|
||||
return 'Please enter a valid email'
|
||||
} else {
|
||||
return true;
|
||||
if(!isValid){
|
||||
return 'Please enter a valid email'
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var validateEmail = createRegexValidator(constants.regex.email);
|
||||
var validateUsername = createRegexValidator(constants.regex.username);
|
||||
|
||||
module.exports = {
|
||||
replaceENVQuestion: {
|
||||
type: 'confirm',
|
||||
@ -181,7 +186,8 @@ module.exports = {
|
||||
{
|
||||
type: 'input',
|
||||
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',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user