1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-11-27 21:19:09 -05:00

Add users api route

This commit is contained in:
Jack Foltz 2018-01-15 11:45:52 -05:00
parent 8ec7973925
commit c2916b7f6d
Signed by: foltik
GPG Key ID: 303F88F996E95541
2 changed files with 35 additions and 0 deletions

View File

@ -8,6 +8,7 @@ var login = require('./login.js');
var panel = require('./panel.js');
var keys = require('./keys.js');
var invites = require('./invites.js');
var users = require('./users.js');
var Key = require('../models/Key.js');
@ -50,6 +51,7 @@ module.exports = function (app) {
app.use('/api/auth', auth);
app.use('/api/keys', requireLogin, keys);
app.use('/api/invites', requireLogin, invites);
app.use('/api/users', requireLogin, users);
app.use('/register', register);
app.use('/login', login);
app.use('/panel', requireLogin, panel);

33
app/routes/users.js Normal file
View File

@ -0,0 +1,33 @@
var express = require('express');
var router = express.Router();
var User = require('../models/User.js');
var requireScope = function (perm) {
return function(req, res, next) {
User.findOne({username: req.session.passport.user}, function(err, user) {
if (err) throw err;
if (user.scope.indexOf(perm) === -1)
res.status(400).json({'message': 'No permission.'});
else
next();
});
}
};
router.get('/get', requireScope('users.view'), function (req, res, next) {
var query = {};
if (req.body.username)
query.username = req.body.username;
User.find(query, function (err, users) {
if (err) {
next(err)
} else {
res.status(200).json(users);
}
})
});
module.exports = router;