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

View File

@ -14,13 +14,15 @@
* 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.RegisterLocalActorApplicationService
import dev.usbharu.hideout.core.application.instance.GetLocalInstanceApplicationService
import dev.usbharu.hideout.core.domain.model.support.principal.Anonymous
import jakarta.servlet.http.HttpServletRequest
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.ModelAttribute
@ -29,10 +31,14 @@ import org.springframework.web.bind.annotation.PostMapping
@Controller
class AuthController(
private val registerLocalActorApplicationService: RegisterLocalActorApplicationService,
private val getLocalInstanceApplicationService: GetLocalInstanceApplicationService,
) {
@GetMapping("/auth/sign_up")
@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")
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(
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-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

View File

@ -1,3 +1,6 @@
auth-signUp.password=Password
auth-signUp.register=Register Account
auth-signUp.username=Username
common.audio=Audio
common.audio-download-link=Download the audio.
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-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

View File

@ -2,13 +2,21 @@
<html lang="ja" xmlns:th="http://www.thymeleaf.org">
<head>
<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>
<body>
<form method='post' th:action="@{/auth/sign_up}">
<input name='username' type='text' value=''>
<input name='password' type='password'>
<div>
<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">
</form>
</body>