more cleanup in routes/user.js

v1.18.x
Baris Soner Usakli 12 years ago
parent 140f90f7f3
commit cdbca7d262

@ -27,8 +27,8 @@ var nconf = require('nconf'),
// Static Assets // Static Assets
app.get('/plugins/:id/*', function(req, res) { app.get('/plugins/:id/*', function(req, res) {
var relPath = req.url.replace('/plugins/' + req.params.id, ''); var relPath = req.url.replace('/plugins/' + req.params.id, '');
if (Plugins.staticDirs[req.params.id]) { if (plugins.staticDirs[req.params.id]) {
var fullPath = path.join(Plugins.staticDirs[req.params.id], relPath); var fullPath = path.join(plugins.staticDirs[req.params.id], relPath);
fs.exists(fullPath, function(exists) { fs.exists(fullPath, function(exists) {
if (exists) { if (exists) {
res.sendfile(fullPath, { res.sendfile(fullPath, {

@ -1,84 +1,51 @@
var user = require('./../user.js'), var fs = require('fs'),
posts = require('./../posts.js'),
postTools = require('../postTools'),
fs = require('fs'),
utils = require('./../../public/src/utils.js'),
path = require('path'), path = require('path'),
winston = require('winston'), winston = require('winston'),
nconf = require('nconf'), nconf = require('nconf'),
meta = require('./../meta'),
async= require('async'), async= require('async'),
user = require('./../user'),
posts = require('./../posts'),
postTools = require('../postTools'),
utils = require('./../../public/src/utils'),
meta = require('./../meta'),
RDB = require('./../redis'), RDB = require('./../redis'),
websockets = require('./../websockets.js'); websockets = require('./../websockets');
(function (User) { (function (User) {
User.createRoutes = function (app) { User.createRoutes = function (app) {
app.namespace('/users', function () { app.namespace('/users', function () {
app.get('', function (req, res) { var routes = ['', '/latest', '/sort-posts', '/sort-reputation', '/online', '/search'];
app.build_header({
req: req,
res: res
}, function (err, header) {
res.send(header + app.create_route("users", "users") + templates['footer']);
});
});
app.get('/latest', function (req, res) {
app.build_header({
req: req,
res: res
}, function (err, header) {
res.send(header + app.create_route("users/latest", "users") + templates['footer']);
});
});
app.get('/sort-posts', function (req, res) {
app.build_header({
req: req,
res: res
}, function (err, header) {
res.send(header + app.create_route("users/sort-posts", "users") + templates['footer']);
});
});
app.get('/sort-reputation', function (req, res) {
app.build_header({
req: req,
res: res
}, function (err, header) {
res.send(header + app.create_route("users/sort-reputation", "users") + templates['footer']);
});
});
app.get('/online', function (req, res) { function createRoute(routeName) {
app.build_header({ app.get(routeName, function (req, res) {
req: req, app.build_header({
res: res req: req,
}, function (err, header) { res: res
res.send(header + app.create_route("users/online", "users") + templates['footer']); }, function (err, header) {
res.send(header + app.create_route("users" + routeName, "users") + templates['footer']);
});
}); });
}); }
app.get('/search', function (req, res) { for (var i=0; i<routes.length; ++i) {
app.build_header({ createRoute(routes[i]);
req: req, }
res: res
}, function (err, header) {
res.send(header + app.create_route("users/search", "users") + templates['footer']);
});
});
}); });
app.namespace('/user', function () { app.namespace('/user', function () {
app.get('/:userslug', function (req, res, next) { app.get('/:userslug', function (req, res, next) {
if (!req.params.userslug) { if (!req.params.userslug) {
next(); return next();
return;
} }
user.getUidByUserslug(req.params.userslug, function (err, uid) { user.getUidByUserslug(req.params.userslug, function (err, uid) {
if (err) {
return next(err);
}
if (!uid) { if (!uid) {
return next(); return next();
} }
@ -89,14 +56,14 @@ var user = require('./../user.js'),
}, function (err, header) { }, function (err, header) {
res.send(header + app.create_route('user/' + req.params.userslug, 'account') + templates['footer']); res.send(header + app.create_route('user/' + req.params.userslug, 'account') + templates['footer']);
}); });
}); });
}); });
app.get('/:userslug/edit', function (req, res) { app.get('/:userslug/edit', function (req, res) {
if (!req.user) if (!req.user) {
return res.redirect('/403'); return res.redirect('/403');
}
user.getUserField(req.user.uid, 'userslug', function (err, userslug) { user.getUserField(req.user.uid, 'userslug', function (err, userslug) {
if (req.params.userslug && userslug === req.params.userslug) { if (req.params.userslug && userslug === req.params.userslug) {

Loading…
Cancel
Save