Browse Source

Merge pull request #2295 from nocodb/fix/change-password-cache

fix: change password cache logic
pull/2307/head
navi 3 years ago committed by GitHub
parent
commit
6ec064cc02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      packages/nocodb/src/lib/meta/api/userApi/userApis.ts
  2. 30
      packages/nocodb/src/lib/models/User.ts

12
packages/nocodb/src/lib/meta/api/userApi/userApis.ts

@ -284,7 +284,8 @@ async function passwordChange(req: Request<any, any>, res): Promise<any> {
await User.update(user.id, { await User.update(user.id, {
salt, salt,
password password,
email: user.email
}); });
Audit.insert({ Audit.insert({
@ -324,12 +325,13 @@ async function passwordForgot(req: Request<any, any>, res): Promise<any> {
(req as any).ncSiteUrl (req as any).ncSiteUrl
}/api/v1/db/auth/password/reset/${token}.`, }/api/v1/db/auth/password/reset/${token}.`,
html: ejs.render(template, { 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) { } catch (e) {
console.log(e) console.log(e);
return NcError.badRequest( return NcError.badRequest(
'Email Plugin is not found. Please contact administrators to configure it in App Store first.' 'Email Plugin is not found. Please contact administrators to configure it in App Store first.'
); );
@ -343,9 +345,7 @@ async function passwordForgot(req: Request<any, any>, res): Promise<any> {
ip: (req as any).clientIp ip: (req as any).clientIp
}); });
} else { } else {
return NcError.badRequest( return NcError.badRequest('Your email has not been registered.');
'Your email has not been registered.'
);
} }
res.json({ msg: 'Please check your email to reset the password' }); res.json({ msg: 'Please check your email to reset the password' });
} }

30
packages/nocodb/src/lib/models/User.ts

@ -74,23 +74,23 @@ export default class User implements UserType {
'roles' 'roles'
]); ]);
// get existing cache // get existing cache
let key = `${CacheScope.USER}:${id}`; const keys = [
let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); // update user:<id>
if (o) { `${CacheScope.USER}:${id}`,
o = { ...o, ...updateObj }; // update user:<email>
// set cache `${CacheScope.USER}:${user.email}`
await NocoCache.set(key, o); ];
{ for (const key of keys) {
// update user:<email> let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
key = `${CacheScope.USER}:${o.email}`; if (o) {
o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); o = { ...o, ...updateObj };
if (o) { // set cache
o = { ...o, ...updateObj }; await NocoCache.set(key, o);
// set cache
await NocoCache.set(key, o);
}
} }
} }
// as <projectId> is unknown, delete user:<email>___<projectId> in cache
await NocoCache.delAll(CacheScope.USER, `${user.email}___*`);
// set meta // set meta
return await ncMeta.metaUpdate(null, null, MetaTable.USERS, updateObj, id); return await ncMeta.metaUpdate(null, null, MetaTable.USERS, updateObj, id);
} }

Loading…
Cancel
Save