Browse Source

fix: convert email to lower case to avoid case sensitivity

re #627

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/653/head
Pranav C 3 years ago
parent
commit
f81c4072be
  1. 24
      packages/nocodb/src/lib/noco/rest/RestAuthCtrl.ts
  2. 5
      packages/nocodb/src/lib/noco/rest/RestAuthCtrlEE.ts

24
packages/nocodb/src/lib/noco/rest/RestAuthCtrl.ts

@ -784,13 +784,21 @@ export default class RestAuthCtrl {
protected async signup(req, res, next): Promise<any> { protected async signup(req, res, next): Promise<any> {
try { try {
const { email, firstname, lastname, token, ignore_subscribe } = req.body; const {
email: _email,
firstname,
lastname,
token,
ignore_subscribe
} = req.body;
let { password } = req.body; let { password } = req.body;
if (!isEmail(email)) { if (!isEmail(_email)) {
return next(new Error(`Invalid email`)); return next(new Error(`Invalid email`));
} }
const email = _email.toLowerCase();
let user = await this.users let user = await this.users
.where({ .where({
email email
@ -928,11 +936,13 @@ export default class RestAuthCtrl {
} }
protected async passwordForgot(req, res, next): Promise<any> { protected async passwordForgot(req, res, next): Promise<any> {
const email = req.body.email; const _email = req.body.email;
if (!email) { if (!_email) {
return next(new Error('Please enter your email address.')); return next(new Error('Please enter your email address.'));
} }
const email = _email.toLowerCase();
const user = await this.users.where({ email }).first(); const user = await this.users.where({ email }).first();
if (!user) { if (!user) {
return next(new Error('This email is not registered with us.')); return next(new Error('This email is not registered with us.'));
@ -1135,12 +1145,12 @@ export default class RestAuthCtrl {
// return next(new Error('SMTP config is not found')); // return next(new Error('SMTP config is not found'));
// } // }
const email = req.body.email; const _email = req.body.email;
if (!email || !validator.isEmail(email)) { if (!_email || !validator.isEmail(_email)) {
return next(new Error('Invalid email address')); return next(new Error('Invalid email address'));
} }
const email = _email.toLowerCase();
// todo: handle roles which contains super // todo: handle roles which contains super
if ( if (
!req.session?.passport?.user?.roles?.owner && !req.session?.passport?.user?.roles?.owner &&

5
packages/nocodb/src/lib/noco/rest/RestAuthCtrlEE.ts

@ -10,7 +10,10 @@ import RestAuthCtrl from './RestAuthCtrl';
export default class RestAuthCtrlEE extends RestAuthCtrl { export default class RestAuthCtrlEE extends RestAuthCtrl {
protected async addAdmin(req, res, next): Promise<any> { protected async addAdmin(req, res, next): Promise<any> {
const emails = (req.body.email || '').split(/\s*,\s*/).map(v => v.trim()); const emails = (req.body.email || '')
.toLowerCase()
.split(/\s*,\s*/)
.map(v => v.trim());
// check for invalid emails // check for invalid emails
const invalidEmails = emails.filter(v => !validator.isEmail(v)); const invalidEmails = emails.filter(v => !validator.isEmail(v));

Loading…
Cancel
Save