Skip to content
Permalink
Browse files Browse the repository at this point in the history
refactor: update forgot password api response
Signed-off-by: Pranav C <pranavxc@gmail.com>
  • Loading branch information
pranavxc committed Dec 20, 2021
1 parent 8171a3c commit f46e89b
Showing 1 changed file with 32 additions and 35 deletions.
67 changes: 32 additions & 35 deletions packages/nocodb/src/lib/noco/rest/RestAuthCtrl.ts
Expand Up @@ -1001,45 +1001,42 @@ export default class RestAuthCtrl {
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.'));
}
if (user) {
const token = uuidv4();
await this.users
.update({
reset_password_token: token,
reset_password_expires: new Date(Date.now() + 60 * 60 * 1000)
})
.where({ id: user.id });

const token = uuidv4();
await this.users
.update({
reset_password_token: token,
reset_password_expires: new Date(Date.now() + 60 * 60 * 1000)
})
.where({ id: user.id });
try {
const template = (await import('./ui/emailTemplates/forgotPassword'))
.default;
await this.emailClient.mailSend({
to: user.email,
subject: 'Password Reset Link',
text: `Visit following link to update your password : ${req.ncSiteUrl}/password/reset/${token}.`,
html: ejs.render(template, {
resetLink: req.ncSiteUrl + `/password/reset/${token}`
})
});
} catch (e) {
console.log(
'Warning : `mailSend` failed, Please configure emailClient configuration.'
);
}
console.log(`Password reset token : ${token}`);

try {
const template = (await import('./ui/emailTemplates/forgotPassword'))
.default;
await this.emailClient.mailSend({
to: user.email,
subject: 'Password Reset Link',
text: `Visit following link to update your password : ${req.ncSiteUrl}/password/reset/${token}.`,
html: ejs.render(template, {
resetLink: req.ncSiteUrl + `/password/reset/${token}`
})
this.xcMeta.audit(null, null, 'nc_audit', {
op_type: 'AUTHENTICATION',
op_sub_type: 'PASSWORD_FORGOT',
user: user.email,
description: `requested for password reset `,
ip: req.clientIp
});
} catch (e) {
console.log(
'Warning : `mailSend` failed, Please configure emailClient configuration.'
);
}
console.log(`Password reset token : ${token}`);

this.xcMeta.audit(null, null, 'nc_audit', {
op_type: 'AUTHENTICATION',
op_sub_type: 'PASSWORD_FORGOT',
user: user.email,
description: `requested for password reset `,
ip: req.clientIp
});

res.json({ msg: 'Check your email for password reset link.' });
res.json({ msg: 'Check your email if you are registered with us.' });
}

protected async tokenValidate(req, res, next): Promise<any> {
Expand Down

0 comments on commit f46e89b

Please sign in to comment.