register
This commit is contained in:
@ -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" });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user