mirror of
https://github.com/Expand-sys/ccashfrontend
synced 2025-12-18 23:52:14 +11:00
patched password changing
This commit is contained in:
parent
404e1d9c3f
commit
6a835685f8
2 changed files with 46 additions and 48 deletions
4
index.js
4
index.js
|
|
@ -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" });
|
||||||
|
|
|
||||||
|
|
@ -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,31 +27,24 @@ 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]) {
|
|
||||||
res.render("settings", {
|
|
||||||
errors: errors,
|
|
||||||
user: req.session.user,
|
|
||||||
admin: req.session.admin,
|
|
||||||
marketplace: process.env.MARKETPLACE,
|
|
||||||
random: papy(),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
if (req.session.errors.length > 0) {
|
||||||
|
console.log(req.session.errors);
|
||||||
|
res.redirect("/settings");
|
||||||
|
} else {
|
||||||
try {
|
try {
|
||||||
patch = await got.patch("https://ccash.ryzerth.com/BankF/changepass", {
|
patch = await got.patch(process.env.BANKAPIURL + "BankF/changepass", {
|
||||||
json: {
|
json: {
|
||||||
name: req.session.user,
|
name: req.session.user,
|
||||||
attempt: attempt,
|
attempt: attempt,
|
||||||
|
|
@ -55,26 +55,24 @@ router.post("/pass", ensureAuthenticated, async function (req, res) {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
console.log(patch);
|
console.log(patch.body);
|
||||||
if (patch.body.value == true) {
|
if (patch.body.value == 0) {
|
||||||
successes.push({ msg: "Change Password Successful, Please Login Again" });
|
req.session.errors.push({
|
||||||
}
|
msg: "Password Wrong",
|
||||||
|
});
|
||||||
|
res.redirect("/settings");
|
||||||
|
} else {
|
||||||
req.session.regenerate(function (err) {
|
req.session.regenerate(function (err) {
|
||||||
res.render("login", {
|
if (patch.body.value == 1) {
|
||||||
successes: successes,
|
req.session.successes = [];
|
||||||
errors: errors,
|
req.session.successes.push({
|
||||||
marketplace: process.env.MARKETPLACE,
|
msg: "Change Password Successful, Please Login Again",
|
||||||
random: papy(),
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
function papy() {
|
|
||||||
const rndInt = Math.floor(Math.random() * 1337);
|
|
||||||
let random = false;
|
|
||||||
if (rndInt == 420) {
|
|
||||||
random = true;
|
|
||||||
}
|
}
|
||||||
return random;
|
res.redirect("/login");
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue