diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/SecurityConfig.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/SecurityConfig.kt index 5e5e9821..a9730eda 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/SecurityConfig.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/SecurityConfig.kt @@ -97,6 +97,12 @@ class SecurityConfig { } formLogin { loginPage = "/auth/sign_in" + loginProcessingUrl = "/login" + defaultSuccessUrl("/home", false) + } + logout { + logoutUrl = "/auth/sign_out" + logoutSuccessUrl = "/auth/sign_in" } } return http.build() diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/SpringMvcConfig.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/SpringMvcConfig.kt index ee75a0ef..301762d4 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/SpringMvcConfig.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/SpringMvcConfig.kt @@ -16,20 +16,29 @@ package dev.usbharu.hideout.core.config +import dev.usbharu.hideout.core.infrastructure.springframework.SPAInterceptor import dev.usbharu.hideout.generate.JsonOrFormModelMethodProcessor import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.http.converter.HttpMessageConverter import org.springframework.web.method.support.HandlerMethodArgumentResolver +import org.springframework.web.servlet.config.annotation.InterceptorRegistry import org.springframework.web.servlet.config.annotation.WebMvcConfigurer import org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor import org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor @Configuration -class MvcConfigurer(private val jsonOrFormModelMethodProcessor: JsonOrFormModelMethodProcessor) : WebMvcConfigurer { +class MvcConfigurer( + private val jsonOrFormModelMethodProcessor: JsonOrFormModelMethodProcessor, + private val spaInterceptor: SPAInterceptor +) : WebMvcConfigurer { override fun addArgumentResolvers(resolvers: MutableList) { resolvers.add(jsonOrFormModelMethodProcessor) } + + override fun addInterceptors(registry: InterceptorRegistry) { + registry.addInterceptor(spaInterceptor) + } } @Configuration diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/WebMvcConfig.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/WebMvcConfig.kt deleted file mode 100644 index d940f617..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/config/WebMvcConfig.kt +++ /dev/null @@ -1,13 +0,0 @@ -package dev.usbharu.hideout.core.config - -import dev.usbharu.hideout.core.infrastructure.springframework.SPAInterceptor -import org.springframework.context.annotation.Configuration -import org.springframework.web.servlet.config.annotation.InterceptorRegistry -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer - -@Configuration -class WebMvcConfig(private val spaInterceptor: SPAInterceptor) : WebMvcConfigurer { - override fun addInterceptors(registry: InterceptorRegistry) { - registry.addInterceptor(spaInterceptor) - } -} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/web/IndexController.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/web/IndexController.kt new file mode 100644 index 00000000..b7b1b879 --- /dev/null +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/web/IndexController.kt @@ -0,0 +1,24 @@ +package dev.usbharu.hideout.core.interfaces.web + +import dev.usbharu.hideout.core.config.ApplicationConfig +import dev.usbharu.hideout.core.infrastructure.springframework.SpringSecurityFormLoginPrincipalContextHolder +import org.springframework.stereotype.Controller +import org.springframework.ui.Model +import org.springframework.web.bind.annotation.GetMapping + +@Controller +class IndexController( + private val applicationConfig: ApplicationConfig, + private val springSecurityFormLoginPrincipalContextHolder: SpringSecurityFormLoginPrincipalContextHolder +) { + @GetMapping("/") + suspend fun index(model: Model): String { + if (springSecurityFormLoginPrincipalContextHolder.getPrincipal().userDetailId != null) { + return "redirect:/home" + } + + + model.addAttribute("applicationConfig", applicationConfig) + return "top" + } +} \ No newline at end of file diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/web/auth/AuthController.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/web/auth/AuthController.kt index 9b0d297b..7e985359 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/web/auth/AuthController.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/interfaces/web/auth/AuthController.kt @@ -19,6 +19,7 @@ package dev.usbharu.hideout.core.interfaces.web.auth import dev.usbharu.hideout.core.application.actor.RegisterLocalActor import dev.usbharu.hideout.core.application.actor.RegisterLocalActorApplicationService import dev.usbharu.hideout.core.application.instance.GetLocalInstanceApplicationService +import dev.usbharu.hideout.core.config.ApplicationConfig import dev.usbharu.hideout.core.domain.model.support.principal.Anonymous import jakarta.servlet.http.HttpServletRequest import org.springframework.stereotype.Controller @@ -30,6 +31,7 @@ import org.springframework.web.bind.annotation.PostMapping @Controller class AuthController( + private val applicationConfig: ApplicationConfig, private val registerLocalActorApplicationService: RegisterLocalActorApplicationService, private val getLocalInstanceApplicationService: GetLocalInstanceApplicationService, ) { @@ -50,4 +52,15 @@ class AuthController( request.login(signUpForm.username, signUpForm.password) return "redirect:$uri" } + + @GetMapping("/auth/sign_in") + suspend fun signIn(model: Model): String { + model.addAttribute("applicationConfig", applicationConfig) + return "sign_in" + } + + @GetMapping("/auth/sign_out") + fun signOut(): String { + return "sign_out" + } } diff --git a/hideout-core/src/main/resources/messages/hideout-web-messages.properties b/hideout-core/src/main/resources/messages/hideout-web-messages.properties index f2b9318e..d2c0de78 100644 --- a/hideout-core/src/main/resources/messages/hideout-web-messages.properties +++ b/hideout-core/src/main/resources/messages/hideout-web-messages.properties @@ -1,3 +1,4 @@ +auth-signIn.title=\u30ED\u30B0\u30A4\u30F3 - {0} auth-signUp.password=\u30D1\u30B9\u30EF\u30FC\u30C9 auth-signUp.register=\u767B\u9332\u3059\u308B auth-signUp.username=\u30E6\u30FC\u30B6\u30FC\u540D diff --git a/hideout-core/src/main/resources/messages/hideout-web-messages_en_US.properties b/hideout-core/src/main/resources/messages/hideout-web-messages_en_US.properties index 67b651f8..e19ac2b5 100644 --- a/hideout-core/src/main/resources/messages/hideout-web-messages_en_US.properties +++ b/hideout-core/src/main/resources/messages/hideout-web-messages_en_US.properties @@ -1,3 +1,4 @@ +auth-signIn.title=Sign in - {0} auth-signUp.password=Password auth-signUp.register=Register Account auth-signUp.username=Username diff --git a/hideout-core/src/main/resources/messages/hideout-web-messages_ja_JP.properties b/hideout-core/src/main/resources/messages/hideout-web-messages_ja_JP.properties index f2b9318e..d2c0de78 100644 --- a/hideout-core/src/main/resources/messages/hideout-web-messages_ja_JP.properties +++ b/hideout-core/src/main/resources/messages/hideout-web-messages_ja_JP.properties @@ -1,3 +1,4 @@ +auth-signIn.title=\u30ED\u30B0\u30A4\u30F3 - {0} auth-signUp.password=\u30D1\u30B9\u30EF\u30FC\u30C9 auth-signUp.register=\u767B\u9332\u3059\u308B auth-signUp.username=\u30E6\u30FC\u30B6\u30FC\u540D diff --git a/hideout-core/src/main/resources/templates/index.html b/hideout-core/src/main/resources/templates/index.html index 9d9d39df..9b20d93e 100644 --- a/hideout-core/src/main/resources/templates/index.html +++ b/hideout-core/src/main/resources/templates/index.html @@ -2,14 +2,16 @@ - Title + Index - +