Bläddra i källkod

Update register page to route to correct location.
Create initial merchant data from frontend form data.

Lee Morgan 5 år sedan
förälder
incheckning
48390cad29
4 ändrade filer med 81 tillägg och 10 borttagningar
  1. 43 3
      controllers/squareData.js
  2. 1 1
      routes.js
  3. 19 6
      views/otherPages/register.ejs
  4. 18 0
      views/otherPages/style.css

+ 43 - 3
controllers/squareData.js

@@ -2,13 +2,53 @@ const Merchant = require("../models/merchant.js");
 const Recipe = require("../models/recipe.js");
 const Transaction = require("../models/transaction.js");
 
-const axios = require("axios");
 const helper = require("./helper.js");
 
+const axios = require("axios");
+const bcrypt = require("bcryptjs");
+
 module.exports = {
-    //GET - Redirects user to Square OAuth page
+    /*POST - Redirects user to Square OAuth and saves input data
+    req.body = {
+        name: String,
+        email: String,
+        password: String,
+        confirmPassword: String
+    }
+    */
     redirect: function(req, res){
-        return res.redirect(`${process.env.SQUARE_ADDRESS}/oauth2/authorize?client_id=${process.env.SUBLINE_SQUARE_APPID}&scope=INVENTORY_READ+ITEMS_READ+MERCHANT_PROFILE_READ+ORDERS_READ+PAYMENTS_READ`);
+        if(req.body.password !== req.body.confirmPassword){
+            req.session.error = "YOUR PASSWORDS DO NOT MATCH";
+            return res.redirect("/");
+        }
+
+        let expirationDate = new Date();
+        expirationDate.setDate(expirationDate.getDate() + 90);
+
+        let salt = bcrypt.genSaltSync(10);
+        let hash = bcrypt.hashSync(req.body.password, salt);
+
+        let merchant = new Merchant({
+            name: req.body.name,
+            email: req.body.email,
+            password: hash,
+            pos: "square",
+            inventory: [],
+            recipes: [],
+            session: {
+                sessionId: helper.generateId(25),
+                expiration: expirationDate
+            }
+        });
+
+        merchant.save()
+            .then((response)=>{
+                return res.redirect(`${process.env.SQUARE_ADDRESS}/oauth2/authorize?client_id=${process.env.SUBLINE_SQUARE_APPID}&scope=INVENTORY_READ+ITEMS_READ+MERCHANT_PROFILE_READ+ORDERS_READ+PAYMENTS_READ`);
+            })
+            .catch((err)=>{
+                res.session.error = "ERROR: UNABLE TO CREATE NEW USER";
+                return res.redirect("/");
+            });
     },
 
     //GET: Used by square. This route is used for the authentication code

+ 1 - 1
routes.js

@@ -81,7 +81,7 @@ module.exports = function(app){
     app.post("/reset", passwordReset.resetPassword);
 
     //Square
-    app.get("/squarelogin", squareData.redirect);
+    app.post("/squarelogin", squareData.redirect);
     app.get("/squareauth", squareData.authorize);
     app.get("/merchant/create/square", squareData.createMerchant);
     app.get("/recipes/update/square", session, squareData.updateRecipes);

+ 19 - 6
views/otherPages/register.ejs

@@ -20,7 +20,7 @@
             <% include ../shared/banner.ejs %>
         <% } %>
 
-        <form action="/merchant/create/none" method="post">
+        <form method="post">
             <h1> Join The Subline </h1>
 
             <label id="nameLabel">Restaurant Name
@@ -40,7 +40,7 @@
             </label>
     
             <label id="agreement">
-                <input type="checkbox" name="agree">
+                <input type="checkbox" name="agree" required>
 
                 <p>I agree to the 
                     <a class="link" href="/privacy">Privacy Policy</a> and the 
@@ -48,13 +48,26 @@
                 </p>
             </label>
 
-            <input class="buttonDisabled" type="submit" value="Sign Up with Email">
+            <h2 class="customText">Sign up with:</h2>
 
-            <h1>OR</h1>
+            <button id="squareButton" class="button" formaction="/squarelogin">
+                <svg aria-hidden="true" viewBox="0 0 44 44" width="44" height="44">
+                    <path fill="currentColor" d="M36.65 0H7.354A7.354 7.354 0 0 0 0 7.354V36.65a7.354 7.354 0 0 0 7.354 7.354H36.65a7.353 7.353 0 0 0 7.354-7.354V7.354A7.352 7.352 0 0 0 36.65 0zm-.646 33.685a2.32 2.32 0 0 1-2.32 2.32H10.325a2.32 2.32 0 0 1-2.321-2.32v-23.36a2.32 2.32 0 0 1 2.321-2.321h23.359a2.32 2.32 0 0 1 2.32 2.321v23.36z"></path>
+                    <path fill="currentColor" d="M17.333 28.003c-.736 0-1.332-.6-1.332-1.339V17.34c0-.739.596-1.339 1.332-1.339h9.338c.738 0 1.332.6 1.332 1.339v9.324c0 .739-.594 1.339-1.332 1.339h-9.338z"></path>
+                </svg>
+                <svg aria-hidden="true" viewBox="0 0 66 22" width="66" height="22">
+                    <path d="M11.2 10c-.7-.2-1.3-.4-1.8-.6C8.4 9 8 8.4 8 7.6c0-1.5 1.5-2.2 3-2.2 1.4 0 2.6.6 3.5 1.6l.1.1 1.2-.9-.1-.1c-1.1-1.4-2.7-2.2-4.6-2.2-1.2 0-2.4.3-3.2.9-1 .8-1.5 1.7-1.5 2.9 0 2.7 2.6 3.4 4.6 3.9 2.1.6 3.4 1 3.4 2.6s-1.3 2.6-3.2 2.6c-1 0-2.8-.3-3.9-2l-.1-.1-1.2.9v.1c1.1 1.6 2.9 2.5 5.1 2.5 2.9 0 4.9-1.6 4.9-4.1 0-2.8-2.7-3.5-4.8-4.1z" fill="currentColor"></path>
+                    <path d="M25.5 9.5V8h1.4v14h-1.4v-5.5c-.8 1.1-2 1.7-3.4 1.7-2.7 0-4.5-2.1-4.5-5.2s1.9-5.2 4.5-5.2c1.4-.1 2.6.6 3.4 1.7zM19.1 13c0 2.9 1.6 3.9 3.2 3.9 2 0 3.3-1.5 3.3-3.9s-1.3-3.9-3.3-3.9c-2.4 0-3.2 2-3.2 3.9z" fill-rule="evenodd" clip-rule="evenodd" fill="currentColor"></path>
+                    <path d="M36.2 8v5.5c0 1.9-1.3 3.3-3.2 3.3-1.5 0-2.3-.9-2.3-2.8V8h-1.4v6.4c0 2.4 1.3 3.8 3.5 3.8 1.4 0 2.5-.6 3.3-1.6V18h1.4V8h-1.3z" fill="currentColor"></path>
+                    <path d="M40.3 9c1-.8 2.4-1.3 3.9-1.3 2.2 0 3.6 1.1 3.6 3V18h-1.4v-1.1c-.7.9-1.7 1.3-3.1 1.3-2.2 0-3.5-1.2-3.5-3.1 0-2.5 2.3-2.8 3.3-3 .2 0 .3-.1.5-.1 1.4-.2 2.7-.4 2.7-1.6 0-1.3-1.7-1.4-2.2-1.4-.9 0-2.2.3-3.1 1v.2L40.3 9zm.9 6.1c0 1.6 1.5 1.8 2.2 1.8 1.4 0 2.9-.8 2.9-2.9v-1.4c-.7.4-1.7.6-2.5.8l-.4.1c-1.5.1-2.2.5-2.2 1.6z" fill-rule="evenodd" clip-rule="evenodd" fill="currentColor"></path>
+                    <path d="M55.9 8.2c-.3-.2-.9-.4-1.4-.4-1.1 0-2.2.6-2.8 1.5V8h-1.4v10h1.4v-5.4c0-2.4 1.3-3.4 2.7-3.4.4 0 .8.1 1.1.2l.1.1.3-1.3z" fill="currentColor"></path>
+                    <path d="M56.3 13c0-3.1 1.9-5.3 4.7-5.3 2.7 0 4.5 1.9 4.5 4.7V13.2h-7.7c0 2.2 1.4 3.6 3.4 3.6 1.2 0 2.2-.5 2.8-1.3l.1-.1 1 .9-.1.1c-.7.8-1.9 1.8-3.9 1.8-2.9 0-4.8-2.1-4.8-5.2zm4.6-3.9c-1.7 0-2.9 1.1-3.1 2.9H64c-.1-1.4-1-2.9-3.1-2.9z" fill-rule="evenodd" clip-rule="evenodd" fill="currentColor"></path>
+                </svg>
+            </button>
 
-            <!-- <a class="button buttonWithBorder" href="/cloverlogin">Sign Up with Clover</a> -->
+            <button class="button" formaction="/merchant/create/none">NO POS</button>
 
-            <a class="button buttonWithBorder" href="/squarelogin">Sign Up with Square</a>
+            <!-- <a class="button buttonWithBorder" href="/cloverlogin">Sign Up with Clover</a> -->
 
             <a class="link" href="/login">Already have an account? Please Sign In</a>
         </form>

+ 18 - 0
views/otherPages/style.css

@@ -50,6 +50,20 @@ form{
     color: white;
 }
 
+#squareButton{
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    border: 1px solid black;
+    background: white;
+    color: black;
+}
+
+    #squareButton:hover{
+        color: white;
+        background: black;
+    }
+
 /* Public Strand */
 #publicStrand{
     display: flex;
@@ -165,6 +179,10 @@ RegisterPage
             margin-right: 15px;
         }
 
+    .customText{
+        margin: 20px auto 0 auto;
+    }
+
 /*
 Footer Partial
 */