patched password changing

This commit is contained in:
Expand-sys 2021-06-10 07:38:25 +10:00
parent 404e1d9c3f
commit 6a835685f8
2 changed files with 46 additions and 48 deletions

View file

@ -309,8 +309,8 @@ app.post("/register", async function (req, res) {
let checkuser = await got(process.env.BANKAPIURL + "BankF/contains/" + name); let checkuser = await got(process.env.BANKAPIURL + "BankF/contains/" + name);
checkuser = JSON.parse(checkuser.body).value; checkuser = JSON.parse(checkuser.body).value;
let errors = []; let errors = req.session.errors;
let successes = []; let successes = req.session.successes;
if (checkuser == false) { if (checkuser == false) {
if (!name || !password || !password2) { if (!name || !password || !password2) {
errors.push({ msg: "please fill in all fields" }); errors.push({ msg: "please fill in all fields" });

View file

@ -11,7 +11,14 @@ const { postUser } = require("../helpers/functions.js");
const got = require("got"); const got = require("got");
router.get("/", ensureAuthenticated, function (req, res) { router.get("/", ensureAuthenticated, function (req, res) {
let successes = req.session.successes;
req.session.successes = [];
let errors = req.session.errors;
req.session.errors = [];
res.render("settings", { res.render("settings", {
errors: errors,
successes: successes,
user: req.session.user, user: req.session.user,
admin: req.session.admin, admin: req.session.admin,
}); });
@ -20,61 +27,52 @@ router.get("/", ensureAuthenticated, function (req, res) {
router.post("/pass", ensureAuthenticated, async function (req, res) { router.post("/pass", ensureAuthenticated, async function (req, res) {
let { attempt, new_pass, password2 } = req.body; let { attempt, new_pass, password2 } = req.body;
let patch; let patch;
let successes = [];
let errors = [];
if (!attempt || !new_pass || !password2) { if (!attempt || !new_pass || !password2) {
errors.push({ msg: "please fill in all fields" }); req.session.errors.push({ msg: "please fill in all fields" });
} }
//check if match //check if match
if (new_pass !== password2) { if (new_pass != password2) {
errors.push({ msg: "Passwords don't match" }); req.session.errors.push({ msg: "Passwords don't match" });
} }
//check if password is more than 6 characters //check if password is more than 6 characters
if (new_pass.length < 6) { if (new_pass.length < 6) {
errors.push({ msg: "Password must be at least 6 characters" }); req.session.errors.push({ msg: "Password must be at least 6 characters" });
} }
if (errors[0]) { if (req.session.errors.length > 0) {
res.render("settings", { console.log(req.session.errors);
errors: errors, res.redirect("/settings");
user: req.session.user, } else {
admin: req.session.admin, try {
marketplace: process.env.MARKETPLACE, patch = await got.patch(process.env.BANKAPIURL + "BankF/changepass", {
random: papy(), json: {
}); name: req.session.user,
attempt: attempt,
new_pass: new_pass,
},
responseType: "json",
});
} catch (err) {
console.log(err);
}
console.log(patch.body);
if (patch.body.value == 0) {
req.session.errors.push({
msg: "Password Wrong",
});
res.redirect("/settings");
} else {
req.session.regenerate(function (err) {
if (patch.body.value == 1) {
req.session.successes = [];
req.session.successes.push({
msg: "Change Password Successful, Please Login Again",
});
}
res.redirect("/login");
});
}
} }
try {
patch = await got.patch("https://ccash.ryzerth.com/BankF/changepass", {
json: {
name: req.session.user,
attempt: attempt,
new_pass: new_pass,
},
responseType: "json",
});
} catch (err) {
console.log(err);
}
console.log(patch);
if (patch.body.value == true) {
successes.push({ msg: "Change Password Successful, Please Login Again" });
}
req.session.regenerate(function (err) {
res.render("login", {
successes: successes,
errors: errors,
marketplace: process.env.MARKETPLACE,
random: papy(),
});
});
}); });
function papy() {
const rndInt = Math.floor(Math.random() * 1337);
let random = false;
if (rndInt == 420) {
random = true;
}
return random;
}
module.exports = router; module.exports = router;