From 29bfcd3a3ffb064a762e0d3f8e8dfc40fab7efe9 Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Mon, 27 May 2013 22:03:13 +0100 Subject: [PATCH 1/3] Duplicate user, error handling, password in fixture --- config.js | 3 ++- core/admin/controllers/index.js | 17 +++++++----- core/shared/data/fixtures/001.js | 9 ++++--- .../models/dataProvider.bookshelf.users.js | 27 ++++++++++++------- 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/config.js b/config.js index 5e6813f00a..115eb0ea7c 100644 --- a/config.js +++ b/config.js @@ -68,7 +68,8 @@ connection: { filename: './core/shared/data/testdb.db' }, - debug: true + debug: false + // debug: true }, staging: {}, diff --git a/core/admin/controllers/index.js b/core/admin/controllers/index.js index 95b8c52f90..67510658c8 100755 --- a/core/admin/controllers/index.js +++ b/core/admin/controllers/index.js @@ -64,9 +64,9 @@ console.log('user found: ', user); req.session.user = "ghostadmin"; res.redirect(req.query.redirect || '/ghost/'); - }, function (err) { + }, function (error) { // Do something here to signal the reason for an error - console.log(err.stack); + req.flash('error', error.message); res.redirect('/ghost/login/'); }); }, @@ -78,16 +78,19 @@ }); }, 'doRegister': function (req, res) { - // console.log(req.body); - if (req.body.email_address !== '' && req.body.password.length > 5) { + var email = req.body.email_address, + password = req.body.password; + + if (email !== '' && password.length > 5) { api.users.add({ - email_address: req.body.email_address, - password: req.body.password + email_address: email, + password: password }).then(function (user) { console.log('user added', user); res.redirect('/ghost/login/'); }, function (error) { - console.log('there was an error', error); + req.flash('error', error.message); + res.redirect('/ghost/register/'); }); } else { req.flash('error', "The password is too short. Have at least 6 characters in there"); diff --git a/core/shared/data/fixtures/001.js b/core/shared/data/fixtures/001.js index f2ecbd92d5..849f92a6ae 100644 --- a/core/shared/data/fixtures/001.js +++ b/core/shared/data/fixtures/001.js @@ -50,15 +50,16 @@ module.exports = { users: [ { - "id": "1", - "username": "johnonolan", + "id": "1", + "username": "johnonolan", "first_name": "John", "last_name": "O'Nolan", + "password": "$2a$10$.pb3wOEhbEPvArvOBB.iyuKslBjC7lSXCUzp29civDTvCg3M1j0XO", "email_address": "john@onolan.org", "profile_picture": "logo.png", "cover_picture": "", - "bio": "Interactive designer, public speaker, startup advisor and writer. Living in Austria, attempting world domination via keyboard.", - "url": "john.onolan.org", + "bio": "Interactive designer, public speaker, startup advisor and writer. Living in Austria, attempting world domination via keyboard.", + "url": "john.onolan.org", "created_by": 1, "updated_by": 1 } diff --git a/core/shared/models/dataProvider.bookshelf.users.js b/core/shared/models/dataProvider.bookshelf.users.js index 7407b271a8..eeaf9b443e 100644 --- a/core/shared/models/dataProvider.bookshelf.users.js +++ b/core/shared/models/dataProvider.bookshelf.users.js @@ -30,11 +30,17 @@ // Clone the _user so we don't expose the hashed password unnecessarily userData = _.extend({}, _user); - return nodefn.call(bcrypt.hash, _user.password, null, null).then(function (hash) { - userData.password = hash; - return BaseProvider.prototype.add.call(self, userData); + return self.model.forge({email_address: userData.email_address}).fetch().then(function (user) { + if (!!user.attributes.email_address) { + return when.reject(new Error('A user with that email address already exists.')); + } + return nodefn.call(bcrypt.hash, _user.password, null, null).then(function (hash) { + userData.password = hash; + return BaseProvider.prototype.add.call(self, userData); + }); }); + }; /** @@ -47,12 +53,15 @@ return this.model.forge({ email_address: _userdata.email }).fetch().then(function (user) { - return nodefn.call(bcrypt.compare, _userdata.pw, user.get('password')).then(function (matched) { - if (!matched) { - return when.reject(new Error('Password does not match')); - } - return user; - }); + if (!!user.attributes.email_address) { + return nodefn.call(bcrypt.compare, _userdata.pw, user.get('password')).then(function (matched) { + if (!matched) { + return when.reject(new Error('Passwords do not match')); + } + return user; + }); + } + return when.reject(new Error('We do not have a record for such user.')); }); }; From 5762f9e7380d4073864ceec01fd0723c796bd534 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Mon, 27 May 2013 22:19:26 +0100 Subject: [PATCH 2/3] Updating package.json with grunt-cli package for travis --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 0cf04c5962..54a2841d17 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "start": "node app", - "test": "grunt validate" + "test": "grunt validate --verbose" }, "dependencies": { "express": "3.1.x", @@ -23,6 +23,7 @@ }, "devDependencies": { "grunt": "~0.4.1", + "grunt-cli": "0.1.9", "grunt-jslint": "0.2.x", "should": "~1.2.2", "grunt-mocha-test": "~0.4.0", From 446da0c1e35f0db87ebd4370b4ef38b938c5b68a Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Mon, 27 May 2013 22:45:33 +0100 Subject: [PATCH 3/3] Removing unused bookshelf --- core/test/ghost/api_posts_spec.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/test/ghost/api_posts_spec.js b/core/test/ghost/api_posts_spec.js index d19f4377d0..36f9084a30 100644 --- a/core/test/ghost/api_posts_spec.js +++ b/core/test/ghost/api_posts_spec.js @@ -6,8 +6,7 @@ var _ = require("underscore"), should = require('should'), helpers = require('./helpers'), - PostProvider = require('../../shared/models/dataProvider.bookshelf.posts'), - Bookshelf = require('bookshelf'); + PostProvider = require('../../shared/models/dataProvider.bookshelf.posts'); describe('Bookshelf PostsProvider', function () {