Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b2bf1aaf92 | |||
| 61ddd5b38f |
@@ -37,9 +37,13 @@ Content-Type: application/json
|
|||||||
"refreshToken": "fghij"
|
"refreshToken": "fghij"
|
||||||
}
|
}
|
||||||
|
|
||||||
//DOCS: Retreives the private account data, results vary
|
//Replace an expired authToken pair with these values
|
||||||
GET /auth/account
|
POST /auth/token
|
||||||
Authorization: Bearer accessToken
|
Content-Type: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"token": "refreshToken"
|
||||||
|
}
|
||||||
|
|
||||||
//DOCS: After this is called, the refresh route will no longer work
|
//DOCS: After this is called, the refresh route will no longer work
|
||||||
DELETE /auth/logout
|
DELETE /auth/logout
|
||||||
@@ -49,13 +53,9 @@ Authorization: Bearer accessToken
|
|||||||
"token": "refreshToken"
|
"token": "refreshToken"
|
||||||
}
|
}
|
||||||
|
|
||||||
//Replace an expired authToken pair with these values
|
//DOCS: Retreives the private account data, results vary
|
||||||
POST /auth/token
|
GET /auth/account
|
||||||
Content-Type: application/json
|
Authorization: Bearer accessToken
|
||||||
|
|
||||||
{
|
|
||||||
"token": "refreshToken"
|
|
||||||
}
|
|
||||||
|
|
||||||
//Result
|
//Result
|
||||||
{
|
{
|
||||||
@@ -64,12 +64,12 @@ Content-Type: application/json
|
|||||||
}
|
}
|
||||||
|
|
||||||
//DOCS: Update account data, input varies, but is always JSON
|
//DOCS: Update account data, input varies, but is always JSON
|
||||||
PATCH /auth/update
|
PATCH /auth/account
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
Authorization: Bearer accessToken
|
Authorization: Bearer accessToken
|
||||||
|
|
||||||
//DOCS: Sets the timer, account will be deleted after 2 days
|
//DOCS: Sets the timer, account will be deleted after 2 days
|
||||||
DELETE /auth/deletion
|
DELETE /auth/account
|
||||||
Authorization: Bearer accessToken
|
Authorization: Bearer accessToken
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
|
||||||
@@ -77,4 +77,13 @@ Content-Type: application/json
|
|||||||
"password": "helloworld"
|
"password": "helloworld"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//DOCS: Sets the privilege of the specified user; usable only by admins
|
||||||
|
PATCH /auth/admin/privilege
|
||||||
|
Authorization: Bearer accessToken
|
||||||
|
Content-Type: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"username": "example",
|
||||||
|
"privilege: "administrator"
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
const { accounts } = require('../database/models');
|
||||||
|
|
||||||
|
//auth/account/privilege
|
||||||
|
const route = async (req, res) => {
|
||||||
|
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;
|
||||||
+22
-3
@@ -1,3 +1,22 @@
|
|||||||
module.exports = {
|
const express = require('express');
|
||||||
defaultAccount: require('./default-account')
|
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;
|
||||||
@@ -9,11 +9,11 @@ const route = async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!account) {
|
if (!account) {
|
||||||
res.status(401).send('Unknown account');
|
return res.status(401).send('Unknown account');
|
||||||
}
|
}
|
||||||
|
|
||||||
//respond with the private-facing data
|
//respond with the private-facing data
|
||||||
res.status(200).json({
|
return res.status(200).json({
|
||||||
contact: account.contact
|
contact: account.contact
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -17,8 +17,8 @@ router.use(tokenAuth);
|
|||||||
|
|
||||||
//basic account management (needs a token)
|
//basic account management (needs a token)
|
||||||
router.delete('/logout', require('./logout'));
|
router.delete('/logout', require('./logout'));
|
||||||
router.get('/account', require('./account'));
|
router.get('/account', require('./account-query'));
|
||||||
router.patch('/update', require('./update'));
|
router.patch('/account', require('./account-update'));
|
||||||
router.delete('/deletion', require('./deletion'));
|
router.delete('/account', require('./account-delete'));
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
+2
-2
@@ -15,8 +15,8 @@ app.use(cors());
|
|||||||
//database connection
|
//database connection
|
||||||
const database = require('./database');
|
const database = require('./database');
|
||||||
|
|
||||||
const admin = require('./admin');
|
//access the admin
|
||||||
admin.defaultAccount();
|
app.use('/admin', require('./admin'));
|
||||||
|
|
||||||
//access the auth
|
//access the auth
|
||||||
app.use('/auth', require('./auth'));
|
app.use('/auth', require('./auth'));
|
||||||
|
|||||||
Reference in New Issue
Block a user