-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware.js
36 lines (32 loc) · 850 Bytes
/
middleware.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module.exports.isLoggedIn = (req, res, next) => {
if (!req.isAuthenticated()) {
req.flash("error", "You must be signed in first!");
return res.redirect("/");
}
next();
};
module.exports.isParent = (req, res, next) => {
if (typeof req.user === "undefined" || req.user.userType !== "parent") {
return res.redirect("/");
}
next();
};
module.exports.isCanteenWorker = (req, res, next) => {
if (
typeof req.user === "undefined" ||
req.user.userType !== "canteenWorker"
) {
return res.redirect("/");
}
next();
};
module.exports.isAdmin = (req, res, next) => {
if (typeof req.user === "undefined" || req.user.userType !== "admin") {
return res.redirect("/");
}
next();
};
module.exports.usernameToLowerCase = (req, res, next) => {
req.body.username = req.body.username.toLowerCase();
next();
};