connect to socket on login
This commit is contained in:
@@ -1,26 +1,9 @@
|
||||
const crypto = require('crypto');
|
||||
const database = require("../db");
|
||||
const authentication = require("../authentication");
|
||||
const socket = require('../socket').default;
|
||||
|
||||
const accountController = {
|
||||
getCookie: (req, res) => {
|
||||
console.log("site loaded")
|
||||
console.log(req.cookies)
|
||||
let cookie = req.cookies.user;
|
||||
if (!cookie) {
|
||||
//crypto.randomBytes() instead of Math.random() for cryptographically secure random numbers
|
||||
let randomBuffer = crypto.randomBytes(16); // 128bits of entropy
|
||||
let randomNumber = randomBuffer.toString('hex');
|
||||
let options = {
|
||||
maxAge: 86400000, // 1 day
|
||||
httpOnly: true
|
||||
}
|
||||
// Set cookie
|
||||
res.cookie("user", randomNumber, options);
|
||||
console.log("cookie set");
|
||||
}
|
||||
res.redirect('/');
|
||||
},
|
||||
register: async (req, res) => {
|
||||
try {
|
||||
const { sharedSecret, publicKey } = req.body;
|
||||
@@ -40,6 +23,7 @@ const accountController = {
|
||||
}
|
||||
},
|
||||
loginGetChallenge: async (req, res) => {
|
||||
//crypto.randomBytes() instead of Math.random() for cryptographically secure random numbers
|
||||
let randomBuffer = crypto.randomBytes(16);
|
||||
let randomNumber = randomBuffer.toString('hex');
|
||||
req.session.randomNumber = randomNumber;
|
||||
@@ -56,6 +40,8 @@ const accountController = {
|
||||
let validKey = authentication.verifySignature(msg, sig, publicKeys);
|
||||
if (validKey !== null) {
|
||||
req.session.publicKey = validKey;
|
||||
socket.auth = { validKey };
|
||||
socket.connect();
|
||||
return res.status(200).json({ message: "Challenge solved successfully" });
|
||||
} else {
|
||||
return res.status(400).json({ error: "Challenge failed" });
|
||||
|
||||
0
src/controllers/chat.js
Normal file
0
src/controllers/chat.js
Normal file
@@ -3,7 +3,6 @@ const path = require('path');
|
||||
const mainController = {
|
||||
root: (req, res) => {
|
||||
let pubKey = req.session.publicKey;
|
||||
console.log(pubKey);
|
||||
let isLoggedIn = typeof pubKey !== 'undefined';
|
||||
res.render('index', {isLoggedIn, pubKey});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user