Now we can check if user is admin. This has to be set manually and now only is used for fetching torrents.

This commit is contained in:
2018-03-06 19:12:21 +01:00
parent 08b373cba0
commit e6a8515432
2 changed files with 27 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ CREATE TABLE IF NOT EXISTS user (
user_name varchar(127) UNIQUE,
password varchar(127),
email varchar(127) UNIQUE,
admin boolean DEFAULT 0,
primary key (user_name)
);

View File

@@ -0,0 +1,26 @@
const establishedDatabase = require('src/database/database');
const mustBeAdmin = (req, res, next) => {
let database = establishedDatabase;
if (req.loggedInUser === undefined) {
return res.status(401).send({
success: false,
error: 'You must be logged in.',
});
} else {
database.get(`SELECT admin FROM user WHERE user_name IS ?`, req.loggedInUser.username)
.then((isAdmin) => {
if (isAdmin.admin == 0) {
return res.status(401).send({
success: false,
error: 'You must be logged in as a admin.'
})
}
})
}
return next();
};
module.exports = mustBeAdmin;