浏览代码

Bug fix: changing the password was no longer working.

Lee Morgan 5 年之前
父节点
当前提交
c69ee9e9b9

+ 12 - 11
controllers/merchantData.js

@@ -315,25 +315,26 @@ module.exports = {
     response = {redirect: String (link to redirect to)}
     */
     changePassword: function(req, res){
-        if(req.body.new !== req.body.confirm){
-            return res.json("PASSWORDS DO NOT MATCH");
-        }
+        if(req.body.new !== req.body.confirm) return res.json("PASSWORDS DO NOT MATCH");
 
-        bcrypt.compare(req.body.current, res.locals.merchant.password, (err, result)=>{
+        bcrypt.compare(req.body.current, res.locals.owner.password, (err, result)=>{
             if(result === true){
                 let salt = bcrypt.genSaltSync(10);
                 let hash = bcrypt.hashSync(req.body.new, salt);
 
-                res.locals.merchant.password = hash;
+                res.locals.owner.password = hash;
 
                 let newExpiration = new Date();
                 newExpiration.setDate(newExpiration.getDate() + 90);
-                res.locals.merchant.session.sessionId = helper.generateId(25);
-                res.locals.merchant.session.expiration = newExpiration;
-
-                res.locals.merchant.save()
-                    .then((merchant)=>{
-                        req.session.error = "PLEASE LOG IN";
+                res.locals.owner.session.sessionId = helper.generateId(25);
+                res.locals.owner.session.expiration = newExpiration;
+
+                res.locals.owner.save()
+                    .then((owner)=>{
+                        console.log("thing");
+                        req.session.owner = undefined;
+                        req.session.merchant = undefined;
+                        req.session.success = "PASSWORD RESET. PLEASE LOG IN AGAIN.";
                         return res.json({redirect: `http://${process.env.SITE}/login`});
                     })
                     .catch((err)=>{

+ 1 - 1
views/dashboardPage/js/strands/account.js

@@ -105,7 +105,7 @@ let account = {
                 if(typeof(response) === "string"){
                     controller.createBanner(response, "error");
                 }else{
-                    window.location.href = response.redirect;
+                    window.location.replace(response.redirect);
                 }
             })
             .catch((err)=>{

+ 1 - 1
views/otherPages/landing.ejs

@@ -70,7 +70,7 @@
                 bannerElem.children[1].innerText = locals.banner.message;
                 bannerElem.style.display = "flex";
 
-                switch(banner.type){
+                switch(locals.banner.type){
                     case "error":
                         bannerElem.children[0].innerHTML = `
                             <svg width="50" height="50" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">

+ 1 - 1
views/otherPages/login.ejs

@@ -47,7 +47,7 @@
                 bannerElem.children[1].innerText = locals.banner.message;
                 bannerElem.style.display = "flex";
 
-                switch(banner.type){
+                switch(locals.banner.type){
                     case "error":
                         bannerElem.children[0].innerHTML = `
                             <svg width="50" height="50" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">

+ 1 - 1
views/otherPages/register.ejs

@@ -79,7 +79,7 @@
                 bannerElem.children[1].innerText = locals.banner.message;
                 bannerElem.style.display = "flex";
 
-                switch(banner.type){
+                switch(locals.banner.type){
                     case "error":
                         bannerElem.children[0].innerHTML = `
                             <svg width="50" height="50" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">

+ 1 - 1
views/passwordResetPages/password.ejs

@@ -50,7 +50,7 @@
                 bannerElem.children[1].innerText = locals.banner.message;
                 bannerElem.style.display = "flex";
 
-                switch(banner.type){
+                switch(locals.banner.type){
                     case "error":
                         bannerElem.children[0].innerHTML = `
                             <svg width="50" height="50" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">