Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/main/kotlin/es/wokis/data/bo/user/UserBO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ data class UserBO(
val totpEncodedSecret: ByteArray? = null,
val currentSession: String? = null,
val emailVerified: Boolean = false,
val loginWithGoogle: Boolean = false,
val sessions: List<String> = emptyList(),
val badges: List<BadgeBO> = emptyList(),
val devices: List<String> = emptyList(),
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/es/wokis/data/dbo/user/UserDBO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ data class UserDBO(
val image: String = ServerConstants.EMPTY_TEXT,
val createdOn: Long = Date().time,
val emailVerified: Boolean = false,
val loginWithGoogle: Boolean = false,
val totpEncodedSecret: ByteArray? = null,
val sessions: List<String> = emptyList(),
val badges: List<BadgeDBO> = emptyList(),
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/es/wokis/data/dto/user/UserDTO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ data class UserDTO(
val image: String = EMPTY_TEXT,
@SerializedName("lang")
val lang: String,
@SerializedName("loginWithGoogle")
val loginWithGoogle: Boolean = false,
@SerializedName("createdOn")
val createdOn: Long,
@SerializedName("totpEnabled")
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/es/wokis/data/mapper/user/UserMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fun UserDTO.toBO() = UserBO(
image = image,
lang = lang,
devices = devices,
loginWithGoogle = loginWithGoogle,
badges = badges.toBO(),
createdOn = createdOn,
emailVerified = emailVerified
Expand All @@ -53,6 +54,7 @@ fun UserBO.toDBO() = UserDBO(
sessions = sessions,
createdOn = createdOn,
emailVerified = emailVerified,
loginWithGoogle = loginWithGoogle,
recoverWords = recoverWords
)

Expand All @@ -66,6 +68,7 @@ fun UserDBO.toBO() = UserBO(
totpEncodedSecret = totpEncodedSecret,
devices = devices,
sessions = sessions,
loginWithGoogle = loginWithGoogle,
badges = badges.toBO(),
createdOn = createdOn,
emailVerified = emailVerified,
Expand All @@ -82,6 +85,7 @@ fun UserBO.toDTO() = UserDTO(
lang = lang,
totpEnabled = totpEncodedSecret != null,
devices = devices,
loginWithGoogle = loginWithGoogle,
badges = badges.toDTO(),
createdOn = createdOn,
emailVerified = emailVerified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import es.wokis.data.exception.RecoverCodeNotFoundException
import es.wokis.data.exception.UserNotFoundException
import es.wokis.data.repository.user.UserRepository
import es.wokis.services.EmailService
import org.mindrot.jbcrypt.BCrypt

interface RecoverRepository {
suspend fun changeUserPassword(changePassRequest: ChangePassRequestDTO): AcknowledgeBO
Expand All @@ -25,10 +26,21 @@ class RecoverRepositoryImpl(
throw RecoverCodeNotFoundException
}
val recover = localDataSource.getRecoverByToken(changePassRequest.recoverCode)
recover?.let {
val user = userRepository.getUserByEmail(it.email)
recover?.let { recover ->
val user = userRepository.getUserByEmail(recover.email)
return user?.let {
userRepository.updateUser(user.copy(password = changePassRequest.newPass, sessions = listOf()))
recover.id?.let { recoverId ->
localDataSource.removeRecover(recoverId)
}
userRepository.updateUser(
user.copy(
password = BCrypt.hashpw(
changePassRequest.newPass,
BCrypt.gensalt()
),
sessions = listOf()
)
)
} ?: throw UserNotFoundException
}
throw RecoverCodeNotFoundException
Expand All @@ -37,6 +49,9 @@ class RecoverRepositoryImpl(
override suspend fun requestChangePass(email: String): AcknowledgeBO {
val user = userRepository.getUserByEmail(email)
user?.let {
if (user.emailVerified) {
throw IllegalStateException()
}
emailService.sendRecoverPass(user)?.also {
return saveRequestChangePass(it)
} ?: throw IllegalStateException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class UserRepositoryImpl(
val email: String = payload.email
val imageUrl: String = (payload["picture"] as? String).orEmpty()
val locale: String = payload["locale"] as? String ?: DEFAULT_LANG
val username = email.split("@").firstOrNull() ?: HashGenerator.generateHash()
val user = getUserByEmail(email)
val token = if (user == null) {
val token = register(
Expand All @@ -132,7 +131,7 @@ class UserRepositoryImpl(

} else {
login(
LoginDTO(username = username, password = EMPTY_TEXT, isGoogleAuth = true),
LoginDTO(username = email, password = EMPTY_TEXT, isGoogleAuth = true),
code,
timeStamp
)
Expand Down Expand Up @@ -214,7 +213,8 @@ class UserRepositoryImpl(
if (BCrypt.checkpw(changePass.oldPass, user.password)) {
return updateUser(
user.copy(
password = BCrypt.hashpw(changePass.newPass, BCrypt.gensalt())
password = BCrypt.hashpw(changePass.newPass, BCrypt.gensalt()),
sessions = emptyList()
)
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/es/wokis/plugins/HTTP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ fun Application.configureHTTP() {
allowSameOrigin = true
maxAgeInSeconds = Duration.ofDays(1).toMinutes() * 60L

anyHost() // TODO: No dejarlo como anyhost, limitarlo al host final
anyHost()
}
}
2 changes: 1 addition & 1 deletion src/main/resources/emails/es/recover-pass.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"></head><body><p>Recover your password</p><p>Use the following code on the app to recover your password: %%TOKEN</p><p>If you have not requested this action, ignore this message.</p><p>Thank you!</p></body></html>
<!DOCTYPE html><html lang="es"><head><meta charset="UTF-8"></head><body><p>Recuperar tu contraseña</p><p>Usa el siguiente código en la app para recuperar tu contraseña: %%TOKEN</p><p>Si no has solicitado este código, ignora este mensaje.</p><p>¡Gracias!</p></body></html>