Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (typeof password !== 'string') {
console.error(
'validateConfirmPassword: password must be a string. received:',
typeof password
)
return { confirmPassword: 'confirmPassword validation failed' }
}
if (typeof confirmPassword !== 'string') {
console.error(
'validateConfirmPassword: confirmPassword must be a string. received:',
typeof confirmPassword
)
return { confirmPassword: 'confirmPassword validation failed' }
}
// confirmPassword shouldn't be empty
if (Validator.isEmpty(confirmPassword)) {
return { confirmPassword: 'Please confirm your password' }
}
// password and confirmPassword should match
if (!Validator.equals(password, confirmPassword)) {
return { confirmPassword: "Passwords don't match, try again" }
}
return { confirmPassword: '' }
}
module.exports.validate = (validationError, checkEndDateData) => {
const currentYear = moment.utc().format('YYYY')
// Check end day
const isCheckEndDayEmpty = isEmpty(checkEndDateData.checkEndDay.trim())
if (isCheckEndDayEmpty) {
validationError.addError('checkEndDay', checkWindowErrorMessages.checkEndDayRequired)
}
if (!isCheckEndDayEmpty && !isInt(checkEndDateData.checkEndDay, { min: 1, max: 31 })) {
validationError.addError('checkEndDay', checkWindowErrorMessages.checkEndDayWrongDay)
}
if (!isCheckEndDayEmpty && !XRegExp('^[0-9]+$').test(checkEndDateData.checkEndDay)) {
validationError.addError('checkEndDay', checkWindowErrorMessages.checkEndDayInvalidChars)
}
// Check end month
const isCheckEndMonthEmpty = isEmpty(checkEndDateData.checkEndMonth.trim())
if (isCheckEndMonthEmpty) {
validationError.addError('checkEndMonth', checkWindowErrorMessages.checkEndMonthRequired)
}
if (!isCheckEndMonthEmpty && !isInt(checkEndDateData.checkEndMonth, { min: 1, max: 12 })) {
validationError.addError('checkEndMonth', checkWindowErrorMessages.checkEndMonthWrongDay)
}
if (!isCheckEndMonthEmpty && !XRegExp('^[0-9]+$').test(checkEndDateData.checkEndMonth)) {
validationError.addError('checkEndMonth', checkWindowErrorMessages.checkEndMonthInvalidChars)
}
// Check end year
const isCheckEndYearEmpty = isEmpty(checkEndDateData.checkEndYear.trim())
if (isCheckEndYearEmpty) {
validationError.addError('checkEndYear', checkWindowErrorMessages.checkEndYearRequired)
}
if (!isCheckEndYearEmpty && !isInt(checkEndDateData.checkEndYear, { min: currentYear, max: (currentYear * 1 + 10) })) {
validationError.addError('checkEndYear', checkWindowErrorMessages.checkEndYearWrongDay)
if (!uploadedFile || !uploadedFile.file) {
validationError.addError(element, fileErrorMessages.noFile)
return validationError
}
if (uploadedFile.file.split('.').pop() !== 'csv') {
validationError.addError(element, fileErrorMessages.noCSVFile)
return validationError
}
// File not readable
let fileContent, unreadable
try {
fileContent = await fs.readFileSync(uploadedFile.file, 'utf8')
} catch (err) {
unreadable = true
}
if (isEmpty(fileContent) || unreadable) {
validationError.addError(element, fileErrorMessages.isNotReadable)
}
return validationError
}
data.jobSkills = validText(data.jobSkills) ? data.jobSkills : '';
data.type = validText(data.type) ? data.type : '';
// data.remote = validText(data.remote) ? data.remote : '';
data.benefits = validText(data.benefits) ? data.benefits : '';
data.startingPay = validText(data.startingPay) ? data.startingPay : '';
if (Validator.isEmpty(data.companyName)) {
errors.companyName = "Company name is required";
}
if (Validator.isEmpty(data.description)) {
errors.description = "Description is required";
}
if (Validator.isEmpty(data.type)) {
errors.type = "Job type is required";
}
if (Validator.isEmpty(data.jobTitle)) {
errors.jobTitle = "Job title is required";
}
if (Validator.isEmpty(data.jobField)) {
errors.jobField = "Job Field is required";
}
if (Validator.isEmpty(data.jobSkills)) {
errors.jobSkills = "Job Skills is required";
}
// if (Validator.isEmpty(data.remote)) {
// errors.remote = "Job must be full-time, part-time or freelance";
// }
if (Validator.isEmpty(data.benefits)) {
errors.benefits = "Job benefits is required";
}
if (Validator.isEmpty(data.startingPay)) {
errors.startingPay = "Job starting pay is required";
validatePassword (value, status) {
let err = this.state.Errors
if (!validator.isLength(value, { min: 6, max: 64 }) && !validator.isEmpty(value)) {
err.indexOf('PasswordError') === -1 ? err.push('PasswordError') : ''
this.setState({PasswordError: 'The Password must be more than 6 and less than 64 characters long', Errors: err})
} else {
err.indexOf('PasswordError') !== -1 ? err.splice(err.indexOf('PasswordError'), 1) : ''
this.setState({PasswordError: '', Errors: err})
if (validator.isEmpty(value) && status) {
err.indexOf('PasswordError') === -1 ? err.push('PasswordError') : ''
this.setState({PasswordError: 'The password is required and cannot be empty', Errors: err})
}
}
}
const notEmpty = string => !validator.isEmpty(string);
module.exports = function validateProfileInput(data) {
let errors = {};
data.handle = !isEmpty(data.handle) ? data.handle : '';
data.college = !isEmpty(data.college) ? data.college : '';
if (!Validator.isEmpty(data.handle)) {
errors.handle = 'handle field is required';
}
if (Validator.isEmpty(data.status)) {
errors.status = 'status is Invalid';
}
if (Validator.isEmpty(data.status)) {
errors.status = 'status is Required';
}
return {
errors,
isValid: isEmpty(errors),
};
};
module.exports = function validateLoginInput(data) {
let errors = {};
data.email = validText(data.email) ? data.email : '';
data.password = validText(data.password) ? data.password : '';
if (!Validator.isEmail(data.email)) {
errors.email = 'Email is invalid';
}
if (Validator.isEmpty(data.email)) {
errors.email = 'Email field is required';
}
if (Validator.isEmpty(data.password)) {
errors.password = 'Password field is required';
}
return {
errors,
isValid: Object.keys(errors).length === 0
};
};
module.exports = function validateRegisterInput(data) {
let error = {};
data.email = !isempty(data.email) ? data.email : '';
data.password = !isempty(data.pass) ? data.pass : '';
if (!Validator.isEmail(data.email)) {
error.email = 'Invalid email';
}
if (Validator.isEmpty(data.email)) {
error.email = 'email is required';
}
if (Validator.isEmpty(data.password)) {
error.password = 'password is required';
}
return {
error,
isValid: isempty(error)
};
};
function validatePassword(password) {
return !validator.isEmpty(password) && validator.isAscii(password) && validator.isLength(password, {min: 8, max: 64});
}