search and reset routes, the very last of the views to be refactored :shipit:

v1.18.x
psychobunny 11 years ago
parent 8802fc5a33
commit c24c2a5422

@ -88,6 +88,34 @@ Controllers.home = function(req, res, next) {
});
};
Controllers.search = function(req, res, next) {
var data = {
show_no_topics: 'hide',
show_no_posts: 'hide',
show_results: 'hide',
search_query: '',
posts: [],
topics: []
};
if (res.locals.isAPI) {
res.json(data);
} else {
res.render('search', data);
}
};
Controllers.reset = function(req, res, next) {
var data = {
reset_code: req.params.code ? req.params.code : null
}
if (res.locals.isAPI) {
res.json(data);
} else {
res.render('reset', data);
}
};
Controllers.login = function(req, res, next) {
var data = {},

@ -46,6 +46,12 @@ middleware.prepareAPI = function(req, res, next) {
next();
};
middleware.guestSearchingAllowed = function(req, res, next) {
if (!req.user && meta.config.allowGuestSearching !== '1') {
return res.redirect('/403');
}
};
middleware.checkGlobalPrivacySettings = function(req, res, next) {
var callerUID = req.user ? parseInt(req.user.uid, 10) : 0;

@ -40,6 +40,12 @@ module.exports = function(app, middleware) {
app.get('/outgoing', middleware.buildHeader, controllers.outgoing);
app.get('/api/outgoing', controllers.outgoing);
app.get('/search/:term?', middleware.buildHeader, middleware.guestSearchingAllowed, controllers.search);
app.get('/api/search/:term?', middleware.guestSearchingAllowed, controllers.search);
app.get('/reset/:code?', middleware.buildHeader, controllers.reset);
app.get('/api/reset/:code?', controllers.reset);
/* Static Pages */
app.get('/404', middleware.buildHeader, controllers.static['404']);
app.get('/api/404', controllers.static['404']);
@ -120,65 +126,6 @@ module.exports = function(app, middleware) {
app.get('/sitemap.xml', controllers.sitemap);
app.get('/robots.txt', controllers.robots);
app.get('api/search/:term?', function (req, res) {
if ((req.user && req.user.uid) || meta.config.allowGuestSearching === '1') {
return res.json({
show_no_topics: 'hide',
show_no_posts: 'hide',
show_results: 'hide',
search_query: '',
posts: [],
topics: []
});
} else {
res.send(403);
}
});
app.get('/search/:term?', function (req, res) {
if (!req.user && meta.config.allowGuestSearching !== '1') {
return res.redirect('/403');
}
if(!req.params.term) {
req.params.term = '';
}
app.build_header({
req: req,
res: res
}, function (err, header) {
//res.send(header + app.create_route('search/' + req.params.term, null, 'search') + templates.footer);
});
});
app.get('/reset/:code', function(req, res) {
app.build_header({
req: req,
res: res
}, function(err, header) {
res.send(header + app.create_route('reset/' + req.params.code) + templates.footer);
});
});
app.get('api/reset/:code', function (req, res) {
res.json({
reset_code: req.params.code
});
});
app.get('/reset', function(req, res) {
app.build_header({
req: req,
res: res
}, function(err, header) {
res.send(header + app.create_route('reset') + templates.footer);
});
});
app.get('api/reset', function (req, res) {
res.json({});
});
// Other routes

Loading…
Cancel
Save