-
Notifications
You must be signed in to change notification settings - Fork 1
/
misc.js
58 lines (48 loc) · 1.1 KB
/
misc.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const db = require("./config/db");
const User = require("./models/User");
function validateEmail(email) {
var re = /\S+@\S+\.\S+/;
return re.test(email);
}
function loginChecker(req, res, next) {
if (req.session.authorised) {
next();
return;
} else {
res.redirect("/");
return;
}
}
function sessionAuthorized(req, res, next) {
if(req.session.authorised) {
res.redirect("/");
return;
}else{
next();
return;
}
}
async function adminChecker(req, res, next) {
let role = req.session.role;
console.log("misc:" + role);
if (role == "admin") {
next()
}else{
console.log('error no permision');
res.redirect('/')
}
}
function checkForm(fields) {
for (var i = 0; i < fields.length; i++) {
var currElement = fields[i];
if (currElement == undefined || currElement == "") {
return false;
}
}
return true;
}
module.exports.checkForm = checkForm;
module.exports.loginChecker = loginChecker;
module.exports.adminChecker = adminChecker;
module.exports.sessionAuthorized = sessionAuthorized;
module.exports.validateEmail = validateEmail;