Compare commits

..

1 Commits

Author SHA1 Message Date
Kayne Ruse b2bf1aaf92 Altered API, read more
I moved /auth/account/privilege to /admin/privilege

I also fixed PATCH and DELETE on /account
2021-03-14 04:35:03 +11:00
8 changed files with 40 additions and 28 deletions
+13 -13
View File
@@ -37,9 +37,13 @@ Content-Type: application/json
"refreshToken": "fghij"
}
//DOCS: Retreives the private account data, results vary
GET /auth/account
Authorization: Bearer accessToken
//Replace an expired authToken pair with these values
POST /auth/token
Content-Type: application/json
{
"token": "refreshToken"
}
//DOCS: After this is called, the refresh route will no longer work
DELETE /auth/logout
@@ -49,13 +53,9 @@ Authorization: Bearer accessToken
"token": "refreshToken"
}
//Replace an expired authToken pair with these values
POST /auth/token
Content-Type: application/json
{
"token": "refreshToken"
}
//DOCS: Retreives the private account data, results vary
GET /auth/account
Authorization: Bearer accessToken
//Result
{
@@ -64,12 +64,12 @@ Content-Type: application/json
}
//DOCS: Update account data, input varies, but is always JSON
PATCH /auth/update
PATCH /auth/account
Content-Type: application/json
Authorization: Bearer accessToken
//DOCS: Sets the timer, account will be deleted after 2 days
DELETE /auth/deletion
DELETE /auth/account
Authorization: Bearer accessToken
Content-Type: application/json
@@ -78,7 +78,7 @@ Content-Type: application/json
}
//DOCS: Sets the privilege of the specified user; usable only by admins
DELETE /auth/deletion
PATCH /auth/admin/privilege
Authorization: Bearer accessToken
Content-Type: application/json
@@ -2,11 +2,6 @@ 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
}, {
+22 -3
View File
@@ -1,3 +1,22 @@
module.exports = {
defaultAccount: require('./default-account')
};
const express = require('express');
const router = express.Router();
//middleware
const tokenAuth = require('../utilities/token-auth');
router.use(tokenAuth);
router.use((req, res, next) => {
//check the user's privilege
if (req.user.privilege != 'administrator') {
return res.status(401).send('Admins only');
}
next();
});
require('./default-account')(); //generate the default accouunt
//basic route management
router.patch('/privilege', require('./account-privilege'));
module.exports = router;
+3 -5
View File
@@ -17,10 +17,8 @@ router.use(tokenAuth);
//basic account management (needs a token)
router.delete('/logout', require('./logout'));
router.get('/account', require('./account'));
router.patch('/update', require('./update'));
router.delete('/deletion', require('./deletion'));
router.patch('/account/privilege', require('./account-privilege'));
router.get('/account', require('./account-query'));
router.patch('/account', require('./account-update'));
router.delete('/account', require('./account-delete'));
module.exports = router;
+2 -2
View File
@@ -15,8 +15,8 @@ app.use(cors());
//database connection
const database = require('./database');
const admin = require('./admin');
admin.defaultAccount();
//access the admin
app.use('/admin', require('./admin'));
//access the auth
app.use('/auth', require('./auth'));