소스 검색

Create new html for welcoming new users.
Generate an id for verifying email upon sign-up.

Lee Morgan 5 년 전
부모
커밋
ead0b92779
5개의 변경된 파일51개의 추가작업 그리고 50개의 파일을 삭제
  1. 11 0
      controllers/helper.js
  2. 9 3
      controllers/merchantData.js
  3. 15 43
      emails/welcomeEmail.js
  4. 1 4
      models/merchant.js
  5. 15 0
      workspace.html

+ 11 - 0
controllers/helper.js

@@ -233,5 +233,16 @@ module.exports = {
             case "ft": return quantity / 3.2808;
             default: return quantity;
         }
+    },
+
+    generateId: function(length){
+        let result = "";
+        let characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+
+        for(let i = 0; i < length; i++){
+            result += characters.charAt(Math.floor(Math.random() * characters.length));
+        }
+        
+        return results.length;
     }
 }

+ 9 - 3
controllers/merchantData.js

@@ -6,6 +6,7 @@ const Merchant = require("../models/merchant");
 const Recipe = require("../models/recipe");
 const InventoryAdjustment = require("../models/inventoryAdjustment");
 const Validator = require("./validator.js");
+const Helper = require("./helper.js");
 const WelcomeEmail = require("../emails/welcomeEmail.js");
 
 module.exports = {
@@ -37,20 +38,25 @@ module.exports = {
                 pos: "none",
                 lastUpdatedTime: Date.now(),
                 createdAt: Date.now(),
-                accountStatus: "valid",
+                status: ["unverified"],
                 inventory: [],
-                recipes: []
+                recipes: [],
+                verifyId: Helper.generateId(15)
             });
 
             merchant.save()
                 .then((merchant)=>{
                     req.session.user = merchant._id;
+                    const mail = merchant.email.split("@");
 
                     const mailgunData = {
                         from: "The Subline <clientsupport@thesubline.net>",
                         to: merchant.email,
                         subject: "Welcome to The Subline!",
-                        template: "welcome-message"
+                        html: WelcomeEmail({
+                            name: merchant.name,
+                            link: `${process.env.SITE}/verify/${merchant.verifyId}/${mail[0]}`
+                        })
                     }
                     mailgun.messages().send(mailgunData, (err, body)=>{});
 

+ 15 - 43
emails/welcomeEmail.js

@@ -1,47 +1,19 @@
 module.exports = (data)=>{
     return `
-        <!DOCTYPE html>
-        <html>
-            <head>
-                <meta charset="utf-8">
-                <meta content="width=device-width, initial-scale=1" name="viewport"/>
-                <title>Welcome to The Subline</title>
-                <link href="https://fonts.googleapis.com/css?family=Saira&display=swap" rel="stylesheet">
-                <style>
-                    *{margin:0;padding:0;font-family:"Saira",sans-serif;}
-        
-                    .header{
-                        display: flex;
-                        justify-content: flex-start;
-                        align-items: center;
-                        height: 75px;
-                        width: 100%;
-                        background: rgb(0, 27, 45);
-                        color: rgb(255, 99, 107);
-                    }
-        
-                    .header img{
-                        max-height: 80%;
-                    }
-        
-                    .message{
-                        width: 90%;
-                        margin: auto;
-                        text-align: center;
-                        padding: 100px 0;
-                        font-size: 30px;
-                    }
-                </style>
-            </head>
-            <body>
-                <div class="header">
-                    <img src="localhost:8080/logo" alt="The Subline">
-                    
-                    <h1>THE SUBLINE</h1>
-                </div>
-        
-                <p class="message">Thank you for signing up for The Subline ${data.name}.  We look forward to helping your business to reduce waste.  To get started, visit our <a href="thesubline.com/help">help page</a> for more information.</p>
-            </body>
-        </html>
+        <div id="welcomeEmail">
+            <header style="width:100%;height:75px;background:rgb(0,27,45);">
+                <img src="https://i.postimg.cc/dQky3vPX/logo.png" alt="Subline Logo" style="height:50px;padding:12px 12px;float:left;">
+
+                <h3 style="color:rgb(255,99,107);font-size:30px;margin:15px 0 0 0;float:left;">THE SUBLINE</h3>
+            </header>
+
+            <h1 style="text-align:center;">Welcome to The Subline ${data.name}!</h1>
+
+            <p>We are glad to have you aboard and look forward to helping your business improve efficiency and cut costs.</p>
+
+            <p>Please follow the link below to verify your email address:</p>
+
+            <p>${data.link}</p>
+        </div>
     `;
 }

+ 1 - 4
models/merchant.js

@@ -24,10 +24,7 @@ const MerchantSchema = new mongoose.Schema({
         type: Date,
         default: Date.now
     },
-    accountStatus: {
-        status: String,
-        expiration: Date,
-    },
+    status: [],
     squareLocation: String,
     inventory: [{
         ingredient: {

+ 15 - 0
workspace.html

@@ -0,0 +1,15 @@
+<div id="welcomeEmail">
+    <header style="width:100%;height:75px;background:rgb(0,27,45);text-align:center;display:inline;">
+            <img src="./views/shared/images/logo.png" alt="Subline Logo" style="height:75%">
+
+            <h3 style="color:rgb(255,99,107)">THE SUBLINE</h3>
+    </header>
+
+    <h1>Welcome to The Subline ${data.name}!</h1>
+
+    <p>We are glad to have you aboard and look forward to helping your business improve efficiency and cut costs.</p>
+
+    <p>Please click the link below to verify your email address.</p>
+
+    <a href="${data.link}">VERIFY EMAIL</a>
+</div>