Merge pull request #3779 from nitro404/hotfix/case-insensitive-user-email
Fix bugs with case insensitive user emails
This commit is contained in:
commit
c2077dfcb0
|
@ -1061,7 +1061,7 @@ module.exports = function(User) {
|
|||
this.settings.ttl = this.settings.ttl || DEFAULT_TTL;
|
||||
|
||||
UserModel.setter.email = function(value) {
|
||||
if (!UserModel.settings.caseSensitiveEmail) {
|
||||
if (!UserModel.settings.caseSensitiveEmail && typeof value === 'string') {
|
||||
this.$email = value.toLowerCase();
|
||||
} else {
|
||||
this.$email = value;
|
||||
|
|
|
@ -138,15 +138,28 @@ describe('User', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('Email is required', function(done) {
|
||||
User.create({password: '123'}, function(err) {
|
||||
assert(err);
|
||||
assert.equal(err.name, 'ValidationError');
|
||||
assert.equal(err.statusCode, 422);
|
||||
assert.equal(err.details.context, User.modelName);
|
||||
assert.deepEqual(err.details.codes.email, ['presence']);
|
||||
it('fails when the required email is missing (case-sensitivity on)', () => {
|
||||
User.create({password: '123'})
|
||||
.then(
|
||||
success => { throw new Error('create should have failed'); },
|
||||
err => {
|
||||
expect(err.name).to.equal('ValidationError');
|
||||
expect(err.statusCode).to.equal(422);
|
||||
expect(err.details.context).to.equal(User.modelName);
|
||||
expect(err.details.codes.email).to.deep.equal(['presence']);
|
||||
});
|
||||
});
|
||||
|
||||
done();
|
||||
it('fails when the required email is missing (case-sensitivity off)', () => {
|
||||
User.settings.caseSensitiveEmail = false;
|
||||
User.create({email: undefined, password: '123'})
|
||||
.then(
|
||||
success => { throw new Error('create should have failed'); },
|
||||
err => {
|
||||
expect(err.name).to.equal('ValidationError');
|
||||
expect(err.statusCode).to.equal(422);
|
||||
expect(err.details.context).to.equal(User.modelName);
|
||||
expect(err.details.codes.email).to.deep.equal(['presence']);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue