From e0e24be68837e137c36bd4e46150e656c31a84cd Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 9 Nov 2023 16:29:23 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B3=B8=EC=9D=B8=EC=9D=B8=EC=A6=9D=20:=20bloc?= =?UTF-8?q?k=20=EB=90=9C=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=EB=A1=9C=20=EB=B3=B8=EC=9D=B8=EC=9D=B8=EC=A6=9D?= =?UTF-8?q?=EC=9D=84=20=EC=8B=9C=EB=8F=84=ED=95=98=EB=8A=94=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20-=20=EB=B3=B8=EC=9D=B8=EC=9D=B8=EC=A6=9D=20?= =?UTF-8?q?=EC=8B=9C=EB=8F=84=20=EA=B3=84=EC=A0=95=20=ED=83=88=ED=87=B4=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sodalive/member/auth/AuthController.kt | 2 +- .../sodalive/member/auth/AuthService.kt | 37 ++++++++++++++++++- .../sodalive/member/auth/BlockAuth.kt | 19 ++++++++++ .../member/auth/BlockAuthRepository.kt | 27 ++++++++++++++ 4 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/kr/co/vividnext/sodalive/member/auth/BlockAuth.kt create mode 100644 src/main/kotlin/kr/co/vividnext/sodalive/member/auth/BlockAuthRepository.kt diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/member/auth/AuthController.kt b/src/main/kotlin/kr/co/vividnext/sodalive/member/auth/AuthController.kt index 764a24e..8a7cecc 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/member/auth/AuthController.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/member/auth/AuthController.kt @@ -19,6 +19,6 @@ class AuthController(private val service: AuthService) { ) = run { if (member == null) throw SodaException("로그인 정보를 확인해주세요.") - ApiResponse.ok(service.verify(member, request)) + ApiResponse.ok(service.verify(member.id!!, request)) } } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/member/auth/AuthService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/member/auth/AuthService.kt index a7a09f3..d3f66f0 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/member/auth/AuthService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/member/auth/AuthService.kt @@ -4,7 +4,12 @@ import com.fasterxml.jackson.databind.ObjectMapper import kr.co.bootpay.Bootpay import kr.co.vividnext.sodalive.common.SodaException import kr.co.vividnext.sodalive.member.Member +import kr.co.vividnext.sodalive.member.MemberRepository +import kr.co.vividnext.sodalive.member.MemberService +import kr.co.vividnext.sodalive.member.SignOut +import kr.co.vividnext.sodalive.member.SignOutRepository import org.springframework.beans.factory.annotation.Value +import org.springframework.data.repository.findByIdOrNull import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import java.time.LocalDate @@ -14,17 +19,25 @@ import java.time.LocalDate class AuthService( private val repository: AuthRepository, private val objectMapper: ObjectMapper, + private val blockAuthRepository: BlockAuthRepository, + + private val memberService: MemberService, + private val memberRepository: MemberRepository, + private val signOutRepository: SignOutRepository, @Value("\${bootpay.application-id}") private val bootpayApplicationId: String, @Value("\${bootpay.private-key}") private val bootpayPrivateKey: String ) { + private val blockMessage = "운영정책을 위반하여 이용을 제한합니다." + @Transactional - fun verify(member: Member, request: AuthVerifyRequest) { + fun verify(memberId: Long, request: AuthVerifyRequest) { + val member = memberRepository.findByIdOrNull(memberId) ?: throw SodaException("로그인 정보를 확인해주세요.") val bootpay = Bootpay(bootpayApplicationId, bootpayPrivateKey) - val authId = repository.getAuthIdByMemberId(memberId = member.id!!) + val authId = repository.getAuthIdByMemberId(memberId = memberId) if (authId != null) throw SodaException("이미 인증된 계정입니다.") try { @@ -42,6 +55,12 @@ class AuthService( val certificate = certificateResult.authenticateData val nowYear = LocalDate.now().year val certificateYear = certificate.birth.substring(0, 4).toInt() + + if (isBlockAuth(certificate)) { + signOut(member) + throw SodaException(blockMessage) + } + if (nowYear - certificateYear >= 19) { val memberIds = repository.getActiveMemberIdsByDi(di = certificate.di) if (memberIds.size >= 3) { @@ -71,4 +90,18 @@ class AuthService( throw SodaException(e.message ?: "인증정보에 오류가 있습니다.\n다시 시도해 주세요.") } } + + private fun isBlockAuth(certificate: AuthVerifyCertificate): Boolean { + val blockAuthId = blockAuthRepository.findByUniqueCiAndDi(certificate.unique, certificate.di) + return blockAuthId != null && blockAuthId > 0 + } + + private fun signOut(member: Member) { + memberService.logoutAll(memberId = member.id!!) + member.isActive = false + + val signOut = SignOut(reason = blockMessage) + signOut.member = member + signOutRepository.save(signOut) + } } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/member/auth/BlockAuth.kt b/src/main/kotlin/kr/co/vividnext/sodalive/member/auth/BlockAuth.kt new file mode 100644 index 0000000..4bd2d4a --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/member/auth/BlockAuth.kt @@ -0,0 +1,19 @@ +package kr.co.vividnext.sodalive.member.auth + +import kr.co.vividnext.sodalive.common.BaseEntity +import javax.persistence.Column +import javax.persistence.Entity + +@Entity +data class BlockAuth( + @Column(nullable = false) + val name: String, + @Column(nullable = false) + val birth: String, + @Column(columnDefinition = "TEXT", nullable = false) + val uniqueCi: String, + @Column(columnDefinition = "TEXT", nullable = false) + val di: String, + @Column(nullable = false) + val gender: Int +) : BaseEntity() diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/member/auth/BlockAuthRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/member/auth/BlockAuthRepository.kt new file mode 100644 index 0000000..ee36a52 --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/member/auth/BlockAuthRepository.kt @@ -0,0 +1,27 @@ +package kr.co.vividnext.sodalive.member.auth + +import com.querydsl.jpa.impl.JPAQueryFactory +import kr.co.vividnext.sodalive.member.auth.QBlockAuth.blockAuth +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository + +@Repository +interface BlockAuthRepository : JpaRepository, BlockAuthQueryRepository + +interface BlockAuthQueryRepository { + fun findByUniqueCiAndDi(uniqueCi: String, di: String): Long? +} + +@Repository +class BlockAuthQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : BlockAuthQueryRepository { + override fun findByUniqueCiAndDi(uniqueCi: String, di: String): Long? { + return queryFactory + .select(blockAuth.id) + .from(blockAuth) + .where( + blockAuth.uniqueCi.eq(uniqueCi) + .and(blockAuth.di.eq(di)) + ) + .fetchFirst() + } +}