Lowercase email address.

fixes #1498
This commit is contained in:
Fabian Becker 2013-11-18 00:34:02 +00:00
parent 8e9b27f0b5
commit 89201a5c84
3 changed files with 19 additions and 4 deletions

View File

@ -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) {

View File

@ -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) {

View File

@ -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;
module.exports = DataGenerator;