user signup

This commit is contained in:
2026-03-19 00:03:54 +00:00
parent 7b9c212c0e
commit 00d9d4023c
3 changed files with 23 additions and 13 deletions

Binary file not shown.

View File

@@ -36,9 +36,20 @@ app.get('/getRooms', (req, res) => {
// res has success or faliure
});
app.get('/createUser', (req, res) => {
app.post('/createUser', async (req, res) => {
// req has email pass(hashed) and name
// res has success or fail
const body = req.body;
let stmt = db.prepare(`SELECT * FROM Users WHERE Email='${body.email}';`);
let storedRecord = stmt.get();
if (storedRecord) {
res.status(400).send("account with that email already exists");
return;
}
const generatedHash = await bcrypt.hash(body.pass, 10);
stmt = db.prepare(`INSERT INTO Users (Email, Pass, Username, Submissions) VALUES ('${body.email}', '${generatedHash}', '${body.name}', 0)`);
stmt.run();
res.status(200).send("account created");
});
app.post('/login', async (req, res) => {
@@ -60,13 +71,4 @@ app.post('/login', async (req, res) => {
app.listen(port, () => {
console.log(`Listening on ${port}`);
// db = openDb();
// console.log("db opened");
});
// async function openDb () {
// return open({
// filename: '/tmp/database.db',
// driver: sqlite3.Database
// })
// }