pug template engine
This commit is contained in:
parent
cc1767e0d0
commit
b547fc3b5e
@ -15,6 +15,7 @@
|
|||||||
"express": "^4.21.2",
|
"express": "^4.21.2",
|
||||||
"express-session": "^1.18.1",
|
"express-session": "^1.18.1",
|
||||||
"pg": "^8.13.1",
|
"pg": "^8.13.1",
|
||||||
|
"pug": "^3.0.3",
|
||||||
"socket.io": "^4.8.1"
|
"socket.io": "^4.8.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -18,6 +18,8 @@ const SQLiteStore = require('connect-sqlite3')(session);
|
|||||||
|
|
||||||
// configure app
|
// configure app
|
||||||
app.set("port", port);
|
app.set("port", port);
|
||||||
|
app.set('view engine', 'pug');
|
||||||
|
app.set('views', __dirname + '/views');
|
||||||
app.use(cookieParser());
|
app.use(cookieParser());
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(session({
|
app.use(session({
|
||||||
@ -27,6 +29,7 @@ app.use(session({
|
|||||||
saveUninitialized: true,
|
saveUninitialized: true,
|
||||||
cookie: { maxAge: 7 * 24 * 60 * 60 * 1000 } // 1 week
|
cookie: { maxAge: 7 * 24 * 60 * 60 * 1000 } // 1 week
|
||||||
}));
|
}));
|
||||||
|
|
||||||
app.use("/", routes);
|
app.use("/", routes);
|
||||||
// bootstrap
|
// bootstrap
|
||||||
app.use('/css', express.static(__dirname + '/node_modules/bootstrap/dist/css'));
|
app.use('/css', express.static(__dirname + '/node_modules/bootstrap/dist/css'));
|
||||||
|
@ -55,10 +55,16 @@ const accountController = {
|
|||||||
const sig = new TextEncoder().encode(signature);
|
const sig = new TextEncoder().encode(signature);
|
||||||
let validKey = authentication.verifySignature(msg, sig, publicKeys);
|
let validKey = authentication.verifySignature(msg, sig, publicKeys);
|
||||||
if (validKey !== null) {
|
if (validKey !== null) {
|
||||||
|
req.session.publicKey = validKey;
|
||||||
return res.status(200).json({ message: "Challenge solved successfully" });
|
return res.status(200).json({ message: "Challenge solved successfully" });
|
||||||
} else {
|
} else {
|
||||||
return res.status(400).json({ error: "Challenge failed" });
|
return res.status(400).json({ error: "Challenge failed" });
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
getPublicKey: (req, res) => {
|
||||||
|
if (req.session.publicKey != null) {
|
||||||
|
return res.status(200).json({ publicKey: req.session.publicKey });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,21 +1,26 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const mainController = {
|
const mainController = {
|
||||||
root: (req, res) => {
|
root: (req, res) => {
|
||||||
res.sendFile(path.resolve(__dirname + '/../public/index.html'));
|
if (typeof req.session.publicKey === 'undefined') {
|
||||||
},
|
// main page when not logged in
|
||||||
style: (req, res) => {
|
res.render('index');
|
||||||
res.sendFile(path.resolve(__dirname + '/../public/style.css'));
|
} else {
|
||||||
},
|
res.render('index');
|
||||||
script: (req, res) => {
|
}
|
||||||
res.sendFile(path.resolve(__dirname + '/../public/script.js'));
|
},
|
||||||
},
|
style: (req, res) => {
|
||||||
ecc: (req, res) => {
|
res.sendFile(path.resolve(__dirname + '/../public/style.css'));
|
||||||
res.sendFile(path.resolve(__dirname + '/../public/ecc.js'));
|
},
|
||||||
},
|
script: (req, res) => {
|
||||||
popups: (req, res) => {
|
res.sendFile(path.resolve(__dirname + '/../public/script.js'));
|
||||||
res.sendFile(path.resolve(__dirname + '/../public/popups.js'));
|
},
|
||||||
}
|
ecc: (req, res) => {
|
||||||
|
res.sendFile(path.resolve(__dirname + '/../public/ecc.js'));
|
||||||
|
},
|
||||||
|
popups: (req, res) => {
|
||||||
|
res.sendFile(path.resolve(__dirname + '/../public/popups.js'));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = mainController;
|
module.exports = mainController;
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en-US">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<link rel="stylesheet" href="/style.css">
|
|
||||||
<script src="/socket.io/socket.io.js" defer></script>
|
|
||||||
<script src="/script.js" defer></script>
|
|
||||||
<script type="module" src="/ecc.js" defer></script>
|
|
||||||
<script type="module" src="/popups.js" defer></script>
|
|
||||||
<!--load bootstrap-->
|
|
||||||
<link rel="stylesheet" href="/css/bootstrap.min.css" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="mainbody">
|
|
||||||
<div id="jswarn"> Please enable Javascript to use this app. </div>
|
|
||||||
<div class="btn-toolbar btn-group-sm" role="toolbar" aria-label="Toolbar">
|
|
||||||
<div class="btn-group mr-2" role="group" aria-label="register">
|
|
||||||
<button id="register" class="btn btn-secondary" type="button">register</button>
|
|
||||||
<button id="login" class="btn btn-secondary" type="button">login</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div id="registerPopup" class="popup">
|
|
||||||
<div class="popup-content">
|
|
||||||
<div class="btn-group mr-2 w-100" role="group" aria-label="Add group">
|
|
||||||
<input id="sharedsecret" type="password" class="form-control input-sm w-50" placeholder="shared secret" required>
|
|
||||||
<input id="publickey" type="text" class="form-control input-sm w-50" placeholder="public key">
|
|
||||||
<button id="registerconfirm" class="btn btn-secondary" type="button">register</button>
|
|
||||||
<button id="registercancel" class="btn btn-secondary" type="button">cancel</button>
|
|
||||||
</div>
|
|
||||||
<div id="registerPopupText"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div id="loginPopup" class="popup">
|
|
||||||
<div class="popup-content">
|
|
||||||
<div class="btn-group mr-2 w-100" role="group" aria-label="Add group">
|
|
||||||
<input id="privatekey" type="password" class="form-control input-sm w-50" placeholder="private key" required>
|
|
||||||
<button id="loginconfirm" class="btn btn-secondary" type="button">login</button>
|
|
||||||
<button id="logincancel" class="btn btn-secondary" type="button">cancel</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<a href="./account/cookie" class="btn btn-primary">Get cookie</a>
|
|
||||||
<ul id="messages"></ul>
|
|
||||||
<form id="form" action="">
|
|
||||||
<input id="input" autocomplete="off" />
|
|
||||||
<button>Send</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -15,7 +15,11 @@ router
|
|||||||
.get(accountController.loginGetChallenge);
|
.get(accountController.loginGetChallenge);
|
||||||
|
|
||||||
router
|
router
|
||||||
.route("/verify-challenge")
|
.route("/verify-challenge")
|
||||||
.post(accountController.loginVerifyChallenge);
|
.post(accountController.loginVerifyChallenge);
|
||||||
|
|
||||||
|
router
|
||||||
|
.route("/get-public-key")
|
||||||
|
.get(accountController.getPublicKey);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
44
src/views/index.pug
Normal file
44
src/views/index.pug
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
doctype html
|
||||||
|
html(lang="en-US")
|
||||||
|
head
|
||||||
|
meta(charset="UTF-8")
|
||||||
|
meta(http-equiv="X-UA-Compatible" content="IE=edge")
|
||||||
|
meta(name="viewport" content="width=device-width, initial-scale=1")
|
||||||
|
link(rel="stylesheet" href="/style.css")
|
||||||
|
script(src="/socket.io/socket.io.js", defer)
|
||||||
|
script(src="/script.js", defer)
|
||||||
|
script(type="module", src="/ecc.js", defer)
|
||||||
|
script(type="module", src="/popups.js", defer)
|
||||||
|
link(rel="stylesheet" href="/css/bootstrap.min.css")
|
||||||
|
body
|
||||||
|
#mainbody
|
||||||
|
#jswarn Please enable Javascript to use this app.
|
||||||
|
|
||||||
|
.btn-toolbar.btn-group-sm(role="toolbar", aria-label="Toolbar")
|
||||||
|
.btn-group.mr-2(role="group", aria-label="register")
|
||||||
|
button#register.btn.btn-secondary(type="button") register
|
||||||
|
button#login.btn.btn-secondary(type="button") login
|
||||||
|
|
||||||
|
#registerPopup.popup
|
||||||
|
.popup-content
|
||||||
|
.btn-group.mr-2.w-100(role="group", aria-label="Add group")
|
||||||
|
input#sharedsecret.form-control.input-sm.w-50(type="password", placeholder="shared secret", required)
|
||||||
|
input#publickey.form-control.input-sm.w-50(type="text", placeholder="public key")
|
||||||
|
button#registerconfirm.btn.btn-secondary(type="button") register
|
||||||
|
button#registercancel.btn.btn-secondary(type="button") cancel
|
||||||
|
#registerPopupText
|
||||||
|
|
||||||
|
#loginPopup.popup
|
||||||
|
.popup-content
|
||||||
|
.btn-group.mr-2.w-100(role="group", aria-label="Add group")
|
||||||
|
input#privatekey.form-control.input-sm.w-50(type="password", placeholder="private key", required)
|
||||||
|
button#loginconfirm.btn.btn-secondary(type="button") login
|
||||||
|
button#logincancel.btn.btn-secondary(type="button") cancel
|
||||||
|
|
||||||
|
a.btn.btn-primary(href="./account/cookie") Get cookie
|
||||||
|
|
||||||
|
ul#messages
|
||||||
|
|
||||||
|
form#form(action="")
|
||||||
|
input#input(autocomplete="off")
|
||||||
|
button Send
|
Loading…
x
Reference in New Issue
Block a user