浏览代码

Add backend for ending the current session.

Lee Morgan 5 年之前
父节点
当前提交
579b8ec2a6
共有 3 个文件被更改,包括 26 次插入2 次删除
  1. 25 0
      controllers/otherData.js
  2. 1 0
      routes.js
  3. 0 2
      views/shared/shared.css

+ 25 - 0
controllers/otherData.js

@@ -2,6 +2,8 @@ const Owner = require("../models/owner.js");
 const Merchant = require("../models/merchant.js");
 const Feedback = require("../models/feedback.js");
 
+const helper = require("./helper.js");
+
 const bcrypt = require("bcryptjs");
 
 module.exports = {
@@ -105,5 +107,28 @@ module.exports = {
             .catch((err)=>{
                 return res.json("ERROR: UNABLE TO SAVE DATA");
             });
+    },
+
+    /*
+    GET: changes the session id and logs user out
+    redirect = "/"
+    */
+    endSession: function(req, res){
+        let newExpiration = new Date();
+        newExpiration.setDate(newExpiration.getDate() + 90);
+
+        res.locals.owner.session.sessionId = helper.generateId(25);
+        res.locals.owner.session.expiration = newExpiration;
+
+        req.session.owner = undefined;
+        req.session.merchant = undefined;
+
+        res.locals.owner.save()
+            .then(()=>{
+                return res.redirect("/");
+            })
+            .catch((err)=>{
+                return res.json("ERROR: SOMETHING WENT WRONG. PLEASE CONTACT SUPPORT.");
+            });
     }
 }

+ 1 - 0
routes.js

@@ -67,6 +67,7 @@ module.exports = function(app){
     app.post("/login", otherData.login);
     app.get("/logout", otherData.logout);
     app.post("/feedback", session, otherData.feedback);
+    app.get("/session/end", session, otherData.endSession);
     
     //Information Pages
     app.get("/privacy", informationPages.privacy);

+ 0 - 2
views/shared/shared.css

@@ -176,8 +176,6 @@ button::-moz-focus-inner{
         cursor: pointer;
     }
 
-
-
 .button{
     display: initial;
     background: rgb(0, 27, 45);