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