feat: /auth/sign_up を改良

This commit is contained in:
usbharu 2024-08-26 17:50:03 +09:00
parent 533582534f
commit c48694ab0b
Signed by: usbharu
GPG Key ID: 8CB1087135660B8D
7 changed files with 33 additions and 10 deletions

View File

@ -19,7 +19,7 @@ class GetLocalInstanceApplicationService(
transaction, transaction,
logger logger
) { ) {
var cachedInstance: Instance? = null private var cachedInstance: Instance? = null
override suspend fun internalExecute(command: Unit, principal: Principal): Instance { override suspend fun internalExecute(command: Unit, principal: Principal): Instance {
if (cachedInstance != null) { if (cachedInstance != null) {
@ -28,9 +28,9 @@ class GetLocalInstanceApplicationService(
} }
val instance = ( val instance = (
instanceRepository.findByUrl(applicationConfig.url.toURI()) instanceRepository.findByUrl(applicationConfig.url.toURI())
?: throw InternalServerException("Local instance not found.") ?: throw InternalServerException("Local instance not found.")
) )
cachedInstance = Instance.of(instance) cachedInstance = Instance.of(instance)
@Suppress("UnsafeCallOnNullableType") @Suppress("UnsafeCallOnNullableType")

View File

@ -14,13 +14,15 @@
* limitations under the License. * limitations under the License.
*/ */
package dev.usbharu.hideout.core.interfaces.api.auth package dev.usbharu.hideout.core.interfaces.web.auth
import dev.usbharu.hideout.core.application.actor.RegisterLocalActor import dev.usbharu.hideout.core.application.actor.RegisterLocalActor
import dev.usbharu.hideout.core.application.actor.RegisterLocalActorApplicationService import dev.usbharu.hideout.core.application.actor.RegisterLocalActorApplicationService
import dev.usbharu.hideout.core.application.instance.GetLocalInstanceApplicationService
import dev.usbharu.hideout.core.domain.model.support.principal.Anonymous import dev.usbharu.hideout.core.domain.model.support.principal.Anonymous
import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletRequest
import org.springframework.stereotype.Controller import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.validation.annotation.Validated import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.ModelAttribute import org.springframework.web.bind.annotation.ModelAttribute
@ -29,10 +31,14 @@ import org.springframework.web.bind.annotation.PostMapping
@Controller @Controller
class AuthController( class AuthController(
private val registerLocalActorApplicationService: RegisterLocalActorApplicationService, private val registerLocalActorApplicationService: RegisterLocalActorApplicationService,
private val getLocalInstanceApplicationService: GetLocalInstanceApplicationService,
) { ) {
@GetMapping("/auth/sign_up") @GetMapping("/auth/sign_up")
@Suppress("FunctionOnlyReturningConstant") @Suppress("FunctionOnlyReturningConstant")
fun signUp(): String = "sign_up" suspend fun signUp(model: Model): String {
model.addAttribute("instance", getLocalInstanceApplicationService.execute(Unit, Anonymous))
return "sign_up"
}
@PostMapping("/auth/sign_up") @PostMapping("/auth/sign_up")
suspend fun signUp(@Validated @ModelAttribute signUpForm: SignUpForm, request: HttpServletRequest): String { suspend fun signUp(@Validated @ModelAttribute signUpForm: SignUpForm, request: HttpServletRequest): String {

View File

@ -1,4 +1,4 @@
package dev.usbharu.hideout.core.interfaces.api.auth package dev.usbharu.hideout.core.interfaces.web.auth
data class SignUpForm( data class SignUpForm(
val username: String, val username: String,

View File

@ -1,3 +1,6 @@
auth-signUp.password=\u30D1\u30B9\u30EF\u30FC\u30C9
auth-signUp.register=\u767B\u9332\u3059\u308B
auth-signUp.username=\u30E6\u30FC\u30B6\u30FC\u540D
common.audio=\u30AA\u30FC\u30C7\u30A3\u30AA common.audio=\u30AA\u30FC\u30C7\u30A3\u30AA
common.audio-download-link=\u97F3\u58F0\u30D5\u30A1\u30A4\u30EB\u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9 common.audio-download-link=\u97F3\u58F0\u30D5\u30A1\u30A4\u30EB\u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9
common.empty=\u8868\u793A\u3059\u308B\u3082\u306E\u304C\u3042\u308A\u307E\u305B\u3093 common.empty=\u8868\u793A\u3059\u308B\u3082\u306E\u304C\u3042\u308A\u307E\u305B\u3093

View File

@ -1,3 +1,6 @@
auth-signUp.password=Password
auth-signUp.register=Register Account
auth-signUp.username=Username
common.audio=Audio common.audio=Audio
common.audio-download-link=Download the audio. common.audio-download-link=Download the audio.
common.empty=Empty common.empty=Empty

View File

@ -1,3 +1,6 @@
auth-signUp.password=\u30D1\u30B9\u30EF\u30FC\u30C9
auth-signUp.register=\u767B\u9332\u3059\u308B
auth-signUp.username=\u30E6\u30FC\u30B6\u30FC\u540D
common.audio=\u30AA\u30FC\u30C7\u30A3\u30AA common.audio=\u30AA\u30FC\u30C7\u30A3\u30AA
common.audio-download-link=\u97F3\u58F0\u30D5\u30A1\u30A4\u30EB\u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9 common.audio-download-link=\u97F3\u58F0\u30D5\u30A1\u30A4\u30EB\u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9
common.empty=\u8868\u793A\u3059\u308B\u3082\u306E\u304C\u3042\u308A\u307E\u305B\u3093 common.empty=\u8868\u793A\u3059\u308B\u3082\u306E\u304C\u3042\u308A\u307E\u305B\u3093

View File

@ -2,13 +2,21 @@
<html lang="ja" xmlns:th="http://www.thymeleaf.org"> <html lang="ja" xmlns:th="http://www.thymeleaf.org">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>SignUp</title> <title th:text="#{auth-signUp.register}">Register Account</title>
<meta property="og:url" th:content="${instance.url + '/auth/sign_up'}">
<meta property="og:title" th:content="#{auth-signUp.register}">
</head> </head>
<body> <body>
<form method='post' th:action="@{/auth/sign_up}"> <form method='post' th:action="@{/auth/sign_up}">
<input name='username' type='text' value=''> <div>
<input name='password' type='password'> <label for="signUp-form-username" th:text="#{auth-signUp.username}">Username</label>
<input id="signUp-form-username" name='username' type='text' value=''>
</div>
<div>
<label for="signUp-form-password" th:text="#{auth-signUp.password}">Password</label>
<input id="signUp-form-password" name='password' type='password'>
</div>
<input type="submit"> <input type="submit">
</form> </form>
</body> </body>