Browse Source

fix: change password cache logic

pull/2295/head
Wing-Kam Wong 3 years ago
parent
commit
4754369bb5
  1. 12
      packages/nocodb/src/lib/meta/api/userApi/userApis.ts
  2. 20
      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' });
} }

20
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 };
// set cache
await NocoCache.set(key, o);
{
// update user:<email> // update user:<email>
key = `${CacheScope.USER}:${o.email}`; `${CacheScope.USER}:${user.email}`
o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); ];
for (const key of keys) {
let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) { if (o) {
o = { ...o, ...updateObj }; o = { ...o, ...updateObj };
// set cache // set cache
await NocoCache.set(key, o); 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