Skip to content

Commit

Permalink
Add logging and exception handling to reset password process
Browse files Browse the repository at this point in the history
In the PasswordFacade class, a log statement and exception handling have been added to the reset password function. Now, when the password reset email is sent, it's wrapped in a try/catch block to handle any potential exceptions. Additionally, a debug-level log is generated whenever a rest password token is created.
  • Loading branch information
hanna-eismant committed Apr 25, 2024
1 parent 6292fae commit 9a81750
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions server/src/main/java/org/hkurh/doky/password/PasswordFacade.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.hkurh.doky.password
import org.hkurh.doky.email.EmailService
import org.hkurh.doky.errorhandling.DokyNotFoundException
import org.hkurh.doky.users.UserService
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component

@Component
Expand All @@ -13,10 +14,20 @@ class PasswordFacade(
) {

fun reset(email: String) {
if (!userService.exists(email)) throw DokyNotFoundException("User with email $email does not exist")
if (!userService.exists(email)) throw DokyNotFoundException("User does not exist")

val user = userService.findUserByUid(email)
val token = resetPasswordService.generateAndSaveResetToken(user!!)
emailService.sendRestorePasswordEmail(user, token)
LOG.debug("Generate reset password token for user ${user.id}")
try {
emailService.sendRestorePasswordEmail(user, token)
} catch (e: Exception) {
LOG.error("Error sending reset password email for user ${user.id}", e)
}
}


companion object {
private val LOG = LoggerFactory.getLogger(PasswordFacade::class.java)
}
}

0 comments on commit 9a81750

Please sign in to comment.