adding check of string for case insensitive emails

This commit is contained in:
Dhaval Trivedi 2016-06-26 17:07:00 +05:30 committed by David Cheung
parent 6d5d7f0d4a
commit 4922f425fc
2 changed files with 32 additions and 1 deletions

View File

@ -657,7 +657,8 @@ module.exports = function(User) {
// Access token to normalize email credentials // Access token to normalize email credentials
UserModel.observe('access', function normalizeEmailCase(ctx, next) { UserModel.observe('access', function normalizeEmailCase(ctx, next) {
if (!ctx.Model.settings.caseSensitiveEmail && ctx.query.where && ctx.query.where.email) { if (!ctx.Model.settings.caseSensitiveEmail && ctx.query.where &&
ctx.query.where.email && typeof(ctx.query.where.email) === 'string') {
ctx.query.where.email = ctx.query.where.email.toLowerCase(); ctx.query.where.email = ctx.query.where.email.toLowerCase();
} }
next(); next();

View File

@ -454,6 +454,36 @@ describe('User', function() {
done(); done();
}); });
}); });
it('Should be able to use query filters (email case-sensitivity off)', function(done) {
User.settings.caseSensitiveEmail = false;
var insensitiveUser = { email: 'insensitive@example.com', password: 'abc' };
User.create(insensitiveUser, function(err, user) {
User.find({ where: { email:
{ inq: [insensitiveUser.email] },
}}, function(err, result) {
if (err) done(err);
assert(result[0], 'The query did not find the user');
assert.equal(result[0].email, insensitiveUser.email);
done();
});
});
});
it('Should be able to use query filters (email case-sensitivity on)', function(done) {
User.settings.caseSensitiveEmail = true;
var sensitiveUser = { email: 'senSiTive@example.com', password: 'abc' };
User.create(sensitiveUser, function(err, user) {
User.find({ where: { email:
{ inq: [sensitiveUser.email] },
}}, function(err, result) {
if (err) done(err);
assert(result[0], 'The query did not find the user');
assert.equal(result[0].email, sensitiveUser.email);
done();
});
});
});
}); });
describe('User.login', function() { describe('User.login', function() {