Compare commits

...

4 Commits

3 changed files with 42 additions and 3 deletions

View File

@ -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;

View File

@ -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();
}

View File

@ -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 = [];