improve email regex; improve error handling for query review
This commit is contained in:
@@ -122,9 +122,39 @@ const postQueryReview = async (req, res) => {
|
||||
|
||||
searchRequest.email = emailInput;
|
||||
searchRequest.subscribed = true;
|
||||
await searchRequest.save();
|
||||
|
||||
await notifyForNewSearchRequest(searchRequest);
|
||||
try {
|
||||
await searchRequest.save();
|
||||
} catch (e) {
|
||||
console.log("[ERROR] Failed to save search request !", e);
|
||||
console.log("Search request : ", searchRequest);
|
||||
const error =
|
||||
"Greška ! Nismo uspjeli kreirati zahtjev za Vašu pretragu. Molimo pokuštajte ponovo";
|
||||
res.render("queryReview", {
|
||||
error,
|
||||
title,
|
||||
queryReviewData,
|
||||
email: ""
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await notifyForNewSearchRequest(searchRequest);
|
||||
} catch (e) {
|
||||
console.log("[ERROR] Failed to send initial welcome email", e);
|
||||
console.log("Search request : ", searchRequest);
|
||||
|
||||
const error =
|
||||
"Greška ! Nismo uspjeli poslati email na Vašu adresu, pokušajte sa drugom email adresom";
|
||||
res.render("queryReview", {
|
||||
error,
|
||||
title,
|
||||
queryReviewData,
|
||||
email: ""
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
res.redirect(nextStep);
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const isValidEmail = email => {
|
||||
const simpleEmailRegex = /^.+@.+\..+$/;
|
||||
const simpleEmailRegex = /^(([^<>()\[\]\\.,;:\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 email && email.length < 250 && simpleEmailRegex.test(email);
|
||||
};
|
||||
|
||||
|
||||
@@ -48,7 +48,20 @@
|
||||
<script>
|
||||
$(document).ready( () => {
|
||||
$("#submit").click( () => {
|
||||
$("#form-queryreview").submit();
|
||||
const simpleEmailRegex = /^(([^<>()\[\]\\.,;:\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,}))$/;
|
||||
const email = $("#email").val();
|
||||
const confirmEmail = $("#confirmEmail").val();
|
||||
|
||||
if (email !== confirmEmail){
|
||||
$("#error-label-email").text("Greška ! Unešeni emailovi nisu isti");
|
||||
return;
|
||||
}
|
||||
|
||||
if (simpleEmailRegex.test(email)){
|
||||
$("#form-queryreview").submit();
|
||||
}else{
|
||||
$("#error-label-email").text("Greška ! Unešeni emailovi nisu isti");
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user