This repository was archived by the owner on May 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthentication.js
More file actions
47 lines (46 loc) · 1.64 KB
/
authentication.js
File metadata and controls
47 lines (46 loc) · 1.64 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var formsTools = require('./formsauthentication.js')
exports.authentication = function (env) {
return function (req, res, next) {
var middleware = function () {
if (req.path != '/login') {
if (req.session['authenticated'] == true) {
next()
} else {
res.redirect('/login?target=' + encodeURIComponent(req.originalUrl))
}
} else {
next()
}
}
if (process.env.AUTHENTICATIONMODE == 'forms' && 'development' == env) {
var WP = require('./persistence/workerProvider.js').WorkerProvider
var wp = new WP()
wp.byId('theo', function (err, result) {
if (err) {
var user = {
username: 'theo',
password: 'start',
firstname: 'Theo',
lastname: 'Test',
emailaddress: 'theo.test@test.de',
phonenumber: '+49 152 55709066',
isadmin: true,
department: 'projectmanagement'
}
wp.save(user, function (err, result) {
middleware()
})
} else {
middleware()
}
})
} else if ('development' == env) {
req.session['isAdmin'] = true
req.session['fullname'] = 'Theo Test'
req.session['username'] = 'theo'
next()
} else {
middleware()
}
}
}