change representation of public key in db to hex string + create room
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const crypto = require('crypto');
|
||||
const database = require("../db");
|
||||
const stringutils = require("../stringutils");
|
||||
const authentication = require("../authentication");
|
||||
const socket = require('../socket').default;
|
||||
|
||||
@@ -10,9 +11,9 @@ const accountController = {
|
||||
if (!sharedSecret || !publicKey) {
|
||||
return res.status(400).json({ error: "Missing sharedSecret or publicKey" });
|
||||
}
|
||||
console.log('Received data:', { sharedSecret, publicKey });
|
||||
if (authentication.checkSharedSecret(sharedSecret)) {
|
||||
database.addUser(publicKey);
|
||||
let pubkey = stringutils.pemToHex(publicKey)
|
||||
database.addUser(pubkey);
|
||||
} else {
|
||||
return res.status(400).json({ error: "Wrong sharedSecret" });
|
||||
}
|
||||
|
||||
@@ -1 +1,20 @@
|
||||
const database = require("../db");
|
||||
const stringutils = require("../stringutils");
|
||||
|
||||
const chatController = {
|
||||
add: async (req, res) => {
|
||||
try {
|
||||
const { pubkey } = req.body;
|
||||
if (!pubkey) {
|
||||
return res.status(400).json({ error: "Missing publicKey" });
|
||||
}
|
||||
await database.createRoom(req.session.publicKey, stringutils.pemToHex(pubkey));
|
||||
return res.status(201).json({ message: "Room created successfully." });
|
||||
} catch (error) {
|
||||
console.error("Error creating the room:", error);
|
||||
return res.status(500).json({ error: "Failed to create the room" });
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
module.exports = chatController;
|
||||
|
||||
@@ -1,39 +1,13 @@
|
||||
const path = require('path');
|
||||
const stringutils = require("../stringutils");
|
||||
|
||||
const mainController = {
|
||||
root: (req, res) => {
|
||||
let pubKey = req.session.publicKey;
|
||||
console.log(pubKey);
|
||||
let isLoggedIn = typeof pubKey !== 'undefined';
|
||||
let pubKeyHex = req.session.publicKey;
|
||||
let isLoggedIn = typeof pubKeyHex !== 'undefined';
|
||||
let pubKey = isLoggedIn ? stringutils.hexToPem(pubKeyHex).replaceAll('\n','') : null;
|
||||
res.render('index', {isLoggedIn, pubKey});
|
||||
},
|
||||
// style: (req, res) => {
|
||||
// res.sendFile(path.resolve(__dirname + '/../public/style.css'));
|
||||
// },
|
||||
// script: (req, res) => {
|
||||
// res.sendFile(path.resolve(__dirname + '/../public/script.js'));
|
||||
// },
|
||||
// ecc: (req, res) => {
|
||||
// res.sendFile(path.resolve(__dirname + '/../public/ecc.js'));
|
||||
// },
|
||||
// ecdh: (req, res) => {
|
||||
// res.sendFile(path.resolve(__dirname + '/../public/ecdh.js'));
|
||||
// },
|
||||
// popups: (req, res) => {
|
||||
// res.sendFile(path.resolve(__dirname + '/../public/popups.js'));
|
||||
// },
|
||||
// chat : (req, res) => {
|
||||
// res.sendFile(path.resolve(__dirname + '/../public/chat.js'));
|
||||
// },
|
||||
// register : (req, res) => {
|
||||
// res.sendFile(path.resolve(__dirname + '/../public/register.js'));
|
||||
// },
|
||||
// pubkey : (req, res) => {
|
||||
// res.sendFile(path.resolve(__dirname + '/../public/pubkey.js'));
|
||||
// },
|
||||
// registertext : (req, res) => {
|
||||
// res.sendFile(path.resolve(__dirname + '/../public/registertext.js'));
|
||||
// }
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = mainController;
|
||||
|
||||
Reference in New Issue
Block a user