Browse Source

Add backend password validation. Add log out button.

Lee Morgan 6 years ago
parent
commit
3bd76a203d

+ 10 - 0
controllers/home.js

@@ -220,6 +220,10 @@ module.exports = {
     createMerchantClover: function(req, res){
         let data = JSON.parse(req.body.data);
 
+        if(data.password.length < 15 || data.password !== data.confirmPassword){
+            return res.render("error");
+        }
+
         axios.get(`https://apisandbox.dev.clover.com/v3/merchants/${req.session.posId}?access_token=${token}`)
             .then((cloverMerchant)=>{
                 req.session.posId = undefined;
@@ -657,5 +661,11 @@ module.exports = {
                 console.log(err);
                 return res.redirect("/");
             });
+    },
+
+    logout: function(req, res){
+        req.session.user = undefined;
+
+        return res.redirect("/");
     }
 }

+ 1 - 0
routes.js

@@ -33,4 +33,5 @@ module.exports = function(app){
     //Other
     app.get("/unregistered", home.unregistered);
     app.post("/login", home.login);
+    app.get("/logout", home.logout);
 }

+ 1 - 0
views/merchantSetupPage/basicInfo.js

@@ -20,6 +20,7 @@ basicInfoObj = {
             controller.data.name = name;
             controller.data.email = email;
             controller.data.password = password;
+            controller.data.confirmPassword = confirmPassword;
 
             addIngredientsObj.display();
         }

+ 1 - 4
views/merchantSetupPage/createRecipes.js

@@ -151,9 +151,7 @@ let createRecipesObj = {
 
     //Add all recipes to data variable
     //Creates a form and submits data
-    submit: function(){
-        console.log("something");
-        
+    submit: function(){        
         let form = document.createElement("form");
         form.method = "post";
         form.action = recipes ? "/merchant/clover/create" : "/merchant/none/create";
@@ -161,7 +159,6 @@ let createRecipesObj = {
         let dataInput = document.createElement("input");
         dataInput.type = "hidden";
         dataInput.name = "data";
-        console.log(controller.data);
         dataInput.value = JSON.stringify(controller.data);
     
         form.appendChild(dataInput);

+ 5 - 1
views/shared/header.ejs

@@ -1,6 +1,10 @@
 <div class="header">
-    <a href="http://www.thesubline.com" >
+    <a class="logo" href="http://www.thesubline.com" >
         <img src="/shared/images/logo.png" alt="Subline">
         <h1>SUBLINE</h1>
     </a>
+    
+    <% if(locals.merchant){ %>
+        <a class="logout" href="/logout">Log out</a>
+    <% } %>
 </div>

+ 12 - 2
views/shared/shared.css

@@ -1,15 +1,16 @@
 .header{
     display: flex;
-    justify-content: center;
+    justify-content: space-between;
     background: #001b2d;
     width: 100%;
     height: 75px;
 }
 
-    .header a{
+    .header .logo{
         display: flex;
         align-items: center;
         text-decoration: none;
+        margin-left: 5px;
     }
 
     .header img{
@@ -24,6 +25,15 @@
         color: #ff626b;
     }
 
+    .header .logout{
+        display: flex;
+        align-items: center;
+        color: #ff626b;
+        float: right;
+        margin-right: 25px;
+        text-decoration: none;
+    }
+
 .banner{
     width: 100%;
     text-align: center;