fix error in validation and undefined email value

This commit is contained in:
GotPPay
2018-01-19 20:15:27 +01:00
parent 00272ec67d
commit 434d45248c
2 changed files with 7 additions and 5 deletions

View File

@@ -9,6 +9,7 @@ module.exports = {
//dot = . //dot = .
//TODO: This list should be longer //TODO: This list should be longer
let transformedEmail = email let transformedEmail = email
.replace (/\s/g, '') //remove all spaces
.replace (/at/gi, '@') .replace (/at/gi, '@')
.replace (/underscore/gi, '_') .replace (/underscore/gi, '_')
.replace (/dash/gi, '-') .replace (/dash/gi, '-')
@@ -17,10 +18,11 @@ module.exports = {
return transformedEmail; return transformedEmail;
}, },
isEmailValid : function(email){ isEmailValid: function (email) {
let validEmailRegex = /^(([^<>()\[\]\\.,;:\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,}))$/; console.log ('Email to validate : ' + email);
let validEmailRegex = /^(([^<>()\[\]\\.,;:\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,}))$/;
return validEmailRegex.test(email); return validEmailRegex.test (email);
}, },
sendEmal: function (name, fromEmail, message, toEmail) { sendEmal: function (name, fromEmail, message, toEmail) {
@@ -59,7 +61,7 @@ module.exports = {
to: toEmail, to: toEmail,
subject: 'Message from Saburly service', subject: 'Message from Saburly service',
text: messageBody, text: messageBody,
html: messageBodyHTML html: messageBodyHTML,
}; };
transporter.sendMail (mailOptions, (error, info) => { transporter.sendMail (mailOptions, (error, info) => {

View File

@@ -88,7 +88,7 @@ module.exports = {
repromptSpeech repromptSpeech
); );
} else if (!intent.slots.Message.value) { } else if (!intent.slots.Message.value) {
intent.slots.Email.value = emailHelper.transformEmailFromAlexaResponse(intent.slots.Message.value); intent.slots.Email.value = emailHelper.transformEmailFromAlexaResponse(intent.slots.Email.value);
if ( if (
!emailHelper.isEmailValid ( !emailHelper.isEmailValid (
intent.slots.Email.value intent.slots.Email.value