@ -110,6 +110,7 @@ passport.deserializeUser(function(uid, done) {
next ( ) ;
} ) ;
// Dunno wtf this does
// app.use(express.logger({ format: '\x1b[1m:method\x1b[0m \x1b[33m:url\x1b[0m :response-time ms' }));
// Useful if you want to use app.put and app.delete (instead of app.post all the time)
@ -124,7 +125,7 @@ passport.deserializeUser(function(uid, done) {
// 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' ];
var routes = [ '' , 'login' , 'register' , 'account' , 'latest' , 'popular' , 'active' ];
for ( var i = 0 , ii = routes . length ; i < ii ; i ++ ) {
( function ( route ) {
@ -191,11 +192,25 @@ passport.deserializeUser(function(uid, done) {
break ;
case 'category' :
global . modules . topics . get ( function ( data ) {
console . log ( data ) ;
res . send ( JSON . stringify ( data ) ) ;
} , req . params . id ) ;
break ;
case 'account' :
case 'latest' :
global . modules . topics . get ( function ( data ) {
res . send ( JSON . stringify ( data ) ) ;
} ) ;
break ;
case 'popular' :
global . modules . topics . get ( function ( data ) {
res . send ( JSON . stringify ( data ) ) ;
} ) ;
break ;
case 'active' :
global . modules . topics . get ( function ( data ) {
res . send ( JSON . stringify ( data ) ) ;
} ) ;
break ;
case 'users' :
get _account _fn ( req , res , function ( userData ) {
res . send ( JSON . stringify ( userData ) ) ;
} ) ;
@ -313,19 +328,24 @@ passport.deserializeUser(function(uid, done) {
//to baris, move this into account.js or sth later - just moved this out here for you to utilize client side tpl parsing
//I didn't want to change too much so you should probably sort out the params etc
function get _account _fn ( req , res , callback ) {
console . log ( "GOING TO ACCOUNT" ) ;
if ( req . user === undefined )
return res . redirect ( '/403' ) ;
var requestedUserId = req . user . uid ;
user . getUserData ( req . user . uid , function ( data ) {
data . joindate = utils . relativeTime ( data . joindate ) ;
if ( req . params . id != req . user . uid )
requestedUserId = req . params . id ;
console . log ( "user data" + JSON . stringify ( data ) ) ;
var userData = { user : data } ;
callback ( userData ) ;
user . getUserData ( requestedUserId , function ( data ) {
if ( data )
{
data . joindate = utils . relativeTime ( data . joindate ) ;
callback ( { user : data } ) ;
}
else
callback ( { user : { } } ) ;
} ) ;
}
@ -349,11 +369,28 @@ passport.deserializeUser(function(uid, done) {
res . send ( 'User list' ) ;
} ) ;
app . get ( '/users/:username' , function ( req , res ) {
global . modules . user . get _uid _by _username ( req . params . username , function ( uid ) {
res . send ( 'User profile for uid: ' + uid ) ;
app . get ( '/users/:uid' , handleUserProfile ) ;
app . get ( '/users/:uid/:username*' , handleUserProfile ) ;
function handleUserProfile ( req , res ) {
if ( req . params . uid == 0 ) {
res . send ( "User doesn't exist!" ) ;
return ;
}
user . getUserData ( req . params . uid , function ( data ) {
if ( data ) {
if ( req . url . indexOf ( data . username ) == - 1 )
res . redirect ( 301 , '/users/' + req . params . uid + '/' + data . username ) ;
else
res . send ( templates [ 'header' ] + '<script>templates.ready(function(){ajaxify.go("users/' + req . params . uid + '/' + data . username + '");});</script>' + templates [ 'footer' ] ) ;
}
else
res . send ( "User doesn't exist!" ) ;
} ) ;
} ) ;
}
app . get ( '/test' , function ( req , res ) {
global . modules . topics . delete ( 1 , 1 ) ;