Add /me* route which redirects to /user/[userslug]* (#6063)

* Add `/me*` route which redirects to the current user's information

- `/me` -> `/user/[usertslug]`
- `/me/bookmarks` -> `/user/[userslug]/bookmarks`
- `/me/settings` -> `/user/[userslug]/settings`

etc

* Add tests for `/me/*`
This commit is contained in:
Peter Jaszkowiak
2017-11-16 15:38:26 -07:00
committed by Barış Soner Uşaklı
parent 643008041c
commit f5385e38bf
4 changed files with 49 additions and 2 deletions

View File

@@ -140,6 +140,22 @@ module.exports = function (middleware) {
], next);
};
middleware.redirectMeToUserslug = function (req, res, next) {
var uid = req.uid;
async.waterfall([
function (next) {
user.getUserField(uid, 'userslug', next);
},
function (userslug) {
if (!userslug) {
return res.status(401).send('not-authorized');
}
var path = req.path.replace(/^(\/api)?\/me/, '/user/' + userslug);
controllers.helpers.redirect(res, path);
},
], next);
};
middleware.isAdmin = function (req, res, next) {
async.waterfall([
function (next) {