|
|
@ -1001,45 +1001,42 @@ export default class RestAuthCtrl { |
|
|
|
const email = _email.toLowerCase(); |
|
|
|
const email = _email.toLowerCase(); |
|
|
|
|
|
|
|
|
|
|
|
const user = await this.users.where({ email }).first(); |
|
|
|
const user = await this.users.where({ email }).first(); |
|
|
|
if (!user) { |
|
|
|
if (user) { |
|
|
|
return next(new Error('This email is not registered with us.')); |
|
|
|
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(); |
|
|
|
try { |
|
|
|
await this.users |
|
|
|
const template = (await import('./ui/emailTemplates/forgotPassword')) |
|
|
|
.update({ |
|
|
|
.default; |
|
|
|
reset_password_token: token, |
|
|
|
await this.emailClient.mailSend({ |
|
|
|
reset_password_expires: new Date(Date.now() + 60 * 60 * 1000) |
|
|
|
to: user.email, |
|
|
|
}) |
|
|
|
subject: 'Password Reset Link', |
|
|
|
.where({ id: user.id }); |
|
|
|
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 { |
|
|
|
this.xcMeta.audit(null, null, 'nc_audit', { |
|
|
|
const template = (await import('./ui/emailTemplates/forgotPassword')) |
|
|
|
op_type: 'AUTHENTICATION', |
|
|
|
.default; |
|
|
|
op_sub_type: 'PASSWORD_FORGOT', |
|
|
|
await this.emailClient.mailSend({ |
|
|
|
user: user.email, |
|
|
|
to: user.email, |
|
|
|
description: `requested for password reset `, |
|
|
|
subject: 'Password Reset Link', |
|
|
|
ip: req.clientIp |
|
|
|
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}`); |
|
|
|
res.json({ msg: 'Check your email if you are registered with us.' }); |
|
|
|
|
|
|
|
|
|
|
|
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.' }); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected async tokenValidate(req, res, next): Promise<any> { |
|
|
|
protected async tokenValidate(req, res, next): Promise<any> { |
|
|
|