feat: password reset
This commit is contained in:
@@ -478,6 +478,38 @@ module.exports = class User extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a password reset request
|
||||
*/
|
||||
static async loginForgotPassword ({ email }, context) {
|
||||
const usr = await WIKI.models.users.query().where({
|
||||
email,
|
||||
providerKey: 'local'
|
||||
}).first()
|
||||
if (!usr) {
|
||||
WIKI.logger.debug(`Password reset attempt on nonexistant local account ${email}: [DISCARDED]`)
|
||||
return
|
||||
}
|
||||
const resetToken = await WIKI.models.userKeys.generateToken({
|
||||
userId: usr.id,
|
||||
kind: 'resetPwd'
|
||||
})
|
||||
|
||||
await WIKI.mail.send({
|
||||
template: 'accountResetPwd',
|
||||
to: email,
|
||||
subject: `Password Reset Request`,
|
||||
data: {
|
||||
preheadertext: `A password reset was requested for ${WIKI.config.title}`,
|
||||
title: `A password reset was requested for ${WIKI.config.title}`,
|
||||
content: `Click the button below to reset your password. If you didn't request this password reset, simply discard this email.`,
|
||||
buttonLink: `${WIKI.config.host}/login-reset/${resetToken}`,
|
||||
buttonText: 'Reset Password'
|
||||
},
|
||||
text: `A password reset was requested for wiki ${WIKI.config.title}. Open the following link to proceed: ${WIKI.config.host}/login-reset/${resetToken}`
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user
|
||||
*
|
||||
|
Reference in New Issue
Block a user