Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewstech committed Mar 31, 2024
1 parent 29a5457 commit 3f999fd
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
42 changes: 42 additions & 0 deletions routes/password.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module.exports = async (req, res) => {
const token = req.cookies.token;
const password = req.body.password;
const confirmPassword = req.body.cpassword;

if (!password || !confirmPassword) {
return res.render("settings", { message: "Missing password." });
}

if (password !== confirmPassword) {
return res.render("settings", { message: "Passwords do not match." });
}

const data = {
"password": password,
};

const response = await fetch("https://api.open-domains.net/password", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `${token}`
},
body: JSON.stringify(data),
});

console.log(response.body);

if (response) {
if (response.status === 400) {
return res.render("settings", { message: "Invalid password." });
}
if (response.status === 500) {
return res.render("settings", { message: "Internal server error." });
}
if (response.status === 200) {
return res.render("settings", { message: "Password updated." });
}
} else {
return res.render("settings", { message: "Internal server error." });
}
}
3 changes: 3 additions & 0 deletions routes/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ module.exports = async (req, res) => {
if (response.status === 500) {
return res.render("register", { message: "Internal server error." });
}
if (response.status === 451) {
return res.render("register", { message: response.body.message });
}
if (response.status === 200) {
return res.render("registered");
}
Expand Down
4 changes: 4 additions & 0 deletions util/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,9 @@ router.get("/mfa-setup", authenticateToken, (req, res) => {
routes.mfa(req, res);
});

router.post("/password", authenticateToken, upload.any(), (req, res) => {
routes.password(req, res);
});


module.exports = router;
4 changes: 3 additions & 1 deletion util/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const verify = require("../routes/verify");
const logout = require("../routes/logout");
const staff = require("../routes/staff");
const mfa = require("../routes/mfa");
const password = require("../routes/password");


module.exports = {
Expand All @@ -18,5 +19,6 @@ module.exports = {
verify,
logout,
staff,
mfa
mfa,
password
}

0 comments on commit 3f999fd

Please sign in to comment.