Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 61ddd5b38f |
@@ -77,4 +77,13 @@ Content-Type: application/json
|
||||
"password": "helloworld"
|
||||
}
|
||||
|
||||
//DOCS: Sets the privilege of the specified user; usable only by admins
|
||||
DELETE /auth/deletion
|
||||
Authorization: Bearer accessToken
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"username": "example",
|
||||
"privilege: "administrator"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
const { accounts } = require('../database/models');
|
||||
|
||||
//auth/account/privilege
|
||||
const route = async (req, res) => {
|
||||
//check the user's privilege
|
||||
if (req.user.privilege != 'administrator') {
|
||||
return res.status(401).send('Only admins can change privilege');
|
||||
}
|
||||
|
||||
const updated = await accounts.update({
|
||||
privilege: req.body.privilege
|
||||
}, {
|
||||
where: {
|
||||
username: req.body.username
|
||||
}
|
||||
});
|
||||
|
||||
if (updated < 1) {
|
||||
return res.status(403).send(`Unknown account`);
|
||||
}
|
||||
|
||||
return res.status(200).end();
|
||||
};
|
||||
|
||||
module.exports = route;
|
||||
@@ -9,11 +9,11 @@ const route = async (req, res) => {
|
||||
});
|
||||
|
||||
if (!account) {
|
||||
res.status(401).send('Unknown account');
|
||||
return res.status(401).send('Unknown account');
|
||||
}
|
||||
|
||||
//respond with the private-facing data
|
||||
res.status(200).json({
|
||||
return res.status(200).json({
|
||||
contact: account.contact
|
||||
});
|
||||
};
|
||||
|
||||
@@ -21,4 +21,6 @@ router.get('/account', require('./account'));
|
||||
router.patch('/update', require('./update'));
|
||||
router.delete('/deletion', require('./deletion'));
|
||||
|
||||
router.patch('/account/privilege', require('./account-privilege'));
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user