Ripped out the pseudonym reserve system

Moving to JWT tokens in future
This commit is contained in:
2021-03-08 11:44:12 +11:00
parent 2667af503e
commit 3e31429a4f
10 changed files with 17 additions and 110 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
const express = require('express');
const router = express.Router();
//reserve the name using a pseudonym
router.post('/reserve', require('./reserve'));
//basic route management
//TODO: import the routes
module.exports = router;
-39
View File
@@ -1,39 +0,0 @@
const crypto = require("crypto");
const Sequelize = require('sequelize');
const Op = Sequelize.Op;
const { pseudonyms } = require('../database/models');
const route = async (req, res) => {
//check the key
if (req.fields.key != process.env.CHAT_KEY) {
return res.status(403).send('Invalid chat key');
}
//generate a UUID to act as a pseudonym (starting with a period)
const pseudonym = `.${uuid()}`;
//find or create the record (using the username)
const [instance, created] = await pseudonyms.findOrCreate({
where: {
username: req.fields.username
}
});
//save the pseudonym (overwriting existing pseudonyms)
const result = await pseudonyms.update({
pseudonym: pseudonym
},{
where: {
username: instance.username
}
});
//OK
return res.status(200).send({ pseudonym: pseudonym });
};
//lazy
const uuid = (bytes = 16) => crypto.randomBytes(bytes).toString("hex");
module.exports = route;