diff --git a/backend/data/src/main/kotlin/io/tolgee/dtos/cacheable/UserAccountDto.kt b/backend/data/src/main/kotlin/io/tolgee/dtos/cacheable/UserAccountDto.kt index c94bea552a..b929cff48d 100644 --- a/backend/data/src/main/kotlin/io/tolgee/dtos/cacheable/UserAccountDto.kt +++ b/backend/data/src/main/kotlin/io/tolgee/dtos/cacheable/UserAccountDto.kt @@ -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.* @@ -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) = @@ -27,7 +26,7 @@ data class UserAccountDto( avatarHash = entity.avatarHash, deleted = entity.deletedAt != null, tokensValidNotBefore = entity.tokensValidNotBefore, - emailVerification = entity.emailVerification, + emailVerified = entity.emailVerification == null, ) } diff --git a/backend/data/src/main/kotlin/io/tolgee/service/EmailVerificationService.kt b/backend/data/src/main/kotlin/io/tolgee/service/EmailVerificationService.kt index ddd6235a6e..e2efbcda7d 100644 --- a/backend/data/src/main/kotlin/io/tolgee/service/EmailVerificationService.kt +++ b/backend/data/src/main/kotlin/io/tolgee/service/EmailVerificationService.kt @@ -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 { @@ -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