From a02c995b6a04489d5a79dba3a8476887989c399f Mon Sep 17 00:00:00 2001 From: usbharu Date: Thu, 4 Apr 2024 12:57:24 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E8=A6=8F=E3=82=A2=E3=82=AB?= =?UTF-8?q?=E3=82=A6=E3=83=B3=E3=83=88=E4=BD=9C=E6=88=90=E3=82=A8=E3=83=B3?= =?UTF-8?q?=E3=83=89=E3=83=9D=E3=82=A4=E3=83=B3=E3=83=88=E3=82=92=E5=88=86?= =?UTF-8?q?=E9=9B=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exposedquery/NoteQueryServiceImpl.kt | 12 +++++------ .../interfaces/api/auth/AuthController.kt | 21 ++++++++++++++++++- .../core/interfaces/api/auth/SignUpForm.kt | 7 +++++++ .../core/service/auth/AuthApiService.kt | 8 +++++++ .../core/service/auth/RegisterAccountDto.kt | 7 +++++++ .../config/MastodonApiSecurityConfig.kt | 2 +- src/main/resources/templates/sign_up.html | 12 ++++++++++- 7 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/SignUpForm.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/core/service/auth/AuthApiService.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/core/service/auth/RegisterAccountDto.kt diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/infrastructure/exposedquery/NoteQueryServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/infrastructure/exposedquery/NoteQueryServiceImpl.kt index b69475c7..85ee76ae 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/infrastructure/exposedquery/NoteQueryServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/infrastructure/exposedquery/NoteQueryServiceImpl.kt @@ -43,9 +43,9 @@ class NoteQueryServiceImpl(private val postRepository: PostRepository, private v .selectAll().where { Posts.id eq id } .let { (it.toNote() ?: return null) to ( - postQueryMapper.map(it) - .singleOrNull() ?: return null - ) + postQueryMapper.map(it) + .singleOrNull() ?: return null + ) } } @@ -57,9 +57,9 @@ class NoteQueryServiceImpl(private val postRepository: PostRepository, private v .selectAll().where { Posts.apId eq apId } .let { (it.toNote() ?: return null) to ( - postQueryMapper.map(it) - .singleOrNull() ?: return null - ) + postQueryMapper.map(it) + .singleOrNull() ?: return null + ) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt b/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt index 7b582c77..93e05968 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/AuthController.kt @@ -16,12 +16,31 @@ package dev.usbharu.hideout.core.interfaces.api.auth +import dev.usbharu.hideout.core.service.auth.AuthApiService +import dev.usbharu.hideout.core.service.auth.RegisterAccountDto 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 +import org.springframework.web.bind.annotation.PostMapping @Controller -class AuthController { +class AuthController(private val authApiService: AuthApiService) { @GetMapping("/auth/sign_up") @Suppress("FunctionOnlyReturningConstant") fun signUp(): String = "sign_up" + + @PostMapping("/auth/sign_up") + suspend fun signUp(@Validated @ModelAttribute signUpForm: SignUpForm, model: Model): String { + val registerAccount = authApiService.registerAccount( + RegisterAccountDto( + signUpForm.username, + signUpForm.password, + signUpForm.recaptchaResponse + ) + ) + + return "redirect:"+registerAccount.first.url + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/SignUpForm.kt b/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/SignUpForm.kt new file mode 100644 index 00000000..5c032c5a --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/core/interfaces/api/auth/SignUpForm.kt @@ -0,0 +1,7 @@ +package dev.usbharu.hideout.core.interfaces.api.auth + +data class SignUpForm( + val username: String, + val password: String, + val recaptchaResponse: String +) diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/auth/AuthApiService.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/auth/AuthApiService.kt new file mode 100644 index 00000000..80179321 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/auth/AuthApiService.kt @@ -0,0 +1,8 @@ +package dev.usbharu.hideout.core.service.auth + +import dev.usbharu.hideout.core.domain.model.actor.Actor +import dev.usbharu.hideout.core.domain.model.userdetails.UserDetail + +interface AuthApiService { + suspend fun registerAccount(registerAccountDto: RegisterAccountDto): Pair +} \ No newline at end of file diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/auth/RegisterAccountDto.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/auth/RegisterAccountDto.kt new file mode 100644 index 00000000..84a2d881 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/auth/RegisterAccountDto.kt @@ -0,0 +1,7 @@ +package dev.usbharu.hideout.core.service.auth + +data class RegisterAccountDto( + val username:String, + val password:String, + val recaptchaResponse:String +) diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/config/MastodonApiSecurityConfig.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/config/MastodonApiSecurityConfig.kt index 39ec70fb..c4bce048 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/config/MastodonApiSecurityConfig.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/config/MastodonApiSecurityConfig.kt @@ -41,7 +41,7 @@ class MastodonApiSecurityConfig { authorizeHttpRequests { authorize(POST, "/api/v1/apps", permitAll) authorize(GET, "/api/v1/instance/**", permitAll) - authorize(POST, "/api/v1/accounts", permitAll) + authorize(POST, "/api/v1/accounts", authenticated) authorize(GET, "/api/v1/accounts/verify_credentials", rf.hasScope("read:accounts")) authorize(GET, "/api/v1/accounts/relationships", rf.hasScope("read:follows")) diff --git a/src/main/resources/templates/sign_up.html b/src/main/resources/templates/sign_up.html index 079fdd7c..ce36b424 100644 --- a/src/main/resources/templates/sign_up.html +++ b/src/main/resources/templates/sign_up.html @@ -3,12 +3,22 @@ SignUp + + -
+ +