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> {
try {
const { email, firstname, lastname, token, ignore_subscribe } = req.body;
const {
email: _email,
firstname,
lastname,
token,
ignore_subscribe
} = req.body;
let { password } = req.body;
if (!isEmail(email)) {
if (!isEmail(_email)) {
return next(new Error(`Invalid email`));
}
const email = _email.toLowerCase();
let user = await this.users
.where({
email
@ -928,11 +936,13 @@ export default class RestAuthCtrl {
}
protected async passwordForgot(req, res, next): Promise<any> {
const email = req.body.email;
if (!email) {
const _email = req.body.email;
if (!_email) {
return next(new Error('Please enter your email address.'));
}
const email = _email.toLowerCase();
const user = await this.users.where({ email }).first();
if (!user) {
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'));
// }
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'));
}
const email = _email.toLowerCase();
// todo: handle roles which contains super
if (
!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 {
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
const invalidEmails = emails.filter(v => !validator.isEmail(v));

Loading…
Cancel
Save