psychobunny 12 years ago
commit 8e48990a48

@ -42,6 +42,10 @@ The server configuration file (located at `/config.js`) contains default options
<td><b>base_url</b></td> <td><b>base_url</b></td>
<td><i>(Default: 'http://localhost')</i> A web-accessible URL to your app, without the port</td> <td><i>(Default: 'http://localhost')</i> A web-accessible URL to your app, without the port</td>
</tr> </tr>
<tr>
<td><b>upload_path</b></td>
<td><i>(Default: '/public/uploads')</i> A relative path (relative to the application's web root) to the uploads folder. Please ensure that Node.js can write to this folder</td>
</tr>
<tr> <tr>
<td><b>use_port</b></td> <td><b>use_port</b></td>
<td><i>(Default: true)</i> Whether or not to include the port number when constructing the url for use in NodeBB. If you are serving NodeBB via a proxy (i.e. nginx), switch this off. <td><i>(Default: true)</i> Whether or not to include the port number when constructing the url for use in NodeBB. If you are serving NodeBB via a proxy (i.e. nginx), switch this off.

@ -1,41 +1,30 @@
var modules = { var categories = require('./src/categories.js'),
user: require('./src/user.js'), templates = require('./src/templates.js'),
topics: require('./src/topics.js'), webserver = require('./src/webserver.js'),
posts: require('./src/posts.js'), websockets = require('./src/websockets.js'),
categories: require('./src/categories.js'), fs = require('fs');
templates: require('./src/templates.js'),
webserver: require('./src/webserver.js'),
websockets: require('./src/websockets.js'),
fs: require('fs')
}
DEVELOPMENT = true;
DEVELOPMENT = true;
global.configuration = {}; global.configuration = {};
global.modules = modules;
(function(config) { (function(config) {
config['ROOT_DIRECTORY'] = __dirname; config['ROOT_DIRECTORY'] = __dirname;
modules.templates.init(); templates.init();
modules.websockets.init();
//setup scripts to be moved outside of the app in future. //setup scripts to be moved outside of the app in future.
function setup_categories() { function setup_categories() {
console.log('Checking categories...'); console.log('Checking categories...');
modules.categories.get(function(data) { categories.get(function(data) {
if (data.categories.length === 0) { if (data.categories.length === 0) {
console.log('Setting up default categories...'); console.log('Setting up default categories...');
modules.fs.readFile(config.ROOT_DIRECTORY + '/install/data/categories.json', function(err, categories) { fs.readFile(config.ROOT_DIRECTORY + '/install/data/categories.json', function(err, categories) {
categories = JSON.parse(categories); categories = JSON.parse(categories);
for (var category in categories) { for (var category in categories) {
modules.categories.create(categories[category]); categories.create(categories[category]);
} }
}); });

@ -5,11 +5,8 @@ var config = {
// "base_url" is expected to be a publically accessible URL to your NodeBB instance (Default base_url: 'http://localhost', port: '4567') // "base_url" is expected to be a publically accessible URL to your NodeBB instance (Default base_url: 'http://localhost', port: '4567')
"base_url": "http://localhost", "base_url": "http://localhost",
// public url for uploaded files
"upload_url": "http://dev.domain.com/uploads/",
// relative path for uploads // relative path for uploads
"upload_path": "/uploads/", "upload_path": "/public/uploads/",
"use_port": true, "use_port": true,
"port": 4567, "port": 4567,
@ -54,5 +51,6 @@ var config = {
} }
config.url = config.base_url + (config.use_port ? ':' + config.port : '') + '/'; config.url = config.base_url + (config.use_port ? ':' + config.port : '') + '/';
config.upload_url = config.base_url + (config.use_port ? ':' + config.port : '') + '/uploads/';
module.exports = config; module.exports = config;

@ -245,6 +245,11 @@ footer.footer {
line-height: 18px; line-height: 18px;
padding: 5px; padding: 5px;
padding-left: 10px; padding-left: 10px;
img.hidden-desktop {
max-width: 10px;
max-height: 10px;
}
} }
.post-content { .post-content {
min-height: 50px; min-height: 50px;
@ -371,6 +376,7 @@ footer.footer {
.user-profile-picture { .user-profile-picture {
width:128px; width:128px;
height:128px; height:128px;
margin-bottom:10px;
} }
.user-8080-picture { .user-8080-picture {

@ -21,11 +21,12 @@ var ajaxify = {};
window.onpopstate = function(event) { window.onpopstate = function(event) {
// this breaks reloading and results in ajaxify.go calling twice, believe it messes around with sockets. ill come back for you later bitchez console.log('popstate called:', event);
// ajaxify.go(document.location.href.replace(rootUrl +'/', '')); if (event !== null && event.state && event.state.url) ajaxify.go(event.state.url, null, null, true);
}; };
ajaxify.go = function(url, callback, custom_tpl) { ajaxify.go = function(url, callback, template, quiet) {
// "quiet": If set to true, will not call pushState
// leave room and join global // leave room and join global
app.enter_room('global'); app.enter_room('global');
@ -41,7 +42,11 @@ var ajaxify = {};
} }
if (templates[tpl_url]) { if (templates[tpl_url]) {
window.history.pushState({}, url, "/" + url); if (quiet !== true) {
window.history.pushState({
"url": url
}, url, "/" + url);
}
jQuery('#footer').fadeOut(100); jQuery('#footer').fadeOut(100);
jQuery('#content').fadeOut(100); jQuery('#content').fadeOut(100);
@ -55,7 +60,7 @@ var ajaxify = {};
} }
jQuery('#content, #footer').fadeIn(200); jQuery('#content, #footer').fadeIn(200);
}, custom_tpl); }, url, template);
return true; return true;

@ -160,14 +160,12 @@ var templates = {};
}()); }());
function load_template(callback, custom_tpl) { function load_template(callback, url, template) {
var location = document.location || window.location, var location = document.location || window.location,
rootUrl = location.protocol + '//' + (location.hostname || location.host) + (location.port ? ':' + location.port : ''); rootUrl = location.protocol + '//' + (location.hostname || location.host) + (location.port ? ':' + location.port : '');
var url = location.href.replace(rootUrl +'/', '');
url = (url === '' || url === '/') ? 'home' : url; url = (url === '' || url === '/') ? 'home' : url;
jQuery.get(API_URL + url, function(data) { jQuery.get(API_URL + url, function(data) {
var tpl = templates.get_custom_map(url); var tpl = templates.get_custom_map(url);

@ -6,48 +6,47 @@
<p></p> <p></p>
</div> </div>
<!-- BEGIN user -->
<div class="account-username-box"> <div class="account-username-box">
<span class="account-username"><a href="/users/{user.username}">{user.username}</a></span> <span class="account-username"><a href="/users/{username}">{username}</a></span>
<span id="editLink" class="pull-right"><a href="/users/{user.username}/edit">edit</a></span> <span id="editLink" class="pull-right"><a href="/users/{username}/edit">edit</a></span>
</div> </div>
<div class="account-picture-block"> <div class="account-picture-block">
<img src="{user.picture}?s=128" class="user-profile-picture"/> <img src="{picture}" class="user-profile-picture"/>
</div> </div>
<div class="account-bio-block"> <div class="account-bio-block">
<span class="account-bio-label">email</span> <span class="account-bio-label">email</span>
<span>{user.email}</span> <span>{email}</span>
<br/> <br/>
<span class="account-bio-label">full name</span> <span class="account-bio-label">full name</span>
<span>{user.fullname}</span> <span>{fullname}</span>
<br/> <br/>
<span class="account-bio-label">website</span> <span class="account-bio-label">website</span>
<span><a href="{user.website}">{user.website}</a></span> <span><a href="{website}">{website}</a></span>
<br/> <br/>
<span class="account-bio-label">location</span> <span class="account-bio-label">location</span>
<span>{user.location}</span> <span>{location}</span>
<br/> <br/>
<span class="account-bio-label">age</span> <span class="account-bio-label">age</span>
<span>{user.age}</span> <span>{age}</span>
<br/> <br/>
<span class="account-bio-label">member for</span> <span class="account-bio-label">member for</span>
<span>{user.joindate}</span> <span>{joindate}</span>
<br/> <br/>
<span class="account-bio-label">reputation</span> <span class="account-bio-label">reputation</span>
<span id='reputation'>{user.reputation}</span> <span id='reputation'>{reputation}</span>
<br/> <br/>
<span class="account-bio-label">posts</span> <span class="account-bio-label">posts</span>
<span id='postcount'>{user.postcount}</span> <span id='postcount'>{postcount}</span>
</div> </div>

@ -6,7 +6,6 @@
<strong></strong> <strong></strong>
<p></p> <p></p>
</div> </div>
<!-- Change Picture Modal --> <!-- Change Picture Modal -->
<div id="change-picture-modal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div id="change-picture-modal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
@ -21,7 +20,7 @@
<span class="user-picture-label">Gravatar</span> <span class="user-picture-label">Gravatar</span>
<i class='icon-ok icon-2x'></i> <i class='icon-ok icon-2x'></i>
</div> </div>
<br/>
<div id="uploaded-box"> <div id="uploaded-box">
<img id="user-uploaded-picture" src="" class="img-polaroid user-profile-picture"> <img id="user-uploaded-picture" src="" class="img-polaroid user-profile-picture">
<span class="user-picture-label">Uploaded picture</span> <span class="user-picture-label">Uploaded picture</span>
@ -64,81 +63,76 @@
<button id="pictureUploadSubmitBtn" class="btn btn-primary">Upload Picture</button> <button id="pictureUploadSubmitBtn" class="btn btn-primary">Upload Picture</button>
</div> </div>
</div> </div>
<!-- BEGIN user -->
<div class="account-username-box"> <div class="account-username-box">
<span class="account-username"><a href="/users/{user.username}">{user.username}</a></span> <span class="account-username"><a href="/users/{username}">{username}</a></span>
<span class="pull-right"><a href="/users/{user.username}/edit">edit</a></span> <span class="pull-right"><a href="/users/{username}/edit">edit</a></span>
</div> </div>
<div class="account-picture-block text-center"> <div class="row-fluid">
<img id="user-current-picture" class="user-profile-picture" src="{user.picture}" /><br/> <div class="span3" style="text-align: center; margin-bottom:20px;">
<a id="changePictureBtn" href="#">change picture</a> <div class="account-picture-block text-center">
</div> <img id="user-current-picture" class="user-profile-picture" src="{picture}" /><br/>
<a id="changePictureBtn" href="#" class="btn btn-primary">change picture</a>
</div>
<div class="inline-block"> </div>
<form class='form-horizontal'>
<div class="control-group"> <div class="span9">
<label class="control-label" for="inputEmail">Email</label> <div class="inline-block">
<div class="controls"> <form class='form-horizontal'>
<input type="text" id="inputEmail" placeholder="Email" value="{user.email}"> <div class="control-group">
</div> <label class="control-label" for="inputEmail">Email</label>
</div> <div class="controls">
<input type="text" id="inputEmail" placeholder="Email" value="{email}">
<div class="control-group"> </div>
<label class="control-label" for="inputFullname">Full Name</label> </div>
<div class="controls">
<input type="text" id="inputFullname" placeholder="Full Name" value="{user.fullname}"> <div class="control-group">
</div> <label class="control-label" for="inputFullname">Full Name</label>
</div> <div class="controls">
<input type="text" id="inputFullname" placeholder="Full Name" value="{fullname}">
<div class="control-group"> </div>
<label class="control-label" for="inputWebsite">Website</label> </div>
<div class="controls">
<input type="text" id="inputWebsite" placeholder="http://website.com" value="{user.website}"> <div class="control-group">
</div> <label class="control-label" for="inputWebsite">Website</label>
</div> <div class="controls">
<input type="text" id="inputWebsite" placeholder="http://website.com" value="{website}">
<div class="control-group"> </div>
<label class="control-label" for="inputLocation">Location</label> </div>
<div class="controls">
<input type="text" id="inputLocation" placeholder="Location" value="{user.location}"> <div class="control-group">
</div> <label class="control-label" for="inputLocation">Location</label>
</div> <div class="controls">
<input type="text" id="inputLocation" placeholder="Location" value="{location}">
<div class="control-group"> </div>
<label class="control-label" for="inputBirthday">Birthday</label> </div>
<div class="controls">
<input type="text" id="inputBirthday" placeholder="dd/mm/yyyy" value="{user.birthday}"> <div class="control-group">
</div> <label class="control-label" for="inputBirthday">Birthday</label>
</div> <div class="controls">
<input type="text" id="inputBirthday" placeholder="mm/dd/yyyy" value="{birthday}">
<input type="hidden" id="inputUID" value="{user.uid}"> </div>
</div>
<div class="form-actions">
<a id="submitBtn" href="" class="btn btn-primary">Save changes</a> <input type="hidden" id="inputUID" value="{uid}">
<a href="/users/{user.username}" class="btn">Cancel</a>
</div> <div class="form-actions">
<a id="submitBtn" href="" class="btn btn-primary">Save changes</a>
</form> <a href="/users/{username}" class="btn">Cancel</a>
</div> </div>
<!-- how to pass data to the script ?? --> </form>
<div id="user-data-picture" class="hide">{user.picture}</div> </div>
<div id="user-data-gravatarpicture" class="hide">{user.gravatarpicture}</div> </div>
<div id="user-data-uploadedpicture" class="hide">{user.uploadedpicture}</div> </div>
<!-- END user -->
</div> </div>
<script type="text/javascript">
<script type="text/javascript"> var gravatarPicture = '{gravatarpicture}';
var uploadedPicture = '{uploadedpicture}';
$(document).ready(function() { $(document).ready(function() {
@ -175,7 +169,7 @@ $(document).ready(function() {
$('#user-current-picture').attr('src', imageUrlOnServer); $('#user-current-picture').attr('src', imageUrlOnServer);
$('#user-uploaded-picture').attr('src', imageUrlOnServer); $('#user-uploaded-picture').attr('src', imageUrlOnServer);
$('#user-data-uploadedpicture').html(imageUrlOnServer); uploadedPicture = imageUrlOnServer;
setTimeout(function() { setTimeout(function() {
hideAlerts(); hideAlerts();
@ -248,10 +242,6 @@ $(document).ready(function() {
}); });
function updateImages() { function updateImages() {
var currentPicture = $('#user-current-picture').attr('src');
var gravatarPicture = $('#user-data-gravatarpicture').html();
var uploadedPicture = $('#user-data-uploadedpicture').html();
if(gravatarPicture) { if(gravatarPicture) {
$('#user-gravatar-picture').attr('src', gravatarPicture); $('#user-gravatar-picture').attr('src', gravatarPicture);
@ -308,9 +298,9 @@ $(document).ready(function() {
changeUserPicture(selectedImageType); changeUserPicture(selectedImageType);
if(selectedImageType == 'gravatar') if(selectedImageType == 'gravatar')
$('#user-current-picture').attr('src', $('#user-data-gravatarpicture').html()); $('#user-current-picture').attr('src', gravatarPicture);
else if(selectedImageType == 'uploaded') else if(selectedImageType == 'uploaded')
$('#user-current-picture').attr('src', $('#user-data-uploadedpicture').html()); $('#user-current-picture').attr('src', uploadedPicture);
} }
}); });

@ -2,14 +2,14 @@
<div class="row-fluid"> <div class="row-fluid">
<div class="well {register_window:spansize}"> <div class="well {register_window:spansize}">
<form method="post" action="/register"> <form method="post" action="/register">
<label for="email">Email Address</label><input type="email" name="email" placeholder="Enter Email Address" id="email" /> <span id="email-notify" class="label label-important"></span> <br /> <label for="email">Email Address</label><input type="email" name="email" placeholder="Enter Email Address" id="email" /> <span id="email-notify" class="label label-important"></span><br />
<label for="username">Username</label><input type="text" name="username" placeholder="Enter Username" id="username" /> <span id="username-notify" class="label label-success"></span> <br /> <label for="username">Username</label><input type="text" name="username" placeholder="Enter Username" id="username" /> <span id="username-notify" class="label label-success"></span> <br />
<label for="password">Password</label><input type="password" name="password" placeholder="Enter Password" id="password" /><br /> <label for="password">Password</label><input type="password" name="password" placeholder="Enter Password" id="password" /> <span id="password-notify" class="label label-important"></span> <br />
<button class="btn btn-primary" id="register" type="submit">Register Now</button> <button class="btn btn-primary" id="register" type="submit">Register Now</button>
</form> </form>
</div> </div>
<div class="well span6 {alternate_logins:display}"> <div class="well span6 {alternate_logins:display}">
<h4>Alternative Logins</h4> <h4>Alternative Registration</h4>
<ul class="alt-logins"> <ul class="alt-logins">
<li data-url="/auth/twitter" class="twitter {twitter:display}"></li> <li data-url="/auth/twitter" class="twitter {twitter:display}"></li>
<li data-url="/auth/google" class="google {google:display}"></li> <li data-url="/auth/google" class="google {google:display}"></li>
@ -24,7 +24,8 @@
register = document.getElementById('register'), register = document.getElementById('register'),
emailEl = document.getElementById('email'), emailEl = document.getElementById('email'),
username_notify = document.getElementById('username-notify'), username_notify = document.getElementById('username-notify'),
email_notify = document.getElementById('email-notify'); email_notify = document.getElementById('email-notify'),
password_notify = document.getElementById('password-notify');
username.onkeyup = function() { username.onkeyup = function() {
if (username.value.length > 2) socket.emit('user.exists', {username: username.value}); if (username.value.length > 2) socket.emit('user.exists', {username: username.value});
@ -36,6 +37,13 @@
emailEl.addEventListener('change', function() { emailEl.addEventListener('change', function() {
socket.emit('user.email.exists', { email: emailEl.value }); socket.emit('user.email.exists', { email: emailEl.value });
}, false); }, false);
password.addEventListener('keyup', function() {
if (password.value.length < 5) {
password_notify.innerHTML = 'Password too short';
} else {
password_notify.innerHTML = '';
}
}, false);
ajaxify.register_events(['user.exists', 'user.email.exists']); ajaxify.register_events(['user.exists', 'user.email.exists']);
@ -63,5 +71,34 @@
document.location.href = e.target.getAttribute('data-url'); document.location.href = e.target.getAttribute('data-url');
} }
}); });
// Form Validation
function validateForm() {
var validated = true;
if (username.value.length < 2) {
username_notify.innerHTML = 'Invalid username';
username_notify.className = 'label label-important';
validated = false;
}
if (password.value.length < 5) {
password_notify.innerHTML = 'Password too short';
validated = false;
} else {
password_notify.innerHTML = '';
}
if (email.value.indexOf('@') === -1) {
email_notify.innerHTML = 'Invalid email address';
validated = false;
} else {
email_notify.innerHTML = '';
}
return validated;
}
register.addEventListener('click', function(e) {
if (!validateForm()) e.preventDefault();
}, false);
}()); }());
</script> </script>

@ -1,4 +1,7 @@
var user = require('./../user.js'),
topics = require('./../topics.js');
(function(Admin) { (function(Admin) {
Admin.create_routes = function(app) { Admin.create_routes = function(app) {
@ -29,7 +32,7 @@
if (req.params.tab == 'search') { if (req.params.tab == 'search') {
res.send(JSON.stringify({search_display: 'block', users: []})) res.send(JSON.stringify({search_display: 'block', users: []}))
} else { } else {
global.modules.user.getUserList(function(data){ user.getUserList(function(data){
res.send(JSON.stringify({search_display: 'none', users:data})); res.send(JSON.stringify({search_display: 'none', users:data}));
}); });
} }
@ -39,13 +42,13 @@
if (req.params.tab == 'disabled') { if (req.params.tab == 'disabled') {
res.send(JSON.stringify({categories: []})); res.send(JSON.stringify({categories: []}));
} else { } else {
global.modules.categories.get(function(data) { categories.get(function(data) {
res.send(JSON.stringify(data)); res.send(JSON.stringify(data));
}); });
} }
break; break;
case 'topics' : case 'topics' :
global.modules.topics.get(function(data) { topics.get(function(data) {
res.send(JSON.stringify(data)); res.send(JSON.stringify(data));
}); });
break; break;

@ -138,9 +138,8 @@
})); }));
app.post('/register', function(req, res) { app.post('/register', function(req, res) {
console.log('wtf');
user_module.create(req.body.username, req.body.password, req.body.email, function(err, uid) { user_module.create(req.body.username, req.body.password, req.body.email, function(err, uid) {
if (err === null) { if (err === null && uid > 0) {
req.login({ req.login({
uid: uid uid: uid
}, function() { }, function() {

@ -0,0 +1,95 @@
var user = require('./../user.js');
(function(User) {
User.create_routes = function(app) {
app.get('/uid/:uid', function(req, res) {
if(!req.params.uid)
return res.redirect('/403');
user.getUserData(req.params.uid, function(data){
if(data)
res.send(data);
else
res.send("User doesn't exist!");
});
});
app.get('/users', function(req, res) {
user.getUserList(function(data) {
res.send(templates['header'] + app.create_route("users", "users") + templates['footer']);
});
});
app.get('/users/:username*', function(req, res) {
if(!req.params.username) {
res.send("User doesn't exist!");
return;
}
user.get_uid_by_username(req.params.username, function(uid) {
if(!uid) {
res.redirect('/403');
return;
}
user.getUserData(uid, function(data) {
if(data) {
res.send(templates['header'] + app.create_route('users/'+data.username, 'account') + templates['footer']);
}
else {
res.redirect('/403');
}
});
});
});
/*
function api_method(req, res) {
switch(req.params.method) {
case 'users' :
if (req.params.tab == 'search') {
res.send(JSON.stringify({search_display: 'block', users: []}))
} else {
user.getUserList(function(data){
res.send(JSON.stringify({search_display: 'none', users:data}));
});
}
break;
case 'categories':
if (req.params.tab == 'disabled') {
res.send(JSON.stringify({categories: []}));
} else {
categories.get(function(data) {
res.send(JSON.stringify(data));
});
}
break;
case 'topics' :
topics.get(function(data) {
res.send(JSON.stringify(data));
});
break;
default :
res.send('{}');
}
}
app.get('/api/admin/:method/:tab?*', api_method);
app.get('/api/admin/:method*', api_method);*/
};
}(exports));

@ -1,3 +1,6 @@
var fs = require('fs');
// to be deprecated in favour of client-side only templates. // to be deprecated in favour of client-side only templates.
(function(Templates) { (function(Templates) {
@ -7,7 +10,7 @@
function loadTemplates(templatesToLoad) { function loadTemplates(templatesToLoad) {
for (var t in templatesToLoad) { for (var t in templatesToLoad) {
(function(file) { (function(file) {
modules.fs.readFile(global.configuration.ROOT_DIRECTORY + '/public/templates/' + file + '.tpl', function(err, html) { fs.readFile(global.configuration.ROOT_DIRECTORY + '/public/templates/' + file + '.tpl', function(err, html) {
var template = function() { var template = function() {
this.toString = function() { this.toString = function() {
return this.html; return this.html;

@ -1,4 +1,6 @@
var config = require('../config.js'),
var config = require('../config.js'),
utils = require('./utils.js'), utils = require('./utils.js'),
RDB = require('./redis.js'), RDB = require('./redis.js'),
crypto = require('crypto'), crypto = require('crypto'),
@ -76,8 +78,14 @@ var config = require('../config.js'),
for(var i=0,ii=fields.length; i<ii; ++i) { for(var i=0,ii=fields.length; i<ii; ++i) {
key = fields[i]; key = fields[i];
if(data[key] !== undefined) if(data[key] !== undefined) {
User.setUserField(uid, key, data[key]); User.setUserField(uid, key, data[key]);
if(key === 'email') {
User.setUserField(uid, 'gravatarpicture', User.createGravatarURLFromEmail(data[key]));
}
}
} }
} }
@ -237,60 +245,49 @@ var config = require('../config.js'),
User.create = function(username, password, email, callback) { User.create = function(username, password, email, callback) {
if(!username) { User.exists(username, function(exists) {
console.log("invalid registration data! username ["+username+"], password ["+password+"], email ["+email+"]"); if (exists || email.indexOf('@') === -1 || password.length < 5) return callback(null, -1);
return;
}
// TODO : check if username email is unique!! -baris
RDB.incr('global:next_user_id', function(err, uid) { RDB.incr('global:next_user_id', function(err, uid) {
RDB.handle(err); RDB.handle(err);
User.hashPassword(password, function(hash) {
console.log("Registering uid : " + uid); var gravatar = User.createGravatarURLFromEmail(email);
User.hashPassword(password, function(hash) { RDB.hmset('user:'+uid, {
'username' : username,
var gravatar = User.createGravatarURLFromEmail(email); 'fullname': '',
'location':'',
RDB.hmset('user:'+uid, { 'birthday':'',
'username' : username, 'website':'',
'fullname': '', 'email' : email,
'location':'', 'joindate' : new Date().getTime(),
'birthday':'', 'password' : hash,
'website':'', 'picture': gravatar,
'email' : email, 'gravatarpicture' : gravatar,
'joindate' : new Date().getTime(), 'uploadedpicture': '',
'password' : hash, 'reputation': 0,
'picture': gravatar, 'postcount': 0
'gravatarpicture' : gravatar, });
'uploadedpicture': '',
'reputation': 0, RDB.set('username:' + username + ':uid', uid);
'postcount': 0 RDB.set('email:' + email +':uid', uid);
});
if(email)
User.sendConfirmationEmail(email);
RDB.set('username:' + username + ':uid', uid); RDB.incr('usercount', function(err, count) {
RDB.set('email:' + email +':uid', uid); RDB.handle(err);
if(email) io.sockets.emit('user.count', {count: count});
User.sendConfirmationEmail(email); });
RDB.incr('usercount', function(err, count) {
RDB.handle(err);
io.sockets.emit('user.count', {count: count});
});
RDB.lpush('userlist', username); RDB.lpush('userlist', username);
io.sockets.emit('user.latest', {username: username}); io.sockets.emit('user.latest', {username: username});
callback(null, uid); callback(null, uid);
});
}); });
}); });
}; };
User.createGravatarURLFromEmail = function(email) { User.createGravatarURLFromEmail = function(email) {

@ -8,9 +8,14 @@ var express = require('express'),
redisServer = redis.createClient(config.redis.port, config.redis.host, config.redis.options), redisServer = redis.createClient(config.redis.port, config.redis.host, config.redis.options),
user = require('./user.js'), user = require('./user.js'),
categories = require('./categories.js'),
posts = require('./posts.js'),
topics = require('./topics.js'),
utils = require('./utils.js'), utils = require('./utils.js'),
fs = require('fs'), fs = require('fs'),
admin = require('./routes/admin.js'), admin = require('./routes/admin.js'),
userRoute = require('./routes/user.js'),
auth = require('./routes/authentication.js'); auth = require('./routes/authentication.js');
@ -40,18 +45,18 @@ var express = require('express'),
if (/^\/api\//.test(req.url)) return next(); if (/^\/api\//.test(req.url)) return next();
if (req.user && req.user.uid) { if (req.user && req.user.uid) {
global.modules.user.session_ping(req.sessionID, req.user.uid); user.session_ping(req.sessionID, req.user.uid);
} }
// (Re-)register the session as active // (Re-)register the session as active
global.modules.user.active.register(req.sessionID); user.active.register(req.sessionID);
next(); next();
}); });
auth.create_routes(app); auth.create_routes(app);
admin.create_routes(app); admin.create_routes(app);
userRoute.create_routes(app);
app.create_route = function(url, tpl) { // to remove app.create_route = function(url, tpl) { // to remove
@ -98,7 +103,7 @@ var express = require('express'),
function api_method(req, res) { function api_method(req, res) {
switch(req.params.method) { switch(req.params.method) {
case 'home' : case 'home' :
global.modules.categories.get(function(data) { categories.get(function(data) {
res.send(JSON.stringify(data)); res.send(JSON.stringify(data));
}); });
break; break;
@ -147,27 +152,27 @@ var express = require('express'),
res.send(JSON.stringify(data)); res.send(JSON.stringify(data));
break; break;
case 'topic' : case 'topic' :
global.modules.posts.get(function(data) { posts.get(function(data) {
res.send(JSON.stringify(data)); res.send(JSON.stringify(data));
}, req.params.id, (req.user) ? req.user.uid : 0); }, req.params.id, (req.user) ? req.user.uid : 0);
break; break;
case 'category' : case 'category' :
global.modules.topics.get(function(data) { topics.get(function(data) {
res.send(JSON.stringify(data)); res.send(JSON.stringify(data));
}, req.params.id, (req.user) ? req.user.uid : 0); }, req.params.id, (req.user) ? req.user.uid : 0);
break; break;
case 'latest' : case 'latest' :
global.modules.topics.get(function(data) { topics.get(function(data) {
res.send(JSON.stringify(data)); res.send(JSON.stringify(data));
}); });
break; break;
case 'popular' : case 'popular' :
global.modules.topics.get(function(data) { topics.get(function(data) {
res.send(JSON.stringify(data)); res.send(JSON.stringify(data));
}); });
break; break;
case 'active' : case 'active' :
global.modules.topics.get(function(data) { topics.get(function(data) {
res.send(JSON.stringify(data)); res.send(JSON.stringify(data));
}); });
break; break;
@ -189,7 +194,7 @@ var express = require('express'),
break; break;
case 'confirm': case 'confirm':
global.modules.user.email.confirm(req.params.id, function(data) { user.email.confirm(req.params.id, function(data) {
if (data.status === 'ok') { if (data.status === 'ok') {
res.send(JSON.stringify({ res.send(JSON.stringify({
'alert-class': 'alert-success', 'alert-class': 'alert-success',
@ -268,7 +273,7 @@ var express = require('express'),
return; return;
} }
filename = uid + '-' + filename filename = uid + '-' + filename;
var uploadPath = config.upload_path + filename; var uploadPath = config.upload_path + filename;
console.log('trying to upload to : '+ global.configuration['ROOT_DIRECTORY'] + uploadPath); console.log('trying to upload to : '+ global.configuration['ROOT_DIRECTORY'] + uploadPath);
@ -340,21 +345,23 @@ var express = require('express'),
function get_account_fn(req, res, callback) { function get_account_fn(req, res, callback) {
var username = req.params.id; var username = req.params.id;
console.log("derp");
user.get_uid_by_username(username, function(uid) { user.get_uid_by_username(username, function(uid) {
user.getUserData(uid, function(data) { user.getUserData(uid, function(data) {
if(data) if(data)
{ {
data.joindate = utils.relativeTime(data.joindate); data.joindate = utils.relativeTime(data.joindate);
data.age = new Date().getFullYear() - new Date(data.birthday).getFullYear();; data.age = new Date().getFullYear() - new Date(data.birthday).getFullYear();
console.log(data.age);
if(data.age === null)
data.age = 0;
data.uid = uid; data.uid = uid;
callback({ data.yourid = (req.user)?req.user.uid : 0;
yourid: (req.user)?req.user.uid : 0, data.theirid = uid;
theirid: uid,
user: data callback(data);
});
} }
else else
callback({user:{}}); callback({user:{}});
@ -368,31 +375,7 @@ var express = require('express'),
callback({users:data}); callback({users:data});
}); });
} }
app.get('/uid/:uid', function(req, res) {
if(!req.params.uid)
return res.redirect('/403');
user.getUserData(req.params.uid, function(data){
if(data)
res.send(data);
else
res.send("User doesn't exist!");
});
});
app.get('/users', function(req, res) {
user.getUserList(function(data){
res.send(templates['header'] + app.create_route("users", "users") + templates['footer']);
});
});
app.get('/users/:uid/edit', function(req, res){ app.get('/users/:uid/edit', function(req, res){
@ -407,37 +390,10 @@ var express = require('express'),
return res.redirect('/403'); return res.redirect('/403');
}); });
}); });
app.get('/users/:username*', handleUserProfile);
function handleUserProfile(req, res) {
if(!req.params.username) {
res.send("User doesn't exist!");
return;
}
user.get_uid_by_username(req.params.username, function(uid) {
if(!uid) {
res.redirect('/403');
return;
}
user.getUserData(uid, function(data) {
if(data) {
res.send(templates['header'] + app.create_route('users/'+data.username, 'account') + templates['footer']);
}
else {
res.redirect('/403');
}
});
});
}
app.get('/test', function(req, res) { app.get('/test', function(req, res) {
global.modules.posts.getRawContent(11, function(post) { posts.getRawContent(11, function(post) {
res.send(JSON.stringify(post)); res.send(JSON.stringify(post));
}); });
}); });

@ -1,17 +1,19 @@
var SocketIO = require('socket.io').listen(global.server,{log:false}),
var SocketIO = require('socket.io').listen(global.server,{log:false}),
cookie = require('cookie'), cookie = require('cookie'),
connect = require('connect'), connect = require('connect'),
config = require('../config.js'); config = require('../config.js'),
user = require('./user.js'),
posts = require('./posts.js'),
topics = require('./topics.js'),
categories = require('./categories.js'),
templates = require('./templates.js');
(function(io) { (function(io) {
var modules = null, var users = {},
users = {},
rooms = {} rooms = {}
global.io = io; global.io = io;
module.exports.init = function() {
modules = global.modules;
}
// Adapted from http://howtonode.org/socket-io-auth // Adapted from http://howtonode.org/socket-io-auth
io.set('authorization', function(handshakeData, accept) { io.set('authorization', function(handshakeData, accept) {
@ -30,7 +32,7 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
// Otherwise, continue unimpeded. // Otherwise, continue unimpeded.
var sessionID = handshakeData.sessionID; var sessionID = handshakeData.sessionID;
global.modules.user.get_uid_by_session(sessionID, function(userId) { user.get_uid_by_session(sessionID, function(userId) {
if (userId) if (userId)
{ {
users[sessionID] = userId; users[sessionID] = userId;
@ -47,10 +49,10 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
var hs = socket.handshake; var hs = socket.handshake;
var uid = users[hs.sessionID]; var uid = users[hs.sessionID];
if (DEVELOPMENT === true) { if (DEVELOPMENT === true) {
// refreshing templates // refreshing templates
modules.templates.init(); templates.init();
} }
/*process.on('uncaughtException', function(err) { /*process.on('uncaughtException', function(err) {
@ -93,7 +95,7 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
} }
modules.user.get_usernames_by_uids(uids, function(usernames) { user.get_usernames_by_uids(uids, function(usernames) {
io.sockets.in(data.enter).emit('api:get_users_in_room', { io.sockets.in(data.enter).emit('api:get_users_in_room', {
usernames: usernames, usernames: usernames,
uids: uids, uids: uids,
@ -111,7 +113,7 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
socket.on('api:updateHeader', function(data) { socket.on('api:updateHeader', function(data) {
if(uid) { if(uid) {
modules.user.getUserFields(uid, data.fields, function(fields) { user.getUserFields(uid, data.fields, function(fields) {
fields.uid = uid; fields.uid = uid;
socket.emit('api:updateHeader', fields); socket.emit('api:updateHeader', fields);
}); });
@ -128,107 +130,107 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
}); });
socket.on('user.exists', function(data) { socket.on('user.exists', function(data) {
modules.user.exists(data.username, function(exists){ user.exists(data.username, function(exists){
socket.emit('user.exists', {exists: exists}); socket.emit('user.exists', {exists: exists});
}); });
}); });
socket.on('user.count', function(data) { socket.on('user.count', function(data) {
modules.user.count(socket, data); user.count(socket, data);
}); });
socket.on('user.latest', function(data) { socket.on('user.latest', function(data) {
modules.user.latest(socket, data); user.latest(socket, data);
}); });
socket.on('user.email.exists', function(data) { socket.on('user.email.exists', function(data) {
modules.user.email.exists(socket, data.email); user.email.exists(socket, data.email);
}); });
socket.on('user:reset.send', function(data) { socket.on('user:reset.send', function(data) {
modules.user.reset.send(socket, data.email); user.reset.send(socket, data.email);
}); });
socket.on('user:reset.valid', function(data) { socket.on('user:reset.valid', function(data) {
modules.user.reset.validate(socket, data.code); user.reset.validate(socket, data.code);
}); });
socket.on('user:reset.commit', function(data) { socket.on('user:reset.commit', function(data) {
modules.user.reset.commit(socket, data.code, data.password); user.reset.commit(socket, data.code, data.password);
}); });
socket.on('api:topics.post', function(data) { socket.on('api:topics.post', function(data) {
modules.topics.post(socket, uid, data.title, data.content, data.category_id); topics.post(socket, uid, data.title, data.content, data.category_id);
}); });
socket.on('api:posts.reply', function(data) { socket.on('api:posts.reply', function(data) {
modules.posts.reply(socket, data.topic_id, uid, data.content); posts.reply(socket, data.topic_id, uid, data.content);
}); });
socket.on('api:user.active.get', function() { socket.on('api:user.active.get', function() {
modules.user.active.get(); user.active.get();
}); });
socket.on('api:posts.favourite', function(data) { socket.on('api:posts.favourite', function(data) {
modules.posts.favourite(io, data.pid, data.room_id, uid); posts.favourite(io, data.pid, data.room_id, uid);
}); });
socket.on('api:posts.unfavourite', function(data) { socket.on('api:posts.unfavourite', function(data) {
modules.posts.unfavourite(io, data.pid, data.room_id, uid); posts.unfavourite(io, data.pid, data.room_id, uid);
}); });
socket.on('api:user.active.get_record', function() { socket.on('api:user.active.get_record', function() {
modules.user.active.get_record(socket); user.active.get_record(socket);
}); });
socket.on('api:topic.delete', function(data) { socket.on('api:topic.delete', function(data) {
modules.topics.delete(data.tid, uid, socket); topics.delete(data.tid, uid, socket);
}); });
socket.on('api:topic.restore', function(data) { socket.on('api:topic.restore', function(data) {
modules.topics.restore(data.tid, uid, socket); topics.restore(data.tid, uid, socket);
}); });
socket.on('api:topic.lock', function(data) { socket.on('api:topic.lock', function(data) {
modules.topics.lock(data.tid, uid, socket); topics.lock(data.tid, uid, socket);
}); });
socket.on('api:topic.unlock', function(data) { socket.on('api:topic.unlock', function(data) {
modules.topics.unlock(data.tid, uid, socket); topics.unlock(data.tid, uid, socket);
}); });
socket.on('api:topic.pin', function(data) { socket.on('api:topic.pin', function(data) {
modules.topics.pin(data.tid, uid, socket); topics.pin(data.tid, uid, socket);
}); });
socket.on('api:topic.unpin', function(data) { socket.on('api:topic.unpin', function(data) {
modules.topics.unpin(data.tid, uid, socket); topics.unpin(data.tid, uid, socket);
}); });
socket.on('api:categories.get', function() { socket.on('api:categories.get', function() {
modules.categories.get(function(categories) { categories.get(function(categories) {
socket.emit('api:categories.get', categories); socket.emit('api:categories.get', categories);
}); });
}); });
socket.on('api:topic.move', function(data) { socket.on('api:topic.move', function(data) {
modules.topics.move(data.tid, data.cid, socket); topics.move(data.tid, data.cid, socket);
}); });
socket.on('api:posts.getRawPost', function(data) { socket.on('api:posts.getRawPost', function(data) {
modules.posts.getRawContent(data.pid, socket); posts.getRawContent(data.pid, socket);
}); });
socket.on('api:posts.edit', function(data) { socket.on('api:posts.edit', function(data) {
modules.posts.edit(uid, data.pid, data.content); posts.edit(uid, data.pid, data.content);
}); });
socket.on('api:posts.delete', function(data) { socket.on('api:posts.delete', function(data) {
modules.posts.delete(uid, data.pid); posts.delete(uid, data.pid);
}); });
socket.on('api:posts.restore', function(data) { socket.on('api:posts.restore', function(data) {
modules.posts.restore(uid, data.pid); posts.restore(uid, data.pid);
}); });
}); });

Loading…
Cancel
Save