mirror of
https://github.com/usbharu/Hideout.git
synced 2026-09-10 03:10:28 +00:00
feat: パスワード、ユーザー名が間違っているときに正常なHTTP Status Codeを返すように
This commit is contained in:
@@ -41,6 +41,10 @@ tasks.withType<ShadowJar> {
|
||||
}
|
||||
}
|
||||
|
||||
tasks.clean {
|
||||
delete += listOf("$rootDir/src/main/resources/static")
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
package dev.usbharu.hideout.exception
|
||||
|
||||
class UserNotFoundException : Exception {
|
||||
class UserNotFoundException : IllegalArgumentException {
|
||||
constructor() : super()
|
||||
constructor(message: String?) : super(message)
|
||||
constructor(s: String?) : super(s)
|
||||
constructor(message: String?, cause: Throwable?) : super(message, cause)
|
||||
constructor(cause: Throwable?) : super(cause)
|
||||
constructor(
|
||||
message: String?,
|
||||
cause: Throwable?,
|
||||
enableSuppression: Boolean,
|
||||
writableStackTrace: Boolean
|
||||
) : super(message, cause, enableSuppression, writableStackTrace)
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@ import io.ktor.server.response.*
|
||||
|
||||
fun Application.configureStatusPages() {
|
||||
install(StatusPages) {
|
||||
exception<Throwable> { call, cause ->
|
||||
call.respondText(text = "500: $cause", status = HttpStatusCode.InternalServerError)
|
||||
}
|
||||
exception<IllegalArgumentException> { call, cause ->
|
||||
call.respondText(text = "400: $cause", status = HttpStatusCode.BadRequest)
|
||||
}
|
||||
exception<Throwable> { call, cause ->
|
||||
call.respondText(text = "500: $cause", status = HttpStatusCode.InternalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package dev.usbharu.hideout.service.impl
|
||||
|
||||
import dev.usbharu.hideout.config.Config
|
||||
import dev.usbharu.hideout.exception.UserNotFoundException
|
||||
import dev.usbharu.hideout.repository.IUserRepository
|
||||
import dev.usbharu.hideout.service.IUserAuthService
|
||||
import io.ktor.util.*
|
||||
@@ -24,7 +23,7 @@ class UserAuthService(
|
||||
|
||||
override suspend fun verifyAccount(username: String, password: String): Boolean {
|
||||
val userEntity = userRepository.findByNameAndDomain(username, Config.configData.domain)
|
||||
?: throw UserNotFoundException("$username was not found")
|
||||
?: return false
|
||||
return userEntity.password == hash(password)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user