Added the start of the login page
This commit is contained in:
parent
cb622ebea0
commit
cf94bde3a3
20
archon.js
20
archon.js
@ -1,18 +1,38 @@
|
||||
const express = require('express');
|
||||
const session = require('express-session');
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
// Start creating our session config
|
||||
var sess = {
|
||||
secret: 'dark archon', // will need to change this later
|
||||
cookie: {}
|
||||
}
|
||||
if (app.get('env') === 'production') {
|
||||
app.set('trust proxy', 1) // trust first proxy
|
||||
sess.cookie.secure = true // serve secure cookies
|
||||
}
|
||||
// Enable the Express.js session handling
|
||||
app.use(session(sess))
|
||||
|
||||
// Initialize the Twig template engine - this might get swapped for Twing later.
|
||||
app.set('view engine', 'twig');
|
||||
|
||||
// Service static files from public/
|
||||
app.use(express.static('public'));
|
||||
|
||||
// Load middleware
|
||||
authMiddleware = require('./src/middleware/authMiddleware');
|
||||
app.use('/', authMiddleware.authProtected);
|
||||
|
||||
// Load in route handlers
|
||||
indexRoutes = require('./routes/index');
|
||||
authRoutes = require('./routes/auth');
|
||||
|
||||
// Assign routes to handlers
|
||||
app.get('/', indexRoutes.home);
|
||||
app.get('/auth/login', authRoutes.getLogin);
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Example app listening on port ${port}`)
|
||||
|
94
package-lock.json
generated
94
package-lock.json
generated
@ -10,6 +10,7 @@
|
||||
"license": "BSD-2-Clause",
|
||||
"dependencies": {
|
||||
"express": "^4.18.1",
|
||||
"express-session": "^1.17.3",
|
||||
"grunt-dart-sass": "^2.0.1",
|
||||
"twig": "^1.15.4"
|
||||
},
|
||||
@ -506,6 +507,32 @@
|
||||
"node": ">= 0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/express-session": {
|
||||
"version": "1.17.3",
|
||||
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.3.tgz",
|
||||
"integrity": "sha512-4+otWXlShYlG1Ma+2Jnn+xgKUZTMJ5QD3YvfilX3AcocOAbIkVylSWEklzALe/+Pu4qV6TYBj5GwOBFfdKqLBw==",
|
||||
"dependencies": {
|
||||
"cookie": "0.4.2",
|
||||
"cookie-signature": "1.0.6",
|
||||
"debug": "2.6.9",
|
||||
"depd": "~2.0.0",
|
||||
"on-headers": "~1.0.2",
|
||||
"parseurl": "~1.3.3",
|
||||
"safe-buffer": "5.2.1",
|
||||
"uid-safe": "~2.1.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/express-session/node_modules/cookie": {
|
||||
"version": "0.4.2",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz",
|
||||
"integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/extend": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz",
|
||||
@ -1622,6 +1649,14 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/on-headers": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz",
|
||||
"integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/once": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
@ -1785,6 +1820,14 @@
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/random-bytes": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/random-bytes/-/random-bytes-1.0.0.tgz",
|
||||
"integrity": "sha1-T2ih3Arli9P7lYSMMDJNt11kNgs=",
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/range-parser": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
|
||||
@ -2123,6 +2166,17 @@
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/uid-safe": {
|
||||
"version": "2.1.5",
|
||||
"resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz",
|
||||
"integrity": "sha512-KPHm4VL5dDXKz01UuEd88Df+KzynaohSL9fBh096KWAxSKZQDI2uBrVqtvRM4rwrIrRRKsdLNML/lnaaVSRioA==",
|
||||
"dependencies": {
|
||||
"random-bytes": "~1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/unc-path-regex": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/unc-path-regex/-/unc-path-regex-0.1.2.tgz",
|
||||
@ -2647,6 +2701,28 @@
|
||||
"vary": "~1.1.2"
|
||||
}
|
||||
},
|
||||
"express-session": {
|
||||
"version": "1.17.3",
|
||||
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.3.tgz",
|
||||
"integrity": "sha512-4+otWXlShYlG1Ma+2Jnn+xgKUZTMJ5QD3YvfilX3AcocOAbIkVylSWEklzALe/+Pu4qV6TYBj5GwOBFfdKqLBw==",
|
||||
"requires": {
|
||||
"cookie": "0.4.2",
|
||||
"cookie-signature": "1.0.6",
|
||||
"debug": "2.6.9",
|
||||
"depd": "~2.0.0",
|
||||
"on-headers": "~1.0.2",
|
||||
"parseurl": "~1.3.3",
|
||||
"safe-buffer": "5.2.1",
|
||||
"uid-safe": "~2.1.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"cookie": {
|
||||
"version": "0.4.2",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz",
|
||||
"integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"extend": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz",
|
||||
@ -3502,6 +3578,11 @@
|
||||
"ee-first": "1.1.1"
|
||||
}
|
||||
},
|
||||
"on-headers": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz",
|
||||
"integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA=="
|
||||
},
|
||||
"once": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
@ -3623,6 +3704,11 @@
|
||||
"side-channel": "^1.0.4"
|
||||
}
|
||||
},
|
||||
"random-bytes": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/random-bytes/-/random-bytes-1.0.0.tgz",
|
||||
"integrity": "sha1-T2ih3Arli9P7lYSMMDJNt11kNgs="
|
||||
},
|
||||
"range-parser": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
|
||||
@ -3879,6 +3965,14 @@
|
||||
"mime-types": "~2.1.24"
|
||||
}
|
||||
},
|
||||
"uid-safe": {
|
||||
"version": "2.1.5",
|
||||
"resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz",
|
||||
"integrity": "sha512-KPHm4VL5dDXKz01UuEd88Df+KzynaohSL9fBh096KWAxSKZQDI2uBrVqtvRM4rwrIrRRKsdLNML/lnaaVSRioA==",
|
||||
"requires": {
|
||||
"random-bytes": "~1.0.0"
|
||||
}
|
||||
},
|
||||
"unc-path-regex": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/unc-path-regex/-/unc-path-regex-0.1.2.tgz",
|
||||
|
@ -16,6 +16,7 @@
|
||||
"license": "BSD-2-Clause",
|
||||
"dependencies": {
|
||||
"express": "^4.18.1",
|
||||
"express-session": "^1.17.3",
|
||||
"grunt-dart-sass": "^2.0.1",
|
||||
"twig": "^1.15.4"
|
||||
},
|
||||
|
3
routes/auth.js
Normal file
3
routes/auth.js
Normal file
@ -0,0 +1,3 @@
|
||||
exports.getLogin = (req, res, next) => {
|
||||
res.render('auth/login');
|
||||
};
|
15
src/middleware/authMiddleware.js
Normal file
15
src/middleware/authMiddleware.js
Normal file
@ -0,0 +1,15 @@
|
||||
exports.authProtected = (req, res, next) => {
|
||||
|
||||
// Extra check to make sure this isn't performed on the login page
|
||||
doNotProtect = ['/auth/login'];
|
||||
if (doNotProtect.includes(req.path)) {
|
||||
return next();
|
||||
}
|
||||
|
||||
if (!('ldap_bind_dn' in req.session)) {
|
||||
return res.redirect('/auth/login');
|
||||
} else {
|
||||
return next();
|
||||
}
|
||||
|
||||
};
|
38
views/auth/login.twig
Normal file
38
views/auth/login.twig
Normal file
@ -0,0 +1,38 @@
|
||||
{% extends 'layout.twig' %}
|
||||
|
||||
{% block content %}
|
||||
<header id="header" class="row">
|
||||
<div class="columns twelve">
|
||||
<h1>Login</h1>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="row">
|
||||
<form id="loginForm" class="columns twelve">
|
||||
<div class="row">
|
||||
<label class="columns twelve">
|
||||
LDAP Host:
|
||||
<input class="u-full-width" type="text" name="ldap_host" placeholder="Enter LDAP host...">
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<label class="columns six">
|
||||
Bind DN:
|
||||
<input class="u-full-width" type="text" name="bind_dn" placeholder="Enter bind DN...">
|
||||
</label>
|
||||
|
||||
<label class="columns six">
|
||||
Bind Password:
|
||||
<input class="u-full-width" type="password" name="bind_pw" placeholder="Enter bind password...">
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="columns twelve u-text-center">
|
||||
<input type="submit" name="bind_submit" value="Login">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user