Răsfoiți Sursa

Update logging in to use owner instead of merchant.
Still cannot get in to the dashboard if the account is not verified.

Lee Morgan 5 ani în urmă
părinte
comite
64d998230e
1 a modificat fișierele cu 14 adăugiri și 13 ștergeri
  1. 14 13
      controllers/otherData.js

+ 14 - 13
controllers/otherData.js

@@ -1,4 +1,4 @@
-const Merchant = require("../models/merchant");
+const Owner = require("../models/owner.js");
 const Feedback = require("../models/feedback.js");
 
 const bcrypt = require("bcryptjs");
@@ -13,19 +13,20 @@ module.exports = {
     Redirects to /dashboard
     */
     login: function(req, res){
-        Merchant.findOne({email: req.body.email.toLowerCase()})
-            .then((merchant)=>{
-                if(merchant !== null){
-                    bcrypt.compare(req.body.password, merchant.password, async (err, result)=>{
+        Owner.findOne({email: req.body.email.toLowerCase()})
+            .then((owner)=>{
+                console.log(owner);
+                if(owner !== null){
+                    bcrypt.compare(req.body.password, owner.password, async (err, result)=>{
                         if(result === true){
                             //Check if email has not been verified
-                            if(merchant.status.includes("unverified")){
+                            if(owner.status.includes("unverified")){
                                 req.session.error = "PLEASE VERIFY YOUR EMAIL ADDRESS";
-                                return res.redirect(`/verify/email/${merchant._id}`);
+                                return res.redirect(`/verify/email/${owner._id}`);
                             }
 
                             //Check for suspended account
-                            if(merchant.status.includes("suspended")){
+                            if(owner.status.includes("suspended")){
                                 req.session.error = "ACCOUNT SUSPENDED. PLEASE CONTACT SUPPORT IF THIS IS IN ERROR";
                                 return res.redirect("/");
                             }
@@ -33,7 +34,7 @@ module.exports = {
                             //Check for out of date access token
                             let cutoff = new Date();
                             cutoff.setDate(cutoff.getDate() + 1);
-                            if(merchant.pos === "square" && merchant.square.expires < cutoff){
+                            if(owner.square !== undefined && owner.square.expires < cutoff){
                                 let data = await axios.post(`${process.env.SQUARE_ADDRESS}/oauth2/token`, {
                                     client_id: process.env.SUBLINE_SQUARE_APPID,
                                     client_secret: process.env.SUBLINE_SQUARE_APPSECRET,
@@ -41,13 +42,13 @@ module.exports = {
                                     refresh_token: merchant.square.refreshToken
                                 });
 
-                                merchant.square.accessToken = data.data.access_token;
-                                merchant.square.expires = new Date(data.data.expires_at);
+                                owner.square.accessToken = data.data.access_token;
+                                owner.square.expires = new Date(data.data.expires_at);
 
-                                await merchant.save();
+                                await owner.save();
                             }
 
-                            req.session.owner = merchant.session.sessionId;
+                            req.session.owner = owner.session.sessionId;
                             return res.redirect("/dashboard");
                         }else{
                             req.session.error = "INVALID EMAIL OR PASSWORD";