diff --git a/public/css/style.less b/public/css/style.less index 9fb17e1184..bd7d559bae 100644 --- a/public/css/style.less +++ b/public/css/style.less @@ -324,6 +324,7 @@ footer.footer { .account-username-box{ border-bottom:1px solid #e3e3e3; + margin-bottom:10px; } .account-username{ @@ -334,6 +335,7 @@ footer.footer { .account-picture-block{ display:inline-block; margin-right:20px; + vertical-align:top; } .account-bio-block{ @@ -347,7 +349,6 @@ footer.footer { } - .category-icon { width: 100%; height: 90px; diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 9423be6c23..448c17d363 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -31,8 +31,12 @@ 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 = 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 22e61ea554..a0ead8319a 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -5,7 +5,14 @@ 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']) { + if (tpl.match(pattern)) { + return (config['custom_mapping'][pattern]); + } + } + } + return false; } templates.ready = function(callback) { @@ -58,7 +65,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' @@ -137,6 +144,11 @@ var templates = {}; } } + if (namespace) { + var regex = new RegExp("{" + namespace + "[^]*?}", 'g'); + template = template.replace(regex, ''); + } + return template; })(data, "", template); @@ -156,18 +168,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/account.tpl b/public/templates/account.tpl index e371c02d3a..7b3f2b3ea7 100644 --- a/public/templates/account.tpl +++ b/public/templates/account.tpl @@ -9,10 +9,9 @@
- {user.username} + {user.username} edit
-
@@ -23,22 +22,34 @@ {user.email}
+ full name + {user.fullname} +
+ + website + {user.website} +
+ + location + {user.location} +
+ + age + {user.age} +
+ member for {user.joindate}
reputation - {user.reputation} + {user.reputation}
posts - {user.postcount} + {user.postcount}
- - -
- - + @@ -47,6 +58,20 @@ \ No newline at end of file diff --git a/public/templates/accountedit.tpl b/public/templates/accountedit.tpl index 1e6f992487..dcb0d4fabc 100644 --- a/public/templates/accountedit.tpl +++ b/public/templates/accountedit.tpl @@ -8,12 +8,62 @@ - +
+ {user.username} + edit +
+ -
- - +
+ +
+ + +
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ + + +
+
@@ -21,6 +71,27 @@ \ No newline at end of file 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", 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/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/topics.js b/src/topics.js index 43c897d919..e06b0458fd 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': [] }); } diff --git a/src/user.js b/src/user.js index beeb94ff94..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); } @@ -239,6 +246,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 23e0ec343e..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); @@ -353,24 +366,17 @@ 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.age = new Date().getFullYear() - new Date(data.birthday).getFullYear();; + data.uid = uid; callback({user:data}); } else @@ -414,9 +420,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'); }); @@ -424,7 +428,6 @@ passport.deserializeUser(function(uid, done) { app.get('/users/:username*', handleUserProfile); - function handleUserProfile(req, res) { if(!req.params.username) { @@ -433,13 +436,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, 'account') + templates['footer']); } else { - res.send("User doesn't exist! /users/"+req.params.username); + res.redirect('/403'); } }); });