This commit is contained in:
2025-02-10 17:08:50 +01:00
parent 4827e6ae57
commit e5ffbac3ea
9 changed files with 102 additions and 9 deletions

View File

@ -1,4 +1,6 @@
const crypto = require('crypto');
const database = require("../db");
const authentication = require("../authentication");
const accountController = {
getCookie: (req, res) => {
@ -18,6 +20,24 @@ const accountController = {
console.log("cookie set");
}
res.redirect('/');
},
register: async (req, res) => {
try {
const { sharedSecret, publicKey } = req.body;
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);
} else {
return res.status(400).json({ error: "Wrong sharedSecret" });
}
return res.status(201).json({ message: "Registration successful" });
} catch (error) {
console.error("Error during registration:", error);
return res.status(500).json({ error: "Server error during registration" });
}
}
};