From eb606855bc6b27baf48de76e830f15ce9ffdf191 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 13 May 2013 14:38:08 -0400 Subject: [PATCH 01/15] updating config defaults to automatically construct upload_url --- config.default.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/config.default.js b/config.default.js index 69c0d7a9c0..3ebaee8e95 100644 --- a/config.default.js +++ b/config.default.js @@ -5,9 +5,6 @@ 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": "http://localhost", - // public url for uploaded files - "upload_url": "http://dev.domain.com/uploads/", - // relative path for uploads "upload_path": "/uploads/", @@ -54,5 +51,6 @@ var config = { } 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; \ No newline at end of file From 62bffff3c7a89ca90a157662c7498987466f8cfb Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Mon, 13 May 2013 15:16:54 -0400 Subject: [PATCH 02/15] forgot to add a ; --- src/webserver.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webserver.js b/src/webserver.js index a5146a2e83..4608a6401d 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -268,7 +268,7 @@ var express = require('express'), return; } - filename = uid + '-' + filename + filename = uid + '-' + filename; var uploadPath = config.upload_path + filename; console.log('trying to upload to : '+ global.configuration['ROOT_DIRECTORY'] + uploadPath); From 8bb724e9946239dcb12cc927438e23a07ad22cd5 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 13 May 2013 15:15:59 -0400 Subject: [PATCH 03/15] minor tweaks to config default, and text copy update on registration page updated readme to mention the upload_path option --- README.md | 4 ++++ config.default.js | 2 +- public/templates/register.tpl | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1553785f39..40485cedae 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,10 @@ The server configuration file (located at `/config.js`) contains default options base_url (Default: 'http://localhost') A web-accessible URL to your app, without the port + + upload_path + (Default: '/public/uploads') A relative path (relative to the application's web root) to the uploads folder. Please ensure that Node.js can write to this folder + use_port (Default: true) 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. diff --git a/config.default.js b/config.default.js index 3ebaee8e95..e7a662b76b 100644 --- a/config.default.js +++ b/config.default.js @@ -6,7 +6,7 @@ var config = { "base_url": "http://localhost", // relative path for uploads - "upload_path": "/uploads/", + "upload_path": "/public/uploads/", "use_port": true, "port": 4567, diff --git a/public/templates/register.tpl b/public/templates/register.tpl index b21f73a333..d1856915d5 100644 --- a/public/templates/register.tpl +++ b/public/templates/register.tpl @@ -9,7 +9,7 @@
-

Alternative Logins

+

Alternative Registration

  • From 6942107dd46ad270f963a4d115581ad111cc3762 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Mon, 13 May 2013 16:41:28 -0400 Subject: [PATCH 04/15] regen gravatar url when email changes --- src/user.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/user.js b/src/user.js index a557e97a80..2d9a6fa018 100644 --- a/src/user.js +++ b/src/user.js @@ -76,8 +76,14 @@ var config = require('../config.js'), for(var i=0,ii=fields.length; i Date: Mon, 13 May 2013 16:57:47 -0400 Subject: [PATCH 05/15] added client and server validation on registration --- public/templates/register.tpl | 43 ++++++++++++++++-- src/routes/authentication.js | 3 +- src/user.js | 83 +++++++++++++++-------------------- 3 files changed, 77 insertions(+), 52 deletions(-) diff --git a/public/templates/register.tpl b/public/templates/register.tpl index d1856915d5..875b3bab8d 100644 --- a/public/templates/register.tpl +++ b/public/templates/register.tpl @@ -2,9 +2,9 @@
    -
    +

    -
    +
    @@ -24,7 +24,8 @@ register = document.getElementById('register'), emailEl = document.getElementById('email'), 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() { if (username.value.length > 2) socket.emit('user.exists', {username: username.value}); @@ -36,6 +37,13 @@ emailEl.addEventListener('change', function() { socket.emit('user.email.exists', { email: emailEl.value }); }, 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']); @@ -63,5 +71,34 @@ 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); }()); \ No newline at end of file diff --git a/src/routes/authentication.js b/src/routes/authentication.js index e6d8a93cfe..e9c17d29ea 100644 --- a/src/routes/authentication.js +++ b/src/routes/authentication.js @@ -138,9 +138,8 @@ })); app.post('/register', function(req, res) { - console.log('wtf'); 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({ uid: uid }, function() { diff --git a/src/user.js b/src/user.js index a557e97a80..15d3674dfd 100644 --- a/src/user.js +++ b/src/user.js @@ -237,60 +237,49 @@ var config = require('../config.js'), User.create = function(username, password, email, callback) { - if(!username) { - console.log("invalid registration data! username ["+username+"], password ["+password+"], email ["+email+"]"); - return; - } - - // TODO : check if username email is unique!! -baris - + User.exists(username, function(exists) { + if (exists || email.indexOf('@') === -1 || password.length < 5) return callback(null, -1); - RDB.incr('global:next_user_id', function(err, uid) { - RDB.handle(err); - - console.log("Registering uid : " + uid); - - User.hashPassword(password, function(hash) { - - var gravatar = User.createGravatarURLFromEmail(email); - - RDB.hmset('user:'+uid, { - 'username' : username, - 'fullname': '', - 'location':'', - 'birthday':'', - 'website':'', - 'email' : email, - 'joindate' : new Date().getTime(), - 'password' : hash, - 'picture': gravatar, - 'gravatarpicture' : gravatar, - 'uploadedpicture': '', - 'reputation': 0, - 'postcount': 0 - }); + RDB.incr('global:next_user_id', function(err, uid) { + RDB.handle(err); + User.hashPassword(password, function(hash) { + var gravatar = User.createGravatarURLFromEmail(email); + + RDB.hmset('user:'+uid, { + 'username' : username, + 'fullname': '', + 'location':'', + 'birthday':'', + 'website':'', + 'email' : email, + 'joindate' : new Date().getTime(), + 'password' : hash, + 'picture': gravatar, + 'gravatarpicture' : gravatar, + 'uploadedpicture': '', + 'reputation': 0, + 'postcount': 0 + }); + + RDB.set('username:' + username + ':uid', uid); + RDB.set('email:' + email +':uid', uid); + + if(email) + User.sendConfirmationEmail(email); - RDB.set('username:' + username + ':uid', uid); - RDB.set('email:' + email +':uid', uid); + RDB.incr('usercount', function(err, count) { + RDB.handle(err); - if(email) - User.sendConfirmationEmail(email); - - RDB.incr('usercount', function(err, count) { - RDB.handle(err); - - io.sockets.emit('user.count', {count: count}); - }); + io.sockets.emit('user.count', {count: count}); + }); - RDB.lpush('userlist', username); - io.sockets.emit('user.latest', {username: username}); + RDB.lpush('userlist', username); + io.sockets.emit('user.latest', {username: username}); - callback(null, uid); - + callback(null, uid); + }); }); - }); - }; User.createGravatarURLFromEmail = function(email) { From d7b6141e31f8406aae8a22c3c3be7aa708b28d03 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Mon, 13 May 2013 17:02:10 -0400 Subject: [PATCH 06/15] button to change picture --- public/css/style.less | 1 + public/templates/accountedit.tpl | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/public/css/style.less b/public/css/style.less index b57ab30238..65cdccb76b 100644 --- a/public/css/style.less +++ b/public/css/style.less @@ -386,6 +386,7 @@ footer.footer { .user-profile-picture { width:128px; height:128px; + margin-bottom:10px; } .user-8080-picture { diff --git a/public/templates/accountedit.tpl b/public/templates/accountedit.tpl index 2b327d8eab..195f9bbcc0 100644 --- a/public/templates/accountedit.tpl +++ b/public/templates/accountedit.tpl @@ -21,7 +21,7 @@ Gravatar
    - +
    Uploaded picture @@ -75,7 +75,7 @@ From f662353cbfc1938d9b7224fe932635830eb25826 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 13 May 2013 17:30:51 -0400 Subject: [PATCH 07/15] fixes to thread avatar on phone --- public/css/style.less | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/public/css/style.less b/public/css/style.less index b57ab30238..9206448f4d 100644 --- a/public/css/style.less +++ b/public/css/style.less @@ -260,6 +260,11 @@ footer.footer { line-height: 18px; padding: 5px; padding-left: 10px; + + img.hidden-desktop { + max-width: 10px; + max-height: 10px; + } } .post-content { min-height: 50px; From 901b378912055684645b901e857f7b055fff3c87 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Mon, 13 May 2013 17:40:14 -0400 Subject: [PATCH 08/15] css fix --- public/templates/accountedit.tpl | 107 ++++++++++++++++--------------- src/webserver.js | 6 +- 2 files changed, 61 insertions(+), 52 deletions(-) diff --git a/public/templates/accountedit.tpl b/public/templates/accountedit.tpl index 195f9bbcc0..f2ed3d5e70 100644 --- a/public/templates/accountedit.tpl +++ b/public/templates/accountedit.tpl @@ -73,57 +73,62 @@ edit
    - - - -
    -
    -
    - -
    - -
    -
    - -
    - -
    - -
    -
    - -
    - -
    - -
    -
    - -
    - -
    - -
    -
    - -
    - -
    - -
    -
    - - - - - -
    +
    +
    + +
    + +
    +
    +
    +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + + + + + +
    +
    +
    diff --git a/src/webserver.js b/src/webserver.js index 4608a6401d..7cb4904b37 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -347,7 +347,11 @@ var express = require('express'), if(data) { 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.birthday); + console.log(new Date(data.birthday).getFullYear()); + data.uid = uid; callback({ From 0bb0fd5789ff4aba91a9e3ec7d1af69a47fe154c Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Mon, 13 May 2013 17:40:51 -0400 Subject: [PATCH 09/15] removed debug console.logs --- src/webserver.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/webserver.js b/src/webserver.js index 7cb4904b37..557b399218 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -348,10 +348,6 @@ var express = require('express'), { data.joindate = utils.relativeTime(data.joindate); data.age = new Date().getFullYear() - new Date(data.birthday).getFullYear(); - - console.log(data.birthday); - console.log(new Date(data.birthday).getFullYear()); - data.uid = uid; callback({ From d564811b71bca3b93c4913780f1b1f596414b57b Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Tue, 14 May 2013 11:32:37 -0400 Subject: [PATCH 10/15] fixed the data passing to accountedit.tpl --- public/templates/account.tpl | 25 ++++++++-------- public/templates/accountedit.tpl | 49 +++++++++++--------------------- src/webserver.js | 9 +++--- 3 files changed, 33 insertions(+), 50 deletions(-) diff --git a/public/templates/account.tpl b/public/templates/account.tpl index 5b870e6c59..06f9ad4a73 100644 --- a/public/templates/account.tpl +++ b/public/templates/account.tpl @@ -6,48 +6,47 @@

    - - + diff --git a/public/templates/accountedit.tpl b/public/templates/accountedit.tpl index f2ed3d5e70..a61c081a67 100644 --- a/public/templates/accountedit.tpl +++ b/public/templates/accountedit.tpl @@ -6,7 +6,6 @@

- - - -
@@ -87,63 +83,56 @@
- +
- +
- +
- +
- +
- +
- - - -
{user.picture}
-
{user.gravatarpicture}
-
{user.uploadedpicture}
- - - - + +