✨ Use Vue-based login page
This commit is contained in:
@ -3,7 +3,7 @@ export class Auth {
|
||||
constructor() {}
|
||||
login = (req, res) => {
|
||||
if (!req.body.password) {
|
||||
res.status(401).sendFile("login.html", { root: "../" });
|
||||
res.redirect("/login");
|
||||
return;
|
||||
} else {
|
||||
if (req.body.password == process.env.AUTH_PASSWORD) {
|
||||
@ -15,18 +15,18 @@ export class Auth {
|
||||
});
|
||||
res.redirect("/");
|
||||
} else {
|
||||
res.status(401).sendFile("login.html", { root: "../" });
|
||||
res.redirect("/login");
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
checkLogin = (req, res, next) => {
|
||||
if (!req.cookies.session) {
|
||||
res.status(401).sendFile("login.html", { root: "../" });
|
||||
res.sendStatus(401);
|
||||
return;
|
||||
} else {
|
||||
if (!this.activeSessions.includes(req.cookies.session)) {
|
||||
res.status(401).sendFile("login.html", { root: "../" });
|
||||
res.sendStatus(401);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -29,13 +29,16 @@ const parser = new Parser(
|
||||
);
|
||||
|
||||
app.post("/login", auth.login);
|
||||
app.use(auth.checkLogin);
|
||||
|
||||
app.use("/api", auth.checkLogin);
|
||||
app.get("/api/check", (_req, res) => {
|
||||
res.sendStatus(200);
|
||||
});
|
||||
app.get("/api/timetable", getTimetable);
|
||||
app.get("/api/substitutions", getSubstitutions);
|
||||
app.get("/api/history", getHistory);
|
||||
app.get("/api/classes", getClasses);
|
||||
app.get("/api/*", (req, res) => {
|
||||
app.get("/api/*", (_req, res) => {
|
||||
res.sendStatus(400);
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user