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. 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, {
salt,
password
password,
email: user.email
});
Audit.insert({
@ -324,12 +325,13 @@ async function passwordForgot(req: Request<any, any>, res): Promise<any> {
(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<any, any>, res): Promise<any> {
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' });
}

30
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:<email>
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:<id>
`${CacheScope.USER}:${id}`,
// update user:<email>
`${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 <projectId> is unknown, delete user:<email>___<projectId> in cache
await NocoCache.delAll(CacheScope.USER, `${user.email}___*`);
// set meta
return await ncMeta.metaUpdate(null, null, MetaTable.USERS, updateObj, id);
}

Loading…
Cancel
Save