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;
+1 -1
View File
@@ -1,3 +1,3 @@
module.exports = {
pseudonyms: require('./pseudonyms')
//TODO: models
};
-28
View File
@@ -1,28 +0,0 @@
const Sequelize = require('sequelize');
const sequelize = require('..');
module.exports = sequelize.define('pseudonyms', {
id: {
type: Sequelize.INTEGER(11),
allowNull: false,
autoIncrement: true,
primaryKey: true,
unique: true
},
username: {
type: 'varchar(320)',
unique: true
},
pseudonym: {
type: 'varchar(320)',
unique: true
},
deletion: {
type: 'DATETIME',
allowNull: true,
defaultValue: null
}
});
+3 -4
View File
@@ -5,12 +5,10 @@ require('dotenv').config();
const express = require('express');
const app = express();
const server = require('http').Server(app);
const formidable = require('express-formidable');
const bodyParser = require('body-parser');
const cors = require('cors');
//config
app.use(formidable());
app.use(bodyParser.json());
app.use(cors());
@@ -26,6 +24,7 @@ app.get('*', (req, res) => {
});
//startup
server.listen(process.env.WEB_PORT || 3200, (err) => {
console.log(`listening to localhost:${process.env.WEB_PORT || 3200}`);
server.listen(process.env.WEB_PORT || 3300, async (err) => {
await database.sync();
console.log(`listening to localhost:${process.env.WEB_PORT || 3300}`);
});