mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-06 23:52:58 +01:00
added helpers.redirect
This commit is contained in:
@@ -200,8 +200,7 @@ categoriesController.get = function(req, res, next) {
|
||||
var topicCount = parseInt(results.categoryData.topic_count, 10);
|
||||
|
||||
if (topicIndex < 0 || topicIndex > Math.max(topicCount - 1, 0)) {
|
||||
var url = '/category/' + cid + '/' + req.params.slug + (topicIndex > topicCount ? '/' + topicCount : '');
|
||||
return res.locals.isAPI ? res.status(302).json(url) : res.redirect(url);
|
||||
return helpers.redirect(res, '/category/' + cid + '/' + req.params.slug + (topicIndex > topicCount ? '/' + topicCount : ''));
|
||||
}
|
||||
|
||||
userPrivileges = results.privileges;
|
||||
|
||||
@@ -51,31 +51,35 @@ groupsController.details = function(req, res, next) {
|
||||
}
|
||||
}
|
||||
], function(err, ok) {
|
||||
if (ok) {
|
||||
async.parallel({
|
||||
group: function(next) {
|
||||
groups.get(res.locals.groupName, {
|
||||
expand: true,
|
||||
uid: uid
|
||||
}, next);
|
||||
},
|
||||
posts: function(next) {
|
||||
groups.getLatestMemberPosts(res.locals.groupName, 10, uid, next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (!results.group) {
|
||||
return helpers.notFound(req, res);
|
||||
}
|
||||
|
||||
res.render('groups/details', results);
|
||||
});
|
||||
} else {
|
||||
return res.locals.isAPI ? res.status(302).json('/groups') : res.redirect('/groups');
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
return helpers.redirect(res, '/groups');
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
group: function(next) {
|
||||
groups.get(res.locals.groupName, {
|
||||
expand: true,
|
||||
uid: uid
|
||||
}, next);
|
||||
},
|
||||
posts: function(next) {
|
||||
groups.getLatestMemberPosts(res.locals.groupName, 10, uid, next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (!results.group) {
|
||||
return helpers.notFound(req, res);
|
||||
}
|
||||
|
||||
res.render('groups/details', results);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -45,6 +45,14 @@ helpers.notAllowed = function(req, res, error) {
|
||||
}
|
||||
};
|
||||
|
||||
helpers.redirect = function(res, url) {
|
||||
if (res.locals.isAPI) {
|
||||
res.status(302).json(url);
|
||||
} else {
|
||||
res.redirect(url);
|
||||
}
|
||||
};
|
||||
|
||||
helpers.buildCategoryBreadcrumbs = function(cid, callback) {
|
||||
var breadcrumbs = [];
|
||||
|
||||
|
||||
@@ -56,12 +56,8 @@ topicsController.get = function(req, res, next) {
|
||||
var postCount = parseInt(results.topic.postcount, 10);
|
||||
var pageCount = Math.max(1, Math.ceil((postCount - 1) / settings.postsPerPage));
|
||||
|
||||
if (utils.isNumber(req.params.post_index)) {
|
||||
var url = '';
|
||||
if (req.params.post_index < 1 || req.params.post_index > postCount) {
|
||||
url = '/topic/' + req.params.topic_id + '/' + req.params.slug + (req.params.post_index > postCount ? '/' + postCount : '');
|
||||
return res.locals.isAPI ? res.status(302).json(url) : res.redirect(url);
|
||||
}
|
||||
if (utils.isNumber(req.params.post_index) && (req.params.post_index < 1 || req.params.post_index > postCount)) {
|
||||
return helpers.redirect(res, '/topic/' + req.params.topic_id + '/' + req.params.slug + (req.params.post_index > postCount ? '/' + postCount : ''));
|
||||
}
|
||||
|
||||
if (settings.usePagination && (req.query.page < 1 || req.query.page > pageCount)) {
|
||||
@@ -266,7 +262,7 @@ topicsController.get = function(req, res, next) {
|
||||
});
|
||||
|
||||
topics.increaseViewCount(tid);
|
||||
|
||||
|
||||
plugins.fireHook('filter:topic.build', {req: req, res: res, templateData: data}, function(err, data) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
|
||||
@@ -60,12 +60,7 @@ middleware.redirectToAccountIfLoggedIn = function(req, res, next) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (res.locals.isAPI) {
|
||||
res.status(302).json(nconf.get('relative_path') + '/user/' + userslug);
|
||||
} else {
|
||||
res.redirect(nconf.get('relative_path') + '/user/' + userslug);
|
||||
}
|
||||
helpers.redirect(res, '/user/' + userslug);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -85,13 +80,7 @@ middleware.addSlug = function(req, res, next) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
var url = nconf.get('relative_path') + name + encodeURI(slug);
|
||||
|
||||
if (res.locals.isAPI) {
|
||||
res.status(302).json(url);
|
||||
} else {
|
||||
res.redirect(url);
|
||||
}
|
||||
helpers.redirect(res, name + encodeURI(slug));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -218,7 +218,7 @@ function handleErrors(app, middleware) {
|
||||
}
|
||||
|
||||
if (parseInt(err.status, 10) === 302 && err.path) {
|
||||
return res.locals.isAPI ? res.status(302).json(err) : res.redirect(err.path);
|
||||
return res.locals.isAPI ? res.status(302).json(err.path) : res.redirect(err.path);
|
||||
}
|
||||
|
||||
res.status(err.status || 500);
|
||||
|
||||
Reference in New Issue
Block a user