Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/insecurity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,16 @@ export const updateAuthenticatedUsers = () => (req: Request, res: Response, next
}
next()
}

export const clearSessionsFor = (user: UserModel) => {
const token = authenticatedUsers.tokenOf(user)
if (token) {
delete authenticatedUsers.tokenMap[token]
delete authenticatedUsers.idMap[user.id]
}
}

export const sendPasswordResetNotification = (email: string) => {
// Placeholder: replace with real email dispatch
console.info(`Password reset notification sent to ${email}`)
}
2 changes: 2 additions & 0 deletions routes/resetPassword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ module.exports = function resetPassword () {
if ((data != null) && security.hmac(answer) === data.answer) {
UserModel.findByPk(data.UserId).then((user: UserModel | null) => {
user?.update({ password: newPassword }).then((user: UserModel) => {
security.clearSessionsFor(user)
security.sendPasswordResetNotification(user.email)
verifySecurityAnswerChallenges(user, answer)
res.json({ user })
}).catch((error: unknown) => {
Expand Down