From a0f2b044b22635a29ca333826e6db182a3ef68a7 Mon Sep 17 00:00:00 2001 From: Nedim Uka Date: Wed, 29 May 2019 17:04:16 +0200 Subject: [PATCH] Added validation to email confirmation --- app/controllers/querySubmit.js | 30 ++++++++++++++----- app/views/querySubmit.ejs | 55 ++++++++++++++++++++++++---------- 2 files changed, 63 insertions(+), 22 deletions(-) diff --git a/app/controllers/querySubmit.js b/app/controllers/querySubmit.js index 4ed6863..05f53bd 100644 --- a/app/controllers/querySubmit.js +++ b/app/controllers/querySubmit.js @@ -1,7 +1,7 @@ const { currentRERequest } = require('../helpers/url'); const { isValidEmail } = require('../helpers/email'); -const getQuerySubmit = async (req,res) => { +const getQuerySubmit = async (req, res) => { const nextStep = req.query.nextStep; const error = req.query.error; @@ -16,14 +16,30 @@ const postQuerySubmit = async (req, res) => { const nextStep = req.query.nextStep || '/ponovo'; const emailInput = req.body.email; + const emailConfirmInput = req.body.confirm; + let error = "Greška ! Unesite validan email"; - if (isValidEmail(emailInput)){ - request.email = req.body.email; - await request.save(); - res.redirect(nextStep); - } else { - res.redirect('?error=1'); + if (!isValidEmail(emailInput) || !isValidEmail(emailInput)) { + + error = "Greška ! Unesite validan email"; + res.render('querySubmit', { + error + }); + return; } + + if (emailInput !== emailConfirmInput) { + + error = "Greška ! Unešeni emailovi nisu isti"; + res.render('querySubmit', { + error + }); + return; + } + + request.email = req.body.email; + await request.save(); + res.redirect(nextStep); }; module.exports = { diff --git a/app/views/querySubmit.ejs b/app/views/querySubmit.ejs index 5612ce4..ded8ac6 100644 --- a/app/views/querySubmit.ejs +++ b/app/views/querySubmit.ejs @@ -9,13 +9,25 @@ - <% if (error) {%> -
-
-
Greška ! Unesite ispravan email
-
+ +
+
+
<%= error %>
- <%}%> +
+ +
+
+ +
+
+ +
+
+
+
+
+