-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.js
More file actions
33 lines (33 loc) · 1.06 KB
/
helper.js
File metadata and controls
33 lines (33 loc) · 1.06 KB
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
//User portal/login help functions
module.exports = {
//check that session is authorized for admin route
authAdmin: function(req, res, next) {
if (!req.session.authenticated || req.session.role != 'admin') {
res.redirect('/');
return;
}
next();
},
//check that session is authorized for user route
authUser: function(req, res, next) {
if (!req.session.authenticated || req.session.role != 'user') {
res.redirect('/');
return;
}
next();
},
//check form input string is not null or only whitespace
isEmpty: function(input) {
return !input || !input.trim();
},
//generate random password for password reset
genPass: function(len) {
var password = '';
var charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-=+;:,.?';
while (len > 0) {
password += charset[Math.round(Math.random() * (charset.length - 1))];
len--;
}
return password;
}
};