From 89201a5c847f6a65c1c3366e4929e6c1a2c559d1 Mon Sep 17 00:00:00 2001 From: Fabian Becker Date: Mon, 18 Nov 2013 00:34:02 +0000 Subject: [PATCH] Lowercase email address. fixes #1498 --- core/server/models/user.js | 4 ++-- core/test/integration/model/model_users_spec.js | 15 +++++++++++++++ core/test/utils/fixtures/data-generator.js | 4 ++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/core/server/models/user.js b/core/server/models/user.js index 55c7b5a07b..edabf30483 100644 --- a/core/server/models/user.js +++ b/core/server/models/user.js @@ -61,7 +61,7 @@ User = ghostBookshelf.Model.extend({ saving: function () { this.set('name', this.sanitize('name')); - this.set('email', this.sanitize('email')); + this.set('email', this.sanitize('email').toLocaleLowerCase()); this.set('location', this.sanitize('location')); this.set('website', this.sanitize('website')); this.set('bio', this.sanitize('bio')); @@ -154,7 +154,7 @@ User = ghostBookshelf.Model.extend({ // Finds the user by email, and checks the password check: function (_userdata) { return this.forge({ - email: _userdata.email + email: _userdata.email.toLocaleLowerCase() }).fetch({require: true}).then(function (user) { return nodefn.call(bcrypt.compare, _userdata.pw, user.get('password')).then(function (matched) { if (!matched) { diff --git a/core/test/integration/model/model_users_spec.js b/core/test/integration/model/model_users_spec.js index ca36371e9d..8cdf3fdf42 100644 --- a/core/test/integration/model/model_users_spec.js +++ b/core/test/integration/model/model_users_spec.js @@ -48,6 +48,21 @@ describe('User Model', function run() { }).then(null, done); }); + it('can lowercase email', function (done) { + var userData = testUtils.DataGenerator.forModel.users[2], + gravatarStub = sinon.stub(UserModel, 'gravatarLookup', function (userData) { + return when.resolve(userData); + }); + + UserModel.add(userData).then(function (createdUser) { + should.exist(createdUser); + createdUser.has('uuid').should.equal(true); + createdUser.attributes.email.should.eql(userData.email.toLocaleLowerCase(), "email address correct"); + gravatarStub.restore(); + done(); + }).then(null, done); + }); + it('can find gravatar', function (done) { var userData = testUtils.DataGenerator.forModel.users[4], gravatarStub = sinon.stub(UserModel, 'gravatarLookup', function (userData) { diff --git a/core/test/utils/fixtures/data-generator.js b/core/test/utils/fixtures/data-generator.js index e89eca16ab..3a6fb41a38 100644 --- a/core/test/utils/fixtures/data-generator.js +++ b/core/test/utils/fixtures/data-generator.js @@ -63,7 +63,7 @@ DataGenerator.Content = { { name: 'Jimothy Bogendath', slug: 'jimothy-bogendath', - email: 'jbogendath@example.com', + email: 'jbOgendAth@example.com', password: '$2a$10$.pZeeBE0gHXd0PTnbT/ph.GEKgd0Wd3q2pWna3ynTGBkPKnGIKZL6' }, { @@ -220,4 +220,4 @@ DataGenerator.forModel = (function () { }()); -module.exports = DataGenerator; \ No newline at end of file +module.exports = DataGenerator;