You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
635 lines
21 KiB
JavaScript
635 lines
21 KiB
JavaScript
var express = require('express'),
|
|
WebServer = express(),
|
|
server = require('http').createServer(WebServer),
|
|
RedisStore = require('connect-redis')(express),
|
|
path = require('path'),
|
|
redis = require('redis'),
|
|
redisServer = redis.createClient(global.config.redis.port, global.config.redis.host),
|
|
marked = require('marked'),
|
|
utils = require('../public/src/utils.js'),
|
|
fs = require('fs'),
|
|
|
|
user = require('./user.js'),
|
|
categories = require('./categories.js'),
|
|
posts = require('./posts.js'),
|
|
topics = require('./topics.js'),
|
|
notifications = require('./notifications.js'),
|
|
admin = require('./routes/admin.js'),
|
|
userRoute = require('./routes/user.js'),
|
|
installRoute = require('./routes/install.js'),
|
|
auth = require('./routes/authentication.js'),
|
|
meta = require('./meta.js');
|
|
|
|
(function(app) {
|
|
var templates = null;
|
|
|
|
app.build_header = function(res) {
|
|
return templates['header'].parse({
|
|
cssSrc: global.config['theme:src'] || '/vendor/bootstrap/css/bootstrap.min.css',
|
|
title: global.config['title'] || 'NodeBB',
|
|
csrf:res.locals.csrf_token
|
|
});
|
|
};
|
|
|
|
// 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.bodyParser()); // Puts POST vars in request.body
|
|
app.use(express.cookieParser()); // If you want to parse cookies (res.cookies)
|
|
app.use(express.compress());
|
|
app.use(express.session({
|
|
store: new RedisStore({
|
|
client: redisServer,
|
|
ttl: 60*60*24*14
|
|
}),
|
|
secret: global.config.secret,
|
|
key: 'express.sid'
|
|
}));
|
|
app.use(express.csrf());
|
|
app.use(function(req, res, next) {
|
|
res.locals.csrf_token = req.session._csrf;
|
|
next();
|
|
});
|
|
|
|
module.exports.init = function() {
|
|
templates = global.templates;
|
|
}
|
|
|
|
auth.initialize(app);
|
|
|
|
app.use(function(req, res, next) {
|
|
// Don't bother with session handling for API requests
|
|
if (/^\/api\//.test(req.url)) return next();
|
|
|
|
if (req.user && req.user.uid) {
|
|
user.session_ping(req.sessionID, req.user.uid);
|
|
}
|
|
|
|
// (Re-)register the session as active
|
|
user.active.register(req.sessionID);
|
|
|
|
next();
|
|
});
|
|
|
|
auth.create_routes(app);
|
|
admin.create_routes(app);
|
|
userRoute.create_routes(app);
|
|
installRoute.create_routes(app);
|
|
|
|
|
|
app.create_route = function(url, tpl) { // to remove
|
|
return '<script>templates.ready(function(){ajaxify.go("' + url + '", null, "' + tpl + '");});</script>';
|
|
};
|
|
|
|
// Basic Routes (entirely client-side parsed, goal is to move the rest of the crap in this file into this one section)
|
|
(function() {
|
|
var routes = ['login', 'register', 'account', 'recent', 'popular', 'active', '403', '404'];
|
|
|
|
for (var i=0, ii=routes.length; i<ii; i++) {
|
|
(function(route) {
|
|
|
|
app.get('/' + route, function(req, res) {
|
|
if ((route === 'login' || route ==='register') && (req.user && req.user.uid > 0)) {
|
|
|
|
user.getUserField(req.user.uid, 'userslug', function(userslug) {
|
|
res.redirect('/users/'+userslug);
|
|
});
|
|
return;
|
|
}
|
|
|
|
res.send(app.build_header(res) + app.create_route(route) + templates['footer']);
|
|
});
|
|
}(routes[i]));
|
|
}
|
|
}());
|
|
|
|
// Complex Routes
|
|
app.get('/', function(req, res) {
|
|
categories.getAllCategories(function(returnData) {
|
|
res.send(
|
|
app.build_header(res) +
|
|
'\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/home'].parse(returnData) + '\n\t</noscript>' +
|
|
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.send("Unable to locate an rss feed at this location.");
|
|
return;
|
|
}
|
|
|
|
res.setHeader('Content-Type', 'application/xml');
|
|
res.setHeader('Content-Length', data.length);
|
|
res.end(data);
|
|
});
|
|
return;
|
|
}
|
|
|
|
|
|
var topic_url = tid + (req.params.slug ? '/' + req.params.slug : '');
|
|
topics.getTopicWithPosts(tid, ((req.user) ? req.user.uid : 0), function(topic) {
|
|
res.send(
|
|
app.build_header(res) +
|
|
'\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/topic'].parse(topic) + '\n\t</noscript>' +
|
|
'\n\t<script>templates.ready(function(){ajaxify.go("topic/' + topic_url + '");});</script>' +
|
|
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.send("Unable to locate an rss feed at this location.");
|
|
return;
|
|
}
|
|
|
|
res.setHeader('Content-Type', 'application/xml');
|
|
res.setHeader('Content-Length', data.length);
|
|
res.end(data);
|
|
});
|
|
return;
|
|
}
|
|
|
|
var category_url = cid + (req.params.slug ? '/' + req.params.slug : '');
|
|
categories.getCategoryById(cid, 0, function(returnData) {
|
|
|
|
res.send(
|
|
app.build_header(res) +
|
|
'\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/category'].parse(returnData) + '\n\t</noscript>' +
|
|
'\n\t<script>templates.ready(function(){ajaxify.go("category/' + category_url + '");});</script>' +
|
|
templates['footer']
|
|
);
|
|
});
|
|
});
|
|
|
|
app.get('/confirm/:code', function(req, res) {
|
|
res.send(app.build_header(res) + '<script>templates.ready(function(){ajaxify.go("confirm/' + req.params.code + '");});</script>' + templates['footer']);
|
|
});
|
|
|
|
// These functions are called via ajax once the initial page is loaded to populate templates with data
|
|
function api_method(req, res) {
|
|
var uid = (req.user) ? req.user.uid : 0;
|
|
|
|
switch(req.params.method) {
|
|
case 'get_templates_listing' :
|
|
utils.walk(global.configuration.ROOT_DIRECTORY + '/public/templates', function(err, data) {
|
|
res.json(data);
|
|
});
|
|
break;
|
|
case 'home' :
|
|
categories.getAllCategories(function(data) {
|
|
data.motd_class = (config.show_motd === '1' || config.show_motd === undefined) ? '' : 'none';
|
|
data.motd = marked(config.motd || "# NodeBB v0.1\nWelcome to NodeBB, the discussion platform of the future.\n\n<a target=\"_blank\" href=\"http://www.nodebb.org\" class=\"btn btn-large\"><i class=\"icon-comment\"></i> Get NodeBB</a> <a target=\"_blank\" href=\"https://github.com/designcreateplay/NodeBB\" class=\"btn btn-large\"><i class=\"icon-github-alt\"></i> Fork us on Github</a> <a target=\"_blank\" href=\"https://twitter.com/dcplabs\" class=\"btn btn-large\"><i class=\"icon-twitter\"></i> @dcplabs</a>");
|
|
res.json(data);
|
|
}, uid);
|
|
break;
|
|
case 'login' :
|
|
var data = {},
|
|
login_strategies = auth.get_login_strategies(),
|
|
num_strategies = login_strategies.length;
|
|
|
|
if (num_strategies == 0) {
|
|
data = {
|
|
'login_window:spansize': 'span12',
|
|
'alternate_logins:display': 'none'
|
|
};
|
|
} else {
|
|
data = {
|
|
'login_window:spansize': 'span6',
|
|
'alternate_logins:display': 'block'
|
|
}
|
|
for (var i=0, ii=num_strategies; i<ii; i++) {
|
|
data[login_strategies[i] + ':display'] = 'active';
|
|
}
|
|
}
|
|
|
|
data.token = res.locals.csrf_token;
|
|
|
|
res.json(data);
|
|
break;
|
|
case 'register' :
|
|
var data = {},
|
|
login_strategies = auth.get_login_strategies(),
|
|
num_strategies = login_strategies.length;
|
|
|
|
if (num_strategies == 0) {
|
|
data = {
|
|
'register_window:spansize': 'span12',
|
|
'alternate_logins:display': 'none'
|
|
};
|
|
} else {
|
|
data = {
|
|
'register_window:spansize': 'span6',
|
|
'alternate_logins:display': 'block'
|
|
}
|
|
for (var i=0, ii=num_strategies; i<ii; i++) {
|
|
data[login_strategies[i] + ':display'] = 'active';
|
|
}
|
|
}
|
|
|
|
data.token = res.locals.csrf_token;
|
|
|
|
res.json(data);
|
|
break;
|
|
case 'topic' :
|
|
topics.getTopicWithPosts(req.params.id, uid, function(data) {
|
|
res.json(data);
|
|
});
|
|
break;
|
|
case 'category' :
|
|
categories.getCategoryById(req.params.id, uid, function(data) {
|
|
res.json(data);
|
|
}, req.params.id, uid);
|
|
break;
|
|
case 'recent' :
|
|
categories.getLatestTopics(uid, 0, 9, function(data) {
|
|
res.json(data);
|
|
});
|
|
break;
|
|
case 'popular' :
|
|
categories.getLatestTopics(uid, 0, 9, function(data) {
|
|
res.json(data);
|
|
});
|
|
break;
|
|
case 'active' :
|
|
categories.getLatestTopics(uid, 0, 9, function(data) {
|
|
res.json(data);
|
|
});
|
|
break;
|
|
case 'confirm':
|
|
user.email.confirm(req.params.id, function(data) {
|
|
if (data.status === 'ok') {
|
|
res.json({
|
|
'alert-class': 'alert-success',
|
|
title: 'Email Confirmed',
|
|
text: 'Thank you for vaidating your email. Your account is now fully activated.'
|
|
});
|
|
} else {
|
|
res.json({
|
|
'alert-class': 'alert-error',
|
|
title: 'An error occurred...',
|
|
text: 'There was a problem validating your email address. Perhaps the code was invalid or has expired.'
|
|
});
|
|
}
|
|
});
|
|
break;
|
|
default :
|
|
res.json({});
|
|
break;
|
|
}
|
|
}
|
|
|
|
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("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("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("Post doesn't exist!");
|
|
});
|
|
});
|
|
|
|
app.all('/test', function(req, res) {
|
|
|
|
categories.getCategoryById(1,1, function(data) {
|
|
res.send(data);
|
|
},1);
|
|
|
|
});
|
|
|
|
|
|
app.get('/restoreusers', function(req, res) {
|
|
var users = [
|
|
{
|
|
"lastposttime": "1371780880500",
|
|
"userslug": "frandroid",
|
|
"postcount": "2",
|
|
"joindate": "1371780652088",
|
|
"reputation": "2",
|
|
"picture": "http://www.gravatar.com/avatar/18c5b5c8f510b87137f791033faef29a?default=identicon",
|
|
"username": "frandroid",
|
|
"location": "",
|
|
"password": "$2a$10$aeIuMhHfMbfwD9vyfpmgSek.oJz0Awg6uYqRR9EfMVrEo1pltGriS",
|
|
"fullname": "",
|
|
"birthday": "",
|
|
"uploadedpicture": "",
|
|
"website": "",
|
|
"signature": "",
|
|
"administrator": "0",
|
|
"gravatarpicture": "http://www.gravatar.com/avatar/18c5b5c8f510b87137f791033faef29a?default=identicon",
|
|
"email": "[email protected]",
|
|
"uid": "4"
|
|
},
|
|
{
|
|
"lastposttime": "1371844905163",
|
|
"userslug": "jmartins",
|
|
"postcount": "1",
|
|
"joindate": "1371844542588",
|
|
"reputation": "0",
|
|
"picture": "http://www.gravatar.com/avatar/61211955edb0f5ad1c4bf3d9d0d794c4?default=identicon",
|
|
"username": "jmartins",
|
|
"location": "",
|
|
"password": "$2a$10$1aRt1HbyCSxAi.Oozqs/U.9IaVn7e14BMLbKZFWRAOJScPA.2IuaK",
|
|
"fullname": "",
|
|
"birthday": "",
|
|
"uploadedpicture": "",
|
|
"website": "",
|
|
"signature": "",
|
|
"gravatarpicture": "http://www.gravatar.com/avatar/61211955edb0f5ad1c4bf3d9d0d794c4?default=identicon",
|
|
"administrator": "0",
|
|
"email": "[email protected]",
|
|
"uid": "7"
|
|
},
|
|
{
|
|
"lastposttime": "1372276794108",
|
|
"userslug": "julian",
|
|
"postcount": "4",
|
|
"joindate": "1371501794786",
|
|
"reputation": "1",
|
|
"picture": "http://www.gravatar.com/avatar/e1565907855fffe8433c31671a49f177?default=identicon",
|
|
"username": "julian",
|
|
"password": "$2a$10$guB.xWD30zA6MXW8qTjlW.I4mtRCWT8RzkaJlaiUErfbX9neUodQ2",
|
|
"location": "",
|
|
"birthday": "",
|
|
"fullname": "",
|
|
"uploadedpicture": "",
|
|
"website": "",
|
|
"signature": "Co-Founder, Design Create Play / NodeBB\nToronto, Ontario",
|
|
"administrator": "1",
|
|
"gravatarpicture": "http://www.gravatar.com/avatar/e1565907855fffe8433c31671a49f177?default=identicon",
|
|
"email": "[email protected]",
|
|
"uid": "2"
|
|
},
|
|
{
|
|
"lastposttime": "1372296188180",
|
|
"userslug": "trevor",
|
|
"postcount": "7",
|
|
"joindate": "1372294776557",
|
|
"reputation": "1",
|
|
"picture": "http://www.gravatar.com/avatar/a0f06a0090e5367b55c1a8fb31c47513?default=identicon",
|
|
"username": "trevor",
|
|
"location": "",
|
|
"password": "$2a$10$wNL8cj31MlBrazPY92/AzeIs4WU6eBMVumriOFOyu2mtqdEVSOpni",
|
|
"fullname": "",
|
|
"birthday": "",
|
|
"uploadedpicture": "",
|
|
"website": "",
|
|
"signature": "",
|
|
"gravatarpicture": "http://www.gravatar.com/avatar/a0f06a0090e5367b55c1a8fb31c47513?default=identicon",
|
|
"administrator": "0",
|
|
"email": "[email protected]",
|
|
"uid": "11"
|
|
},
|
|
{
|
|
"lastposttime": "1372100797920",
|
|
"userslug": "dave",
|
|
"postcount": "1",
|
|
"joindate": "1372100717633",
|
|
"reputation": "0",
|
|
"picture": "http://www.gravatar.com/avatar/378b22e75617b070b80e52336aaa9d5c?default=identicon",
|
|
"username": "dave",
|
|
"location": "",
|
|
"password": "$2a$10$26D0Sccbl1qudOK2AEDWj.FvR3f3dsQUnk.xcLfS082S49xKuA5j.",
|
|
"fullname": "",
|
|
"birthday": "",
|
|
"uploadedpicture": "",
|
|
"website": "",
|
|
"signature": "",
|
|
"gravatarpicture": "http://www.gravatar.com/avatar/378b22e75617b070b80e52336aaa9d5c?default=identicon",
|
|
"administrator": "0",
|
|
"email": "[email protected]",
|
|
"uid": "9"
|
|
},
|
|
{
|
|
"lastposttime": "1372297084849",
|
|
"userslug": "baris",
|
|
"postcount": "12",
|
|
"joindate": "1371501788271",
|
|
"reputation": "1",
|
|
"picture": "http://www.gravatar.com/avatar/91050ce0072697b53380c6a03a1bc12a?default=identicon",
|
|
"username": "baris",
|
|
"password": "$2a$10$ZAQVjLKg2ev0sW6VCyq87O6LX5/z7d.uyIYWdM0kgIq7JKR/wCg1G",
|
|
"location": "Toronto, ON",
|
|
"birthday": "1983-02-18",
|
|
"fullname": "Baris Soner Usakli",
|
|
"uploadedpicture": "http://try.nodebb.org/uploads/1-black1.jpg",
|
|
"website": "http://baris.shadowytree.com",
|
|
"signature": "NodeBB Developer\nhttp://nodebb.org",
|
|
"gravatarpicture": "http://www.gravatar.com/avatar/91050ce0072697b53380c6a03a1bc12a?default=identicon",
|
|
"email": "[email protected]",
|
|
"uid": "1"
|
|
},
|
|
{
|
|
"lastposttime": "1372177299261",
|
|
"userslug": "psychobunny",
|
|
"postcount": "5",
|
|
"joindate": "1371567705241",
|
|
"reputation": "5",
|
|
"picture": "http://www.gravatar.com/avatar/ec001b26766105ea038160c98a317956?default=identicon",
|
|
"username": "psychobunny",
|
|
"password": "$2a$10$FmiNS8EDEB3m9IYnr4JF2eL/6L5h6TT0aegN1KItPD5MRrSFVDuR6",
|
|
"location": "",
|
|
"birthday": "",
|
|
"fullname": "",
|
|
"uploadedpicture": "",
|
|
"website": "",
|
|
"signature": "",
|
|
"gravatarpicture": "http://www.gravatar.com/avatar/ec001b26766105ea038160c98a317956?default=identicon",
|
|
"email": "[email protected]",
|
|
"uid": "3"
|
|
},
|
|
{
|
|
"lastposttime": "0",
|
|
"birthday": "",
|
|
"fullname": "",
|
|
"postcount": "0",
|
|
"uploadedpicture": "",
|
|
"website": "",
|
|
"joindate": "1371843703632",
|
|
"signature": "",
|
|
"reputation": "0",
|
|
"administrator": "0",
|
|
"gravatarpicture": "http://www.gravatar.com/avatar/03a709deaf97ef4628f50634939f9d2e?default=identicon",
|
|
"picture": "http://www.gravatar.com/avatar/03a709deaf97ef4628f50634939f9d2e?default=identicon",
|
|
"username": "Pacem",
|
|
"email": "[email protected]",
|
|
"password": "$2a$10$tmioEML3RgQkh7nf0XWAhePfN2xzDpX3jDaIzKvtsqffzohpo9ETa",
|
|
"location": "",
|
|
"userslug": "pacem",
|
|
"uid": "5"
|
|
},
|
|
{
|
|
"lastposttime": "1371844356155",
|
|
"userslug": "alan",
|
|
"postcount": "2",
|
|
"joindate": "1371844234281",
|
|
"reputation": "0",
|
|
"picture": "http://www.gravatar.com/avatar/6350d3781efe9d1a3a88542771ee39d4?default=identicon",
|
|
"username": "alan",
|
|
"location": "",
|
|
"password": "$2a$10$GqQCo3.Xq0WHjbXYbttik.qKHe.AZIS/DJbmO3Iu2IwNjSrfcpW3.",
|
|
"fullname": "",
|
|
"birthday": "",
|
|
"uploadedpicture": "",
|
|
"website": "",
|
|
"signature": "",
|
|
"gravatarpicture": "http://www.gravatar.com/avatar/6350d3781efe9d1a3a88542771ee39d4?default=identicon",
|
|
"administrator": "0",
|
|
"email": "[email protected]",
|
|
"uid": "6"
|
|
},
|
|
{
|
|
"lastposttime": "0",
|
|
"userslug": "prabhu",
|
|
"postcount": "0",
|
|
"joindate": "1372248496742",
|
|
"reputation": "0",
|
|
"picture": "http://www.gravatar.com/avatar/027fdebe8c66386e0805d9fe1647b3f6?default=identicon",
|
|
"username": "prabhu",
|
|
"location": "",
|
|
"password": "$2a$10$l.1flyAxiv1yJd9KDZz0xOZVPewCEavb1A6m3IySisI5PhNBKYwBC",
|
|
"fullname": "",
|
|
"birthday": "",
|
|
"uploadedpicture": "",
|
|
"website": "",
|
|
"signature": "",
|
|
"gravatarpicture": "http://www.gravatar.com/avatar/027fdebe8c66386e0805d9fe1647b3f6?default=identicon",
|
|
"administrator": "0",
|
|
"email": "[email protected]",
|
|
"uid": "10"
|
|
},
|
|
{
|
|
"postcount": "0",
|
|
"birthday": "",
|
|
"uploadedpicture": "",
|
|
"administrator": "0",
|
|
"email": "[email protected]",
|
|
"lastposttime": "0",
|
|
"userslug": "nn",
|
|
"joindate": "1372952945584",
|
|
"reputation": "0",
|
|
"picture": "http://www.gravatar.com/avatar/a770385c11df2ff522891ff79fd0c8eb?default=identicon",
|
|
"username": "NN",
|
|
"location": "",
|
|
"password": "$2a$10$VyvNRROcowKo9CJ/PxG7F.utpO5rQAJuKyUftXImUlr6vqDU02N6O",
|
|
"fullname": "NN",
|
|
"website": "",
|
|
"signature": "",
|
|
"gravatarpicture": "http://www.gravatar.com/avatar/a770385c11df2ff522891ff79fd0c8eb?default=identicon",
|
|
"uid": "13"
|
|
},
|
|
{
|
|
"lastposttime": "1371937280069",
|
|
"userslug": "fabiolousmate",
|
|
"postcount": "1",
|
|
"joindate": "1371937199511",
|
|
"reputation": "0",
|
|
"picture": "http://www.gravatar.com/avatar/ad82efdfb33b2bb514ff1f3d9f32f7d1?default=identicon",
|
|
"username": "fabiolousmate",
|
|
"location": "",
|
|
"password": "$2a$10$AjsgEDOrkqO6In4f.I1eE.zVGPa.SK/z/YljzLjIHbGrjA8tesQy2",
|
|
"fullname": "",
|
|
"birthday": "",
|
|
"uploadedpicture": "",
|
|
"website": "",
|
|
"signature": "",
|
|
"gravatarpicture": "http://www.gravatar.com/avatar/ad82efdfb33b2bb514ff1f3d9f32f7d1?default=identicon",
|
|
"administrator": "0",
|
|
"email": "[email protected]",
|
|
"uid": "8"
|
|
},
|
|
{
|
|
"lastposttime": "0",
|
|
"userslug": "test-test",
|
|
"postcount": "0",
|
|
"joindate": "1372303753517",
|
|
"reputation": "0",
|
|
"picture": "http://www.gravatar.com/avatar/5677dfcb7c7117b0ef64fc9897b861fb?default=identicon",
|
|
"username": "test test",
|
|
"location": "",
|
|
"password": "$2a$10$Gh9GsuROV.W8FDRKVdL7EOvpAxN24JsHD7MGWRx8R39wh6mP2YbXO",
|
|
"fullname": "",
|
|
"birthday": "",
|
|
"uploadedpicture": "",
|
|
"website": "",
|
|
"signature": "",
|
|
"gravatarpicture": "http://www.gravatar.com/avatar/5677dfcb7c7117b0ef64fc9897b861fb?default=identicon",
|
|
"administrator": "0",
|
|
"email": "[email protected]",
|
|
"uid": "12"
|
|
}
|
|
];
|
|
|
|
for(var user in users) {
|
|
redis.hmset('user:'+user.uid, user);
|
|
|
|
RDB.set('username:' + user.username + ':uid', user.uid);
|
|
RDB.set('email:' + user.email +':uid', user.uid);
|
|
RDB.set('userslug:'+ user.userslug +':uid', user.uid);
|
|
|
|
RDB.incr('usercount', function(err, count) {
|
|
RDB.handle(err);
|
|
});
|
|
|
|
RDB.lpush('userlist', user.username);
|
|
}
|
|
|
|
res.send('success');
|
|
});
|
|
|
|
//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);
|
|
global.server = server; |