Explorar el Código

Create login for non-pos user

Lee Morgan hace 6 años
padre
commit
7ab4d55bd2

+ 42 - 0
controllers/merchantData.js

@@ -9,6 +9,48 @@ const RecipeChange = require("../models/recipeChange");
 const token = "b48068eb-411a-918e-ea64-52007147e42c";
 
 module.exports = {
+    //POST - Create a new merchant with no POS system
+    //Inputs:
+    //  req.body.name: restaurant name
+    //  req.body.email: registration email
+    //  req.body.password: password
+    //  req.body.confirmPassword: confirmation password
+    //Redirects to /inventory
+    createMerchantNone: function(req, res){
+        if(req.body.password === req.body.confirmPassword){
+            var salt = bcrypt.genSaltSync(10);
+            var hash = bcrypt.hashSync(req.body.password, salt);
+
+            let merchant = new Merchant({
+                name: req.body.name,
+                email: req.body.email.toLowerCase(),
+                password: hash,
+                pos: "none",
+                lastUpdatedTime: Date.now(),
+                createdAt: Date.now(),
+                accountStatus: "valid",
+                inventory: [],
+                recipes: []
+            });
+
+            merchant.save()
+                .then((merchant)=>{
+                    req.session.user = merchant._id;
+
+                    return res.redirect("/inventory");
+                })
+                .catch((err)=>{
+                    req.session.error = "Error: Unable to create account at this time";
+
+                    return res.redirect("/");
+                });
+        }else{
+            req.session.error = "Error: Passwords must match";
+
+            return res.redirect("/");
+        }
+    },
+
     //GET - Checks clover for new or deleted recipes
     //Returns: 
     //  merchant: Full merchant (recipe ingredients populated)

+ 2 - 1
controllers/renderer.js

@@ -99,7 +99,8 @@ module.exports = {
                         });
                 }else if(merchant.pos === "none"){
                     merchant.password = undefined;
-                    return res.render("inventoryPage/inventory", {merchant: merchant, error: undefined})
+                    console.log(merchant);
+                    return res.render("inventoryPage/inventory", {merchant: merchant, error: undefined});
                 }else{
                     req.session.error = "Error: WEBSITE PANIC";
                     

+ 1 - 0
routes.js

@@ -15,6 +15,7 @@ module.exports = function(app){
     app.get("/data", renderer.displayData);
 
     //Merchant
+    app.post("/merchant/create/none", merchantData.createMerchantNone);
     app.get("/merchant/recipes/update", merchantData.updateRecipes);
     app.post("/merchant/ingredients/create", merchantData.addMerchantIngredient);
     app.post("/merchant/ingredients/remove", merchantData.removeMerchantIngredient);

+ 1 - 1
views/inventoryPage/inventory.ejs

@@ -68,7 +68,7 @@
                 <button class="button" onclick="accountObj.editAccount()">Edit</button>
             </form>
 
-            <form id="accountEdit" onsubmit="accountObj.updateAccount()">
+            <form id="accountEdit">
                 <label>Name:&nbsp;&nbsp;
                     <input id="accountName" type="text" value="<%=merchant.name%>">
                 </label>

+ 8 - 0
views/landingPage/landing.css

@@ -1,3 +1,4 @@
+/* Public Strand */
 #publicStrand{
     display: flex;
     flex-direction: column;
@@ -78,6 +79,7 @@
             color: rgb(255, 99, 107);
         }
 
+/* Login Strand */
 #loginStrand{
     display: none;
     align-items: center;
@@ -104,6 +106,12 @@
             margin: 10px 0;
         }
 
+/* Register Strand */
+#registerStrand{
+    display: none;
+    justify-content: space-around;
+}
+
 @media screen and (max-width: 600px){
     .logo-text img{
         max-height: 20vh;

+ 10 - 6
views/landingPage/landing.ejs

@@ -69,26 +69,30 @@
             </form>
         </div>
 
-        <div id="registerStrand" onsubmit="registerObj.submit()">
-            <form>
+        <div id="registerStrand">
+            <form action="/merchant/create/none" method="post">
                 <label>Restaurant Name:
-                    <input id="regName" type="text">
+                    <input name="name" type="text">
                 </label>
 
                 <label>Email:
-                    <input id="regEmail" type="email">
+                    <input name="email" type="email">
                 </label>
 
                 <label>Password:
-                    <input id="regPass" type="password">
+                    <input name="password" type="password">
                 </label>
 
                 <label>Confirm Password:
-                    <input id="regConfirmPass" type="password">
+                    <input name="confirmPassword" type="password">
                 </label>
 
                 <input type="submit" value="Register">
             </form>
+
+            <button onclick="registerObj.submitClover()">Register with Clover</button>
+
+            <button onclick="registerObj.cancel">Cancel</button>
         </div>
         
 

+ 0 - 4
views/landingPage/public.js

@@ -2,9 +2,5 @@ let publicObj = {
     display: function(){
         controller.clearScreen();
         controller.publicStrand.style.display = "flex";
-
-        if(isLoggedIn){
-            loginObj.display();
-        }
     }
 }

+ 29 - 2
views/landingPage/register.js

@@ -4,9 +4,36 @@ let registerObj = {
         controller.registerStrand.style.display = "flex";
     },
 
-    submit: function(){
+    cancel: function(){
         event.preventDefault();
 
-        
+        publicObj.display();
+    },
+
+    submitNone: function(){
+        event.preventDefault();
+
+        let name = document.querySelector("#regName").value;
+        let email = document.querySelector("#regEmail").value;
+        let pass = document.querySelector("#regPass").value;
+        let confirmPass = document.querySelector("#regConfirmPass").value;
+
+        let data = {
+            name: name,
+            email: email,
+            password: pass,
+            confirmPassword: confirmPass
+        }
+
+        if(validator.merchant.password(pass, confirmPass) && validator.isSanitary(name)){
+            document.querySelector("#regsiterStrand form").submit();
+        }
+
+        // if(validator.merchant.password(pass, confirmPass) && validator.isSanitary(name)){
+        //     axios.post("/merchant/create/none", data)
+        //         .catch((err)=>{
+        //             banner.createError("Error: Unable to create account at the moment");
+        //         });
+        // }
     }
 }