diff --git a/app/src/main/kotlin/io/sakurasou/exception/SignupNotAllowedException.kt b/app/src/main/kotlin/io/sakurasou/exception/SignupNotAllowedException.kt new file mode 100644 index 00000000..c6cd1391 --- /dev/null +++ b/app/src/main/kotlin/io/sakurasou/exception/SignupNotAllowedException.kt @@ -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" +} \ No newline at end of file diff --git a/app/src/main/kotlin/io/sakurasou/service/user/UserServiceImpl.kt b/app/src/main/kotlin/io/sakurasou/service/user/UserServiceImpl.kt index 62b24e2c..f3ede4ff 100644 --- a/app/src/main/kotlin/io/sakurasou/service/user/UserServiceImpl.kt +++ b/app/src/main/kotlin/io/sakurasou/service/user/UserServiceImpl.kt @@ -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 @@ -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(