Compare commits
4 Commits
06a97858d9
...
9fc6950664
Author | SHA1 | Date | |
---|---|---|---|
9fc6950664 | |||
eb9aef8023 | |||
1b0345374b | |||
363614659d |
@ -8,7 +8,12 @@ class UsersEndpoint extends ApiEndpoint {
|
||||
path: '/users'
|
||||
});
|
||||
|
||||
this.methods.push([ 'get', this.getUsers.bind(this), [ server.auth.createAuthoriser('administrator', 10) ]]);
|
||||
this.methods.push([ 'get', this.getUsers.bind(this) ]);
|
||||
this.subpaths = [
|
||||
[ '/:userid', 'get', this.user.bind(this) ],
|
||||
[ '/:userid/applications', 'get', this.userApplications.bind(this) ]
|
||||
];
|
||||
this.middleware = [ server.auth.createAuthoriser('administrator', 10) ];
|
||||
|
||||
}
|
||||
|
||||
@ -20,6 +25,23 @@ class UsersEndpoint extends ApiEndpoint {
|
||||
res.json(users.map(user => user.json));
|
||||
}
|
||||
|
||||
async user (req, res) {
|
||||
const { params } = req;
|
||||
const { userid } = params;
|
||||
const user = await this.server.users.fetchUser(userid);
|
||||
if (!user) return res.status(404).end();
|
||||
res.json(user);
|
||||
}
|
||||
|
||||
async userApplications (req, res) {
|
||||
const { params } = req;
|
||||
const { userid } = params;
|
||||
const user = await this.server.users.fetchUser(userid);
|
||||
if (!user) return res.status(404).send('Could not find the user');
|
||||
const applications = await user.fetchApplications();
|
||||
res.json(Object.values(applications).map(app => app.json));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = UsersEndpoint;
|
@ -87,7 +87,9 @@ class Authenticator {
|
||||
const bool = user?._2fa && !sess.verified && sess.loginMethod === 'password';
|
||||
const verifyPath = '/login/verify';
|
||||
// TODO: clean this up
|
||||
if (bool && ![ verifyPath, '/api' + verifyPath ].includes(req.originalUrl)) return res.redirect(verifyPath);
|
||||
if (bool && ![ verifyPath, '/api' + verifyPath ].includes(req.originalUrl)) {
|
||||
return res.status(401).json({ twoFactor: true }); // res.redirect(verifyPath);
|
||||
}
|
||||
next();
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,22 @@ const UserApplicataion = require('./UserApplication');
|
||||
|
||||
class User {
|
||||
|
||||
static defaultPermissions = {};
|
||||
static defaultPermissions = {
|
||||
developer: {
|
||||
default: 0
|
||||
},
|
||||
administrator: {
|
||||
default: 0
|
||||
},
|
||||
test: {
|
||||
default: 0,
|
||||
dingus: {
|
||||
bingus: {
|
||||
default: 10
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static validTypes = [];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user