// Validates a stream key function validateStreamKey(streamKey) { return !validator.isEmpty(streamKey) && validator.isHexadecimal(streamKey) && validator.isLength(streamKey, {min: 64, max: 64}); }
validate(value){ if(validator.isEmpty(value)){ throw new Error('Please enter your password!') }else if(validator.equals(value.toLowerCase(),"password")){ throw new Error('Password is invalid!') }else if(validator.contains(value.toLowerCase(), "password")){ throw new Error('Password should not contain password!') } }
// Sign in using email and password. export function signin(req, res, next) { const reqEmail = req.body.email; const reqPassword = req.body.password; return chain .then(() => { if (!validator.isEmail(reqEmail)) { throw new ApiError('Invalid email'); } if (validator.isEmpty(reqPassword)) { throw new ApiError('Password cannot be empty'); } }) .then(() => new Promise((resolve, reject) => { passport.authenticate('local-signin', (error, user, info) => { if (error) return reject(new Error(error)); if (!user) return reject(new ApiError(info)); return req.logIn(user, (loginError) => { if (loginError) return reject(new Error(loginError)); return resolve(); }); })(req, res, next); })); }
/** * Given an existing userId and chatId, save a new message with the given string * content. */ export function createMessage(userId, chatId, values) { const sanitizedContent = validator.trim(values.content); if (validator.isEmpty(values.content)) { throw 'Message cannot be empty.'; } const newMessage = new Message(); newMessage.owner = userId; newMessage.chat = chatId; newMessage.content = sanitizedContent; newMessage.type = values.type; newMessage.specifics = values.specifics; return newMessage.save(); }
const validateLoginInput = (data) => { let errors = {}; data.email = !isEmpty(data.email) ? data.email : ''; data.password = !isEmpty(data.password) ? data.password : ''; const re=/\S+@\S+\.\S+/; if (!re.test(data.email)) { errors.email = 'Email is invalid'; } if(validator.isEmpty(data.email)) { errors.email='Email is required'; } if (validator.isEmpty(data.password)) { errors.password = 'Password required'; } return {errors, isValid: isEmpty(errors)}; }
// Validates a message function validateMessage(message) { return !validator.isEmpty(message) && validator.isLength(message, {min: 1, max: 512}); }
// Validates a username function validateUsername(username) { return !validator.isEmpty(username) && validator.isAlphanumeric(username) && validator.isLength(username, {min: 4, max: 32}); }
// Validates a password function validatePassword(password) { return !validator.isEmpty(password) && validator.isAscii(password) && validator.isLength(password, {min: 8, max: 64}); }
const notEmpty = string => !validator.isEmpty(string)
// Validates a user ID function validateUid(uid) { return !validator.isEmpty(uid) && validator.isHexadecimal(uid) && validator.isLength(uid, {min: 16, max: 16}); }
const emptyString = string => validator.isEmpty(string)
const emptyString = string => validator.isEmpty(string)