diff --git a/src/controllers/api.js b/src/controllers/api.js index 73d98842b2..993d07976a 100644 --- a/src/controllers/api.js +++ b/src/controllers/api.js @@ -12,6 +12,7 @@ var categories = require('../categories'); var privileges = require('../privileges'); var plugins = require('../plugins'); var widgets = require('../widgets'); +var accountHelpers = require('../controllers/accounts/helpers'); var apiController = {}; @@ -218,6 +219,22 @@ apiController.getObject = function(req, res, next) { }); }; +apiController.getCurrentUser = function(req, res, next) { + async.waterfall([ + function(next) { + user.getUserField(req.uid, 'userslug', next); + }, + function(userslug, next) { + accountHelpers.getUserDataByUserSlug(userslug, req.uid, next); + } + ], function(err, userData) { + if (err) { + return next(err); + } + res.json(userData); + }); +}; + apiController.getUserByUID = function(req, res, next) { byType('uid', req, res, next); }; diff --git a/src/routes/api.js b/src/routes/api.js index 1a84f59c3a..ee983f1cd5 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -12,6 +12,7 @@ module.exports = function(app, middleware, controllers) { router.get('/config', middleware.applyCSRF, controllers.api.getConfig); router.get('/widgets/render', controllers.api.renderWidgets); + router.get('/me', middleware.checkGlobalPrivacySettings, controllers.api.getCurrentUser); router.get('/user/uid/:uid', middleware.checkGlobalPrivacySettings, controllers.api.getUserByUID); router.get('/user/username/:username', middleware.checkGlobalPrivacySettings, controllers.api.getUserByUsername); router.get('/user/email/:email', middleware.checkGlobalPrivacySettings, controllers.api.getUserByEmail);