Skip to content

Commit

Permalink
createAccount endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Ianyourgod committed Mar 6, 2024
1 parent c9e7a17 commit 820ccda
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions api/v1/routes/users/createAccount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = (app, utils) => {
app.get("/api/v1/users/createAccount", async function (req, res) {
const packet = req.query;
if (!packet.username || !packet.password) {
utils.error(res, 400, "InvalidData");
return;
}

// TODO: this is currently pretty basic. we should add a few more requirements
if (packet.username.length < 3 || packet.username.length > 20) {
utils.error(res, 400, "InvalidData");
return;
}

if (packet.password.length < 6 || packet.password.length > 20) {
utils.error(res, 400, "InvalidData");
return;
}

if (await utils.UserManager.accountExists(packet.username)) {
utils.error(res, 400, "AccountExists");
return;
}

let token = await utils.UserManager.createAccount(packet.username, packet.password);
res.status(200);
res.header("Content-Type", 'application/json');
res.json({ "token": token });
});
}

0 comments on commit 820ccda

Please sign in to comment.