Skip to content

Commit

Permalink
feat: determine whether registration is allowed in saveUser
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiinaKin committed Sep 14, 2024
1 parent 8fba7b6 commit 06d6cbd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.sakurasou.exception

/**
* @author Shiina Kin
* 2024/9/14 08:30
*/
class SignupNotAllowedException : ServiceThrowable() {
override val code: Int
get() = 4001
override val message: String
get() = "Signup is not allowed"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.sakurasou.service.user

import at.favre.lib.crypto.bcrypt.BCrypt
import io.sakurasou.controller.request.UserInsertRequest
import io.sakurasou.exception.SignupNotAllowedException
import io.sakurasou.model.DatabaseSingleton.dbQuery
import io.sakurasou.model.dao.user.UserDao
import io.sakurasou.model.dto.UserInsertDTO
Expand All @@ -21,10 +22,12 @@ class UserServiceImpl(
private val settingService: SettingService
) : UserService {
override suspend fun saveUser(userInsertRequest: UserInsertRequest) {
val systemSetting = settingService.getSystemSetting()
if (!systemSetting.allowSignup) throw SignupNotAllowedException()

val rawPassword = userInsertRequest.password
val encodePassword = BCrypt.withDefaults().hashToString(12, rawPassword.toCharArray())

val systemSetting = settingService.getSystemSetting()

val now = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault())
val userInsertDTO = UserInsertDTO(
Expand Down

0 comments on commit 06d6cbd

Please sign in to comment.