From 0e5830d6f2fa19fbe7a4511404bdd22edb2f0511 Mon Sep 17 00:00:00 2001 From: Dustin Falgout Date: Sun, 6 Dec 2015 09:16:20 -0600 Subject: [PATCH] add api endpoints to get user by username and by email Signed-off-by: Dustin Falgout --- src/controllers/api.js | 48 ++++++++++++++++++++++++++++++++++++++++++ src/routes/api.js | 5 ++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/controllers/api.js b/src/controllers/api.js index 5ccedc5aeb..3d4532b1a9 100644 --- a/src/controllers/api.js +++ b/src/controllers/api.js @@ -195,6 +195,54 @@ apiController.getUserByUID = function(req, res, next) { }; +apiController.getUserByUsername = function (req, res, next) { + var username = req.params.username ? req.params.username : 0; + + async.waterfall([ + function (next) { + user.getUidByUsername(username, next); + }, + async.parallel({ + userData: async.apply(user.getUserData, uid), + settings: async.apply(user.getSettings, uid) + }, function (err, results) { + if (err || !results.userData) { + return next(err); + } + results.userData.email = results.settings.showemail ? results.userData.email : undefined; + results.userData.fullname = results.settings.showfullname ? results.userData.fullname : undefined; + + res.json(results.userData); + }) + + ], next); +}; + + +apiController.getUserByEmail = function (req, res, next) { + var email = req.params.email ? req.params.email : 0; + + async.waterfall([ + function (next) { + user.getUidByEmail(email, next); + }, + async.parallel({ + userData: async.apply(user.getUserData, uid), + settings: async.apply(user.getSettings, uid) + }, function (err, results) { + if (err || !results.userData) { + return next(err); + } + results.userData.email = results.settings.showemail ? results.userData.email : undefined; + results.userData.fullname = results.settings.showfullname ? results.userData.fullname : undefined; + + res.json(results.userData); + }) + + ], next); +}; + + apiController.getModerators = function(req, res, next) { categories.getModerators(req.params.cid, function(err, moderators) { if (err) { diff --git a/src/routes/api.js b/src/routes/api.js index c80d9507c6..34cf142b37 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -13,6 +13,9 @@ module.exports = function(app, middleware, controllers) { router.get('/widgets/render', controllers.api.renderWidgets); 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); + router.get('/:type/pid/:id', controllers.api.getObject); router.get('/:type/tid/:id', controllers.api.getObject); router.get('/:type/cid/:id', controllers.api.getObject); @@ -28,7 +31,7 @@ module.exports = function(app, middleware, controllers) { router.post('/post/upload', middlewares, uploadsController.uploadPost); router.post('/topic/thumb/upload', middlewares, uploadsController.uploadThumb); router.post('/user/:userslug/uploadpicture', middlewares.concat([middleware.authenticate, middleware.checkGlobalPrivacySettings, middleware.checkAccountPermissions]), controllers.accounts.edit.uploadPicture); - + router.post('/user/:userslug/uploadcover', middlewares.concat([middleware.authenticate, middleware.checkGlobalPrivacySettings, middleware.checkAccountPermissions]), controllers.accounts.edit.uploadCoverPicture); router.post('/groups/uploadpicture', middlewares.concat([middleware.authenticate]), controllers.groups.uploadCover); };