Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const options = {
from: from || env.EMAIL_DEFAULT_FROM,
to: to || env.EMAIL_DEFAULT_TO,
subject: subject || env.EMAIL_DEFAULT_SUBJECT,
html: compiledTemplate.html(dataset),
text: compiledTemplate.text(dataset),
}
if ( env.EMAIL_FROM_VALIDATE_IN ) {
const valid_emails = env.EMAIL_FROM_VALIDATE_IN.split(',')
if ( valid_emails.indexOf(options.from) === -1 ) {
throw { message: 'The provided `from` email is not allowed', code: 401 }
}
}
if ( ! isEmail( options.from ) ) {
throw { message: 'The provided `from` email is not a valid email', code: 401 }
}
if ( env.EMAIL_TO_VALIDATE_IN ) {
const valid_emails = env.EMAIL_TO_VALIDATE_IN.split(',')
if ( valid_emails.indexOf(options.to) === -1 ) {
throw { message: 'The provided `to` email is not allowed', code: 401 }
}
}
if ( ! isEmail( options.to ) ) {
throw { message: 'The provided `to` email is not a valid email', code: 401 }
}
// Prevent email grouping on clients
if (+env.EMAIL_PREVENT_GROUPING) {
throw { message: 'The provided `from` email is not allowed', code: 401 }
}
}
if ( ! isEmail( options.from ) ) {
throw { message: 'The provided `from` email is not a valid email', code: 401 }
}
if ( env.EMAIL_TO_VALIDATE_IN ) {
const valid_emails = env.EMAIL_TO_VALIDATE_IN.split(',')
if ( valid_emails.indexOf(options.to) === -1 ) {
throw { message: 'The provided `to` email is not allowed', code: 401 }
}
}
if ( ! isEmail( options.to ) ) {
throw { message: 'The provided `to` email is not a valid email', code: 401 }
}
// Prevent email grouping on clients
if (+env.EMAIL_PREVENT_GROUPING) {
const id = Date.now().toString(32)
options.subject = `[${id}] ${options.subject}`
options.text = `${options.text}\n\nID: [${id}]`
options.html = `${options.html}\n\n`
}
// check email
await transporter.sendMail(options)
} catch (err) {
return next(err)
}
email: v => {
return isEmail(v) || [{ reason: `not_email` }]
},
},
email: (value: any): boolean | Partial => {
if (isEmail(value)) {
return true
} else {
return { reason: `not_email` }
}
},
},
validateInput() {
const { email, username, password } = this.state;
if (_.isEmpty(email) || _.isEmpty(username) || _.isEmpty(password)) {
Alert.alert(I18n.t('shoutem.application.errorTitle'), errorMessages.EMPTY_FIELDS);
return false;
}
if (!isEmail(email)) {
Alert.alert(I18n.t('shoutem.application.errorTitle'), errorMessages.SIGNUP_EMAIL_INVALID);
return false;
}
if (!password || password.length < 6) {
Alert.alert(I18n.t('shoutem.application.errorTitle'), errorMessages.SIGNUP_PASSWORD_INVALID);
return false;
}
const usernameRegexMatch = username.match(this.usernameRegex);
if (!username || !usernameRegexMatch) {
Alert.alert(I18n.t('shoutem.application.errorTitle'), errorMessages.SIGNUP_USERNAME_INVALID);
return false;
}
return true;
email: v => {
if (!isEmail(v)) return `not_email`
if (v.length >= 256) return 'too_long'
return true
},
url: v => isUrl(v) && v.length < 2048,