From d308242d2d5d4603bab2761af43486cc172443ac Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Wed, 8 May 2013 11:08:56 -0400 Subject: [PATCH 1/8] decimal places for rep and post count --- public/templates/account.tpl | 20 +++++++++++++++++--- public/templates/users.tpl | 26 +++++++++++++++++++++++--- src/webserver.js | 3 ++- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/public/templates/account.tpl b/public/templates/account.tpl index e371c02d3a..1fad9dd15a 100644 --- a/public/templates/account.tpl +++ b/public/templates/account.tpl @@ -28,11 +28,11 @@
reputation - {user.reputation} + {user.reputation}
posts - {user.postcount} + {user.postcount} @@ -47,6 +47,20 @@ \ No newline at end of file diff --git a/public/templates/users.tpl b/public/templates/users.tpl index e782b5a8d9..826c1be78e 100644 --- a/public/templates/users.tpl +++ b/public/templates/users.tpl @@ -11,15 +11,35 @@ {users.username}
- {users.reputation} + {users.reputation}
- {users.postcount} + {users.postcount}
- \ No newline at end of file + + + \ No newline at end of file diff --git a/src/webserver.js b/src/webserver.js index 23e0ec343e..a006e2ffd3 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -436,7 +436,8 @@ passport.deserializeUser(function(uid, done) { user.getUserData(uid, function(data) { if(data) { - res.send(templates['header'] + '' + templates['footer']); + //res.send(templates['header'] + '' + templates['footer']); + res.send(templates['header'] + create_route('users/'+data.username,'users') + templates['footer']); } else { res.send("User doesn't exist! /users/"+req.params.username); From 5e36ca2fbec06cc7e416f0f9aa4ce822ae987711 Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Wed, 8 May 2013 11:10:16 -0400 Subject: [PATCH 2/8] removed dupe function --- src/webserver.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/webserver.js b/src/webserver.js index a006e2ffd3..e5a328d194 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -424,7 +424,6 @@ passport.deserializeUser(function(uid, done) { app.get('/users/:username*', handleUserProfile); - function handleUserProfile(req, res) { if(!req.params.username) { From 36e7baa84d6525cb59c40a191c1ca8ed805d6285 Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Wed, 8 May 2013 11:48:21 -0400 Subject: [PATCH 3/8] userS --- public/src/templates.js | 2 +- src/webserver.js | 27 ++++++++++++--------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/public/src/templates.js b/public/src/templates.js index 22e61ea554..e2e374c18e 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -58,7 +58,7 @@ var templates = {}; function init() { loadTemplates([ - 'header', 'footer', 'register', 'home', 'topic','account', 'category', 'users', + 'header', 'footer', 'register', 'home', 'topic','account', 'category', 'users', 'accountedit', 'login', 'reset', 'reset_code', 'account', 'confirm', 'emails/reset', 'emails/reset_plaintext', 'emails/email_confirm', 'emails/email_confirm_plaintext' diff --git a/src/webserver.js b/src/webserver.js index e5a328d194..c41890dcff 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -353,24 +353,16 @@ 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) { - - if (req.user === undefined) - return res.redirect('/403'); - - var requestedUserId = req.user.uid; var username = req.params.id; user.get_uid_by_username(username, function(uid) { - - if(uid != req.user.uid) - requestedUserId = uid; - user.getUserData(requestedUserId, function(data) { + user.getUserData(uid, function(data) { if(data) { data.joindate = utils.relativeTime(data.joindate); - data.uid = requestedUserId; + data.uid = uid; callback({user:data}); } else @@ -415,7 +407,8 @@ passport.deserializeUser(function(uid, done) { if(req.user && req.params.uid) { - res.send(templates['header'] + '' + templates['footer']); + //res.send(templates['header'] + '' + templates['footer']); + res.send(templates['header'] + create_route('users/'+req.params.uid+'/edit','accountedit') + templates['footer']); } else return res.redirect('/403'); @@ -432,14 +425,18 @@ passport.deserializeUser(function(uid, done) { } 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'] + '' + templates['footer']); - res.send(templates['header'] + create_route('users/'+data.username,'users') + templates['footer']); + res.send(templates['header'] + create_route('users/'+data.username, 'account') + templates['footer']); } else { - res.send("User doesn't exist! /users/"+req.params.username); + res.redirect('/403'); } }); }); From 31e845f4b025e2fc5e566f5d6915efce79bf27ab Mon Sep 17 00:00:00 2001 From: psychobunny Date: Wed, 8 May 2013 16:33:29 +0000 Subject: [PATCH 4/8] added regex matching to templates/ajaxify. needs cleanup, just unblocking baris --- public/src/ajaxify.js | 3 ++- public/src/templates.js | 23 ++++++++++++++--------- public/templates/config.json | 1 + 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 9423be6c23..4bb3b76f94 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -31,8 +31,9 @@ var ajaxify = {}; app.enter_room('global'); var url = url.replace(/\/$/, ""); - var tpl_url = (url === '' || url === '/') ? 'home' : url.split('/')[0]; tpl_url = templates.get_custom_map(tpl_url); + var tpl_url = (url === '' || url === '/') ? 'home' : url.split('/')[0]; + if (templates[tpl_url]) { window.history.pushState({}, url, "/" + url); diff --git a/public/src/templates.js b/public/src/templates.js index e2e374c18e..ca9a721c4b 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -5,7 +5,15 @@ var templates = {}; config = {}; templates.get_custom_map = function(tpl) { - return (config['custom_mapping'] && config['custom_mapping'][tpl]) ? config['custom_mapping'][tpl] : tpl; + if (config['custom_mapping'] && tpl) { + for (var pattern in config['custom_mapping']) { + console.log(pattern); + if (tpl.match(pattern)) { + return (config['custom_mapping'][pattern]); + } + } + } + return false; } templates.ready = function(callback) { @@ -156,18 +164,15 @@ function load_template(callback, custom_tpl) { jQuery.get(API_URL + url, function(data) { - - var splits = url.split('/'); - var tpl = url; - - if(splits.length) { - tpl = splits[0]; - tpl = templates.get_custom_map(tpl); + var tpl = templates.get_custom_map(url); + if (tpl == false) { + tpl = url.split('/')[0]; } if (custom_tpl && custom_tpl != "undefined") tpl = custom_tpl; - + + document.getElementById('content').innerHTML = templates[tpl].parse(JSON.parse(data)); if (callback) callback(); }); diff --git a/public/templates/config.json b/public/templates/config.json index 78bf9e0551..8d23609092 100644 --- a/public/templates/config.json +++ b/public/templates/config.json @@ -1,5 +1,6 @@ { "custom_mapping": { + "users[^]*edit": "accountedit", "users": "account", "latest": "category", "popular": "category", From 187d5a101af2cdccc3f70b66a4962e5caa2c9710 Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Wed, 8 May 2013 12:51:37 -0400 Subject: [PATCH 5/8] edit page --- public/css/style.less | 3 +- public/templates/account.tpl | 9 ++--- public/templates/accountedit.tpl | 58 +++++++++++++++++++++++++++++--- src/user.js | 4 +++ src/webserver.js | 3 -- 5 files changed, 62 insertions(+), 15 deletions(-) diff --git a/public/css/style.less b/public/css/style.less index 22e327e34c..acf74e59b9 100644 --- a/public/css/style.less +++ b/public/css/style.less @@ -325,6 +325,7 @@ footer.footer { .account-username-box{ border-bottom:1px solid #e3e3e3; + margin-bottom:10px; } .account-username{ @@ -335,6 +336,7 @@ footer.footer { .account-picture-block{ display:inline-block; margin-right:20px; + vertical-align:top; } .account-bio-block{ @@ -348,7 +350,6 @@ footer.footer { } - .category-icon { width: 100%; height: 90px; diff --git a/public/templates/account.tpl b/public/templates/account.tpl index 1fad9dd15a..5c859a26ad 100644 --- a/public/templates/account.tpl +++ b/public/templates/account.tpl @@ -9,10 +9,9 @@ -
- - -
- - + diff --git a/public/templates/accountedit.tpl b/public/templates/accountedit.tpl index 1e6f992487..27b9c5856f 100644 --- a/public/templates/accountedit.tpl +++ b/public/templates/accountedit.tpl @@ -8,12 +8,62 @@ - + + -
- - + + + +
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ + +
+ +
+
diff --git a/src/user.js b/src/user.js index beeb94ff94..e17d115f32 100644 --- a/src/user.js +++ b/src/user.js @@ -239,6 +239,10 @@ var config = require('../config.js'), RDB.db.hmset('user:'+uid, { 'username' : username, + 'fullname': '', + 'location':'', + 'birthday':'', + 'website':'', 'email' : email, 'joindate' : new Date().getTime(), 'password' : hash, diff --git a/src/webserver.js b/src/webserver.js index c41890dcff..aeb66b3e05 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -406,10 +406,7 @@ passport.deserializeUser(function(uid, done) { app.get('/users/:uid/edit', function(req, res){ if(req.user && req.params.uid) - { - //res.send(templates['header'] + '' + templates['footer']); res.send(templates['header'] + create_route('users/'+req.params.uid+'/edit','accountedit') + templates['footer']); - } else return res.redirect('/403'); }); From baecab84de9187e01deda54e65ed0bf42c242ad9 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Wed, 8 May 2013 16:57:01 +0000 Subject: [PATCH 6/8] added code to remove fields that are not passed in for templates --- public/src/templates.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/public/src/templates.js b/public/src/templates.js index ca9a721c4b..ba2210bbf2 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -145,6 +145,11 @@ var templates = {}; } } + if (namespace) { + var regex = new RegExp("{" + namespace + "[^]*?}", 'g'); + template = template.replace(regex, ''); + } + return template; })(data, "", template); From 8e1ee88878ce202b288ebe70a1f796cfa4c53793 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Wed, 8 May 2013 17:28:22 +0000 Subject: [PATCH 7/8] removed derpy + from header ill come back to that later when im more inspired... fixed ajaxify for custom routed urls, fixed recent/popular/active tab's invalid object initializer --- public/src/ajaxify.js | 7 +++++-- public/src/templates.js | 1 - public/templates/header.tpl | 2 +- src/topics.js | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 4bb3b76f94..448c17d363 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -31,9 +31,12 @@ var ajaxify = {}; app.enter_room('global'); var url = url.replace(/\/$/, ""); - tpl_url = templates.get_custom_map(tpl_url); - var tpl_url = (url === '' || url === '/') ? 'home' : url.split('/')[0]; + + var tpl_url = templates.get_custom_map(url); + if (tpl_url == false) { + tpl_url = (url === '' || url === '/') ? 'home' : url.split('/')[0]; + } if (templates[tpl_url]) { window.history.pushState({}, url, "/" + url); diff --git a/public/src/templates.js b/public/src/templates.js index ba2210bbf2..a0ead8319a 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -7,7 +7,6 @@ var templates = {}; templates.get_custom_map = function(tpl) { if (config['custom_mapping'] && tpl) { for (var pattern in config['custom_mapping']) { - console.log(pattern); if (tpl.match(pattern)) { return (config['custom_mapping'][pattern]); } diff --git a/public/templates/header.tpl b/public/templates/header.tpl index 60930b77e3..401c12113b 100644 --- a/public/templates/header.tpl +++ b/public/templates/header.tpl @@ -38,7 +38,7 @@ diff --git a/src/topics.js b/src/topics.js index 9697b87b7c..3818581cc8 100644 --- a/src/topics.js +++ b/src/topics.js @@ -98,7 +98,7 @@ var RDB = require('./redis.js'), callback({ 'category_name' : category_id ? category_name : 'Recent', 'show_topic_button' : category_id ? 'show' : 'hidden', - 'category_id': category_id, + 'category_id': category_id || 0, 'topics': topics }); @@ -108,7 +108,7 @@ var RDB = require('./redis.js'), callback({ 'category_name' : category_id ? category_name : 'Recent', 'show_topic_button' : category_id ? 'show' : 'hidden', - 'category_id': category_id, + 'category_id': category_id || 0, 'topics': [] }); } From 5edf7efd8f403cd3b6ee0e718a28f0161f8607fb Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Wed, 8 May 2013 13:43:56 -0400 Subject: [PATCH 8/8] user edit and profile changes --- public/templates/account.tpl | 16 ++++++++++++++++ public/templates/accountedit.tpl | 29 +++++++++++++++++++++++++---- src/user.js | 7 +++++++ src/webserver.js | 14 ++++++++++++++ 4 files changed, 62 insertions(+), 4 deletions(-) diff --git a/public/templates/account.tpl b/public/templates/account.tpl index 5c859a26ad..7b3f2b3ea7 100644 --- a/public/templates/account.tpl +++ b/public/templates/account.tpl @@ -22,6 +22,22 @@ {user.email}
+ + {user.fullname} +
+ + + {user.website} +
+ + + {user.location} +
+ + + {user.age} +
+ {user.joindate}
diff --git a/public/templates/accountedit.tpl b/public/templates/accountedit.tpl index 27b9c5856f..dcb0d4fabc 100644 --- a/public/templates/accountedit.tpl +++ b/public/templates/accountedit.tpl @@ -39,7 +39,7 @@
- +
@@ -58,8 +58,8 @@
- - + Save changes + Cancel
@@ -71,6 +71,27 @@ \ No newline at end of file diff --git a/src/user.js b/src/user.js index e17d115f32..51167d4ca8 100644 --- a/src/user.js +++ b/src/user.js @@ -69,6 +69,13 @@ var config = require('../config.js'), }); } + User.updateUserFields = function(uid, data) { + console.log(data); + for(var key in data) { + User.setUserField(uid, key, data[key]); + } + } + User.setUserField = function(uid, field, value) { RDB.db.hset('user:'+uid, field, value); } diff --git a/src/webserver.js b/src/webserver.js index aeb66b3e05..c4c41c39d1 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -332,6 +332,19 @@ passport.deserializeUser(function(uid, done) { }); }); + app.post('/edituser', function(req, res){ + + if(!req.user) { + res.redirect('/403'); + return; + } + + user.updateUserFields(req.user.uid, req.body); + + res.redirect('/'); + }); + + app.get('/baristest', function(req, res) { /*user.getUserField(req.user.uid, 'email', function(data) { console.log(" I GOT FIELD " +data); @@ -362,6 +375,7 @@ passport.deserializeUser(function(uid, done) { if(data) { data.joindate = utils.relativeTime(data.joindate); + data.age = new Date().getFullYear() - new Date(data.birthday).getFullYear();; data.uid = uid; callback({user:data}); }