From aa96e9702874471f64a9df86758240d0bfd0f8d9 Mon Sep 17 00:00:00 2001 From: NGPixel Date: Wed, 9 Sep 2020 19:59:46 -0400 Subject: [PATCH] fix: force lowercase for email on local auth --- server/db/migrations-sqlite/2.5.128.js | 7 +++++++ server/db/migrations/2.5.128.js | 7 +++++++ server/models/users.js | 2 +- server/modules/authentication/local/authentication.js | 2 +- 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 server/db/migrations-sqlite/2.5.128.js create mode 100644 server/db/migrations/2.5.128.js diff --git a/server/db/migrations-sqlite/2.5.128.js b/server/db/migrations-sqlite/2.5.128.js new file mode 100644 index 00000000..e2105c86 --- /dev/null +++ b/server/db/migrations-sqlite/2.5.128.js @@ -0,0 +1,7 @@ +exports.up = async knex => { + await knex('users').update({ + email: knex.raw('LOWER(email)') + }) +} + +exports.down = knex => { } diff --git a/server/db/migrations/2.5.128.js b/server/db/migrations/2.5.128.js new file mode 100644 index 00000000..8316f6ae --- /dev/null +++ b/server/db/migrations/2.5.128.js @@ -0,0 +1,7 @@ +exports.up = async knex => { + await knex('users').update({ + email: knex.raw('LOWER(??)', ['email']) + }) +} + +exports.down = knex => { } diff --git a/server/models/users.js b/server/models/users.js index e648be44..1d0d9799 100644 --- a/server/models/users.js +++ b/server/models/users.js @@ -675,7 +675,7 @@ module.exports = class User extends Model { if (dupUsr) { throw new WIKI.Error.AuthAccountAlreadyExists() } - usrData.email = email + usrData.email = _.toLower(email) } if (!_.isEmpty(name) && name !== usr.name) { usrData.name = _.trim(name) diff --git a/server/modules/authentication/local/authentication.js b/server/modules/authentication/local/authentication.js index 57f4dc47..e6fa75d3 100644 --- a/server/modules/authentication/local/authentication.js +++ b/server/modules/authentication/local/authentication.js @@ -15,7 +15,7 @@ module.exports = { }, async (uEmail, uPassword, done) => { try { const user = await WIKI.models.users.query().findOne({ - email: uEmail, + email: uEmail.toLowerCase(), providerKey: 'local' }) if (user) {