diff --git a/packages/nocodb/src/lib/meta/api/userApi/userApis.ts b/packages/nocodb/src/lib/meta/api/userApi/userApis.ts index 668d318e9b..927bb1c6e3 100644 --- a/packages/nocodb/src/lib/meta/api/userApi/userApis.ts +++ b/packages/nocodb/src/lib/meta/api/userApi/userApis.ts @@ -284,7 +284,8 @@ async function passwordChange(req: Request, res): Promise { await User.update(user.id, { salt, - password + password, + email: user.email }); Audit.insert({ @@ -324,12 +325,13 @@ async function passwordForgot(req: Request, res): Promise { (req as any).ncSiteUrl }/api/v1/db/auth/password/reset/${token}.`, html: ejs.render(template, { - resetLink: (req as any).ncSiteUrl + `/api/v1/db/auth/password/reset/${token}` + resetLink: + (req as any).ncSiteUrl + `/api/v1/db/auth/password/reset/${token}` }) }) ); } catch (e) { - console.log(e) + console.log(e); return NcError.badRequest( 'Email Plugin is not found. Please contact administrators to configure it in App Store first.' ); @@ -343,9 +345,7 @@ async function passwordForgot(req: Request, res): Promise { ip: (req as any).clientIp }); } else { - return NcError.badRequest( - 'Your email has not been registered.' - ); + return NcError.badRequest('Your email has not been registered.'); } res.json({ msg: 'Please check your email to reset the password' }); } diff --git a/packages/nocodb/src/lib/models/User.ts b/packages/nocodb/src/lib/models/User.ts index 33445d643a..92792da92d 100644 --- a/packages/nocodb/src/lib/models/User.ts +++ b/packages/nocodb/src/lib/models/User.ts @@ -74,23 +74,23 @@ export default class User implements UserType { 'roles' ]); // get existing cache - let key = `${CacheScope.USER}:${id}`; - let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); - if (o) { - o = { ...o, ...updateObj }; - // set cache - await NocoCache.set(key, o); - { - // update user: - key = `${CacheScope.USER}:${o.email}`; - o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); - if (o) { - o = { ...o, ...updateObj }; - // set cache - await NocoCache.set(key, o); - } + const keys = [ + // update user: + `${CacheScope.USER}:${id}`, + // update user: + `${CacheScope.USER}:${user.email}` + ]; + for (const key of keys) { + let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); + if (o) { + o = { ...o, ...updateObj }; + // set cache + await NocoCache.set(key, o); } } + // as is unknown, delete user:___ in cache + await NocoCache.delAll(CacheScope.USER, `${user.email}___*`); + // set meta return await ncMeta.metaUpdate(null, null, MetaTable.USERS, updateObj, id); }