Skip to content

Commit

Permalink
fix: Remove EmailVerification entity from UserAccountDto (#2415)
Browse files Browse the repository at this point in the history
It fails, when redis cache is used.
  • Loading branch information
JanCizmar committed Jul 22, 2024
1 parent 1b15335 commit 9755d7c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.tolgee.dtos.cacheable

import io.tolgee.model.EmailVerification
import io.tolgee.model.UserAccount
import java.io.Serializable
import java.util.*
Expand All @@ -14,7 +13,7 @@ data class UserAccountDto(
val avatarHash: String?,
val deleted: Boolean,
val tokensValidNotBefore: Date?,
val emailVerification: EmailVerification? = null,
val emailVerified: Boolean,
) : Serializable {
companion object {
fun fromEntity(entity: UserAccount) =
Expand All @@ -27,7 +26,7 @@ data class UserAccountDto(
avatarHash = entity.avatarHash,
deleted = entity.deletedAt != null,
tokensValidNotBefore = entity.tokensValidNotBefore,
emailVerification = entity.emailVerification,
emailVerified = entity.emailVerification == null,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ class EmailVerificationService(
}

fun isVerified(userAccount: UserAccountDto): Boolean {
return !(
tolgeeProperties.authentication.needsEmailVerification &&
userAccount.emailVerification != null
)
return !tolgeeProperties.authentication.needsEmailVerification || userAccount.emailVerified
}

fun isVerified(userAccount: UserAccount): Boolean {
Expand Down Expand Up @@ -133,8 +130,9 @@ class EmailVerificationService(
val newEmail = user.emailVerification?.newEmail
setNewEmailIfChanged(newEmail, user)

userAccountService.saveAndFlush(user)
user.emailVerification = null
emailVerificationRepository.delete(emailVerification)
userAccountService.saveAndFlush(user)

val isFirstEmailVerification = newEmail == null
val isEmailChange = newEmail != null
Expand Down

0 comments on commit 9755d7c

Please sign in to comment.