@@ -94,4 +94,5 @@
-
\ No newline at end of file
+
+
\ No newline at end of file
diff --git a/public/templates/followers.tpl b/public/templates/followers.tpl
index 139a14dd56..45d973e898 100644
--- a/public/templates/followers.tpl
+++ b/public/templates/followers.tpl
@@ -41,4 +41,4 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/public/templates/following.tpl b/public/templates/following.tpl
index a167182c8c..38b84c45d4 100644
--- a/public/templates/following.tpl
+++ b/public/templates/following.tpl
@@ -45,4 +45,4 @@
-
+
diff --git a/public/templates/footer.tpl b/public/templates/footer.tpl
index d9c02f0d34..51d3b71df6 100644
--- a/public/templates/footer.tpl
+++ b/public/templates/footer.tpl
@@ -45,7 +45,6 @@
-
diff --git a/public/templates/login.tpl b/public/templates/login.tpl
index 4cf156f7a6..a3847fbb71 100644
--- a/public/templates/login.tpl
+++ b/public/templates/login.tpl
@@ -27,4 +27,4 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/public/templates/recent.tpl b/public/templates/recent.tpl
index 1c8fbf8af9..aa4bb57255 100644
--- a/public/templates/recent.tpl
+++ b/public/templates/recent.tpl
@@ -26,8 +26,8 @@
-
-
+
+
{topics.teaser_username}: {topics.teaser_text}
posted {topics.teaser_timestamp} ago
@@ -49,4 +49,4 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/public/templates/register.tpl b/public/templates/register.tpl
index 5a2cea9fc5..7b149091ef 100644
--- a/public/templates/register.tpl
+++ b/public/templates/register.tpl
@@ -20,4 +20,4 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/public/templates/reset.tpl b/public/templates/reset.tpl
index 3a1857a4f4..42d3d12f08 100644
--- a/public/templates/reset.tpl
+++ b/public/templates/reset.tpl
@@ -14,4 +14,4 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/public/templates/reset_code.tpl b/public/templates/reset_code.tpl
index a37d4534df..700005b3f7 100644
--- a/public/templates/reset_code.tpl
+++ b/public/templates/reset_code.tpl
@@ -22,4 +22,4 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/public/templates/topic.tpl b/public/templates/topic.tpl
index 9d716a1e3d..576afb828f 100644
--- a/public/templates/topic.tpl
+++ b/public/templates/topic.tpl
@@ -140,4 +140,4 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/public/templates/users.tpl b/public/templates/users.tpl
index 8f6da1c8b2..3904e6db06 100644
--- a/public/templates/users.tpl
+++ b/public/templates/users.tpl
@@ -36,4 +36,4 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/src/categories.js b/src/categories.js
index df390e4055..1d2575bfe1 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -309,7 +309,7 @@ var RDB = require('./redis.js'),
}
Categories.getCategories = function(cids, callback, current_user) {
- if (cids.length === 0) {
+ if (!cids || cids.length === 0) {
callback({'categories' : []});
return;
}
diff --git a/src/user.js b/src/user.js
index 0c2ab2f73c..a80a10c873 100644
--- a/src/user.js
+++ b/src/user.js
@@ -14,10 +14,9 @@ var utils = require('./../public/src/utils.js'),
User.create = function(username, password, email, callback) {
username = username.trim(), email = email.trim();
- // @todo return a proper error? use node-validator?
+ // @todo use node-validator?
if(!utils.isEmailValid(email) || !utils.isUserNameValid(username) || !utils.isPasswordValid(password)) {
- console.log('Invalid email/username/password!');
- callback(null, 0);
+ callback('Invalid email/username/password!', 0);
return;
}
@@ -25,13 +24,13 @@ var utils = require('./../public/src/utils.js'),
User.exists(userslug, function(exists) {
if(exists) {
- callback(null, 0);
+ callback('Username taken!', 0);
return;
}
User.isEmailAvailable(email, function(available) {
if(!available) {
- callback(null, 0);
+ callback('Email taken!', 0);
return;
}
diff --git a/src/webserver.js b/src/webserver.js
index 4c5d7ee007..d3a8b79224 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -1,4 +1,5 @@
var express = require('express'),
+ express_namespace = require('express-namespace'),
WebServer = express(),
server = require('http').createServer(WebServer),
RedisStore = require('connect-redis')(express),
@@ -26,16 +27,18 @@ var express = require('express'),
app.build_header = function(res) {
return templates['header'].parse({
- cssSrc: global.config['theme:src'] || '/vendor/bootstrap/css/bootstrap.min.css',
+ cssSrc: global.config['theme:src'] || global.config.relative_path + '/vendor/bootstrap/css/bootstrap.min.css',
title: global.config['title'] || 'NodeBB',
- csrf:res.locals.csrf_token
+ csrf:res.locals.csrf_token,
+ relative_path: global.config.relative_path
});
};
// Middlewares
app.use(express.favicon(path.join(__dirname, '../', 'public', 'favicon.ico')));
app.use(require('less-middleware')({ src: path.join(__dirname, '../', 'public') }));
- app.use(express.static(path.join(__dirname, '../', 'public')));
+ //app.use(express.static(path.join(__dirname, '../', 'public')));
+ app.use(global.config.relative_path, express.static(path.join(__dirname, '../', 'public')));
app.use(express.bodyParser()); // Puts POST vars in request.body
app.use(express.cookieParser()); // If you want to parse cookies (res.cookies)
app.use(express.compress());
@@ -108,11 +111,7 @@ var express = require('express'),
res.json('500', { error: err.message });
});
- auth.create_routes(app);
- admin.create_routes(app);
- userRoute.create_routes(app);
- installRoute.create_routes(app);
- testBed.create_routes(app);
+
app.create_route = function(url, tpl) { // to remove
return '';
@@ -141,77 +140,156 @@ var express = require('express'),
}());
// Complex Routes
- app.get('/', function(req, res) {
- categories.getAllCategories(function(returnData) {
- res.send(
- app.build_header(res) +
- '\n\t' +
- app.create_route('') +
- templates['footer']
- );
- }, 0);
- });
+ app.namespace(global.config.relative_path, function() {
- app.get('/topic/:topic_id/:slug?', function(req, res) {
- var tid = req.params.topic_id;
- if (tid.match('.rss')) {
- fs.readFile('feeds/topics/' + tid, function (err, data) {
- if (err) {
- res.type('text').send(404, "Unable to locate an rss feed at this location.");
+ auth.create_routes(app);
+ admin.create_routes(app);
+ userRoute.create_routes(app);
+ installRoute.create_routes(app);
+ testBed.create_routes(app);
+
+ app.get('/', function(req, res) {
+ console.log('going in home');
+ categories.getAllCategories(function(returnData) {
+ res.send(
+ app.build_header(res) +
+ '\n\t' +
+ app.create_route('') +
+ templates['footer']
+ );
+ }, 0);
+ });
+
+
+ app.get('/topic/:topic_id/:slug?', function(req, res) {
+ var tid = req.params.topic_id;
+ if (tid.match('.rss')) {
+ fs.readFile('feeds/topics/' + tid, function (err, data) {
+ if (err) {
+ res.type('text').send(404, "Unable to locate an rss feed at this location.");
+ return;
+ }
+
+ res.type('xml').set('Content-Length', data.length).send(data);
+ });
+ return;
+ }
+
+
+ var topic_url = tid + (req.params.slug ? '/' + req.params.slug : '');
+ topics.getTopicWithPosts(tid, ((req.user) ? req.user.uid : 0), function(err, topic) {
+ if (err) return res.redirect('404');
+
+ res.send(
+ app.build_header(res) +
+ '\n\t' +
+ '\n\t' +
+ templates['footer']
+ );
+ });
+ });
+
+ app.get('/category/:category_id/:slug?', function(req, res) {
+ var cid = req.params.category_id;
+ if (cid.match('.rss')) {
+ fs.readFile('feeds/categories/' + cid, function (err, data) {
+ if (err) {
+ res.type('text').send(404, "Unable to locate an rss feed at this location.");
+ return;
+ }
+
+ res.type('xml').set('Content-Length', data.length).send(data);
+ });
+ return;
+ }
+
+ var category_url = cid + (req.params.slug ? '/' + req.params.slug : '');
+ categories.getCategoryById(cid, 0, function(returnData) {
+ if(!returnData) {
+ res.redirect('404');
return;
}
- res.type('xml').set('Content-Length', data.length).send(data);
+ res.send(
+ app.build_header(res) +
+ '\n\t' +
+ '\n\t' +
+ templates['footer']
+ );
});
- return;
- }
-
-
- var topic_url = tid + (req.params.slug ? '/' + req.params.slug : '');
- topics.getTopicWithPosts(tid, ((req.user) ? req.user.uid : 0), function(err, topic) {
- if (err) return res.redirect('404');
-
- res.send(
- app.build_header(res) +
- '\n\t' +
- '\n\t' +
- templates['footer']
- );
});
- });
- app.get('/category/:category_id/:slug?', function(req, res) {
- var cid = req.params.category_id;
- if (cid.match('.rss')) {
- fs.readFile('feeds/categories/' + cid, function (err, data) {
- if (err) {
- res.type('text').send(404, "Unable to locate an rss feed at this location.");
+ app.get('/confirm/:code', function(req, res) {
+ res.send(app.build_header(res) + '' + templates['footer']);
+ });
+
+ app.get('/api/:method', api_method);
+ app.get('/api/:method/:id', api_method);
+ // ok fine MUST ADD RECURSION style. I'll look for a better fix in future but unblocking baris for this:
+ app.get('/api/:method/:id/:section?', api_method);
+ app.get('/api/:method/:id*', api_method);
+
+ app.get('/cid/:cid', function(req, res) {
+ categories.getCategoryData(req.params.cid, function(data){
+ if(data)
+ res.send(data);
+ else
+ res.send(404, "Category doesn't exist!");
+ });
+ });
+
+ app.get('/tid/:tid', function(req, res) {
+ topics.getTopicData(req.params.tid, function(data){
+ if(data)
+ res.send(data);
+ else
+ res.send(404, "Topic doesn't exist!");
+ });
+ });
+
+ app.get('/pid/:pid', function(req, res) {
+ posts.getPostData(req.params.pid, function(data){
+ if(data)
+ res.send(data);
+ else
+ res.send(404, "Post doesn't exist!");
+ });
+ });
+
+
+ //START TODO: MOVE TO GRAPH.JS
+
+ app.get('/graph/users/:username/picture', function(req, res) {
+ user.get_uid_by_username(req.params.username, function(uid) {
+ if (uid == null) {
+ res.json({
+ status: 0
+ });
return;
}
-
- res.type('xml').set('Content-Length', data.length).send(data);
+ user.getUserField(uid, 'picture', function(picture) {
+ if (picture == null) res.redirect('http://www.gravatar.com/avatar/a938b82215dfc96c4cabeb6906e5f953&default=identicon');
+ res.redirect(picture);
+ });
});
- return;
- }
-
- var category_url = cid + (req.params.slug ? '/' + req.params.slug : '');
- categories.getCategoryById(cid, 0, function(returnData) {
- if(!returnData) {
- res.redirect('404');
- return;
- }
- res.send(
- app.build_header(res) +
- '\n\t' +
- '\n\t' +
- templates['footer']
- );
});
- });
- app.get('/confirm/:code', function(req, res) {
- res.send(app.build_header(res) + '' + templates['footer']);
+ //END TODO: MOVE TO GRAPH.JS
+
+ app.get('/test', function(req, res) {
+
+ console.log('derp');
+ user.get_userslugs_by_uids([1,2], function(data) {
+ res.send(data);
+ });
+
+ /* categories.getCategoryById(1,1, function(data) {
+ res.send(data);
+ },1);*/
+
+ });
+
});
// These functions are called via ajax once the initial page is loaded to populate templates with data
@@ -342,73 +420,10 @@ var express = require('express'),
}
}
- app.get('/api/:method', api_method);
- app.get('/api/:method/:id', api_method);
- // ok fine MUST ADD RECURSION style. I'll look for a better fix in future but unblocking baris for this:
- app.get('/api/:method/:id/:section?', api_method);
- app.get('/api/:method/:id*', api_method);
-
- app.get('/cid/:cid', function(req, res) {
- categories.getCategoryData(req.params.cid, function(data){
- if(data)
- res.send(data);
- else
- res.send(404, "Category doesn't exist!");
- });
- });
-
- app.get('/tid/:tid', function(req, res) {
- topics.getTopicData(req.params.tid, function(data){
- if(data)
- res.send(data);
- else
- res.send(404, "Topic doesn't exist!");
- });
- });
-
- app.get('/pid/:pid', function(req, res) {
- posts.getPostData(req.params.pid, function(data){
- if(data)
- res.send(data);
- else
- res.send(404, "Post doesn't exist!");
- });
- });
+
- app.get('/test', function(req, res) {
-
- console.log('derp');
- user.get_userslugs_by_uids([1,2], function(data) {
- res.send(data);
- });
-
-/* categories.getCategoryById(1,1, function(data) {
- res.send(data);
- },1);*/
-
- });
-
-
- //START TODO: MOVE TO GRAPH.JS
-
- app.get('/graph/users/:username/picture', function(req, res) {
- user.get_uid_by_username(req.params.username, function(uid) {
- if (uid == null) {
- res.json({
- status: 0
- });
- return;
- }
- user.getUserField(uid, 'picture', function(picture) {
- if (picture == null) res.redirect('http://www.gravatar.com/avatar/a938b82215dfc96c4cabeb6906e5f953&default=identicon');
- res.redirect(picture);
- });
- });
-
- });
-
- //END TODO: MOVE TO GRAPH.JS
+
}(WebServer));
server.listen(config.port);