more cleanup in routes/user.js

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

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

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

Loading…
Cancel
Save