본인인증 : block 된 사용자 정보로 본인인증을 시도하는 경우

- 본인인증 시도 계정 탈퇴 처리
This commit is contained in:
Klaus 2023-11-09 18:42:32 +09:00
parent 60012a7aad
commit 8be8d15e4c
1 changed files with 44 additions and 45 deletions

View File

@ -10,7 +10,6 @@ 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.Propagation
import org.springframework.transaction.annotation.Transactional
import java.time.LocalDate
@ -32,9 +31,7 @@ class AuthService(
) {
private val blockMessage = "운영정책을 위반하여 이용을 제한합니다."
@Transactional
fun verify(memberId: Long, request: AuthVerifyRequest) {
val member = memberRepository.findByIdOrNull(memberId) ?: throw SodaException("로그인 정보를 확인해주세요.")
val bootpay = Bootpay(bootpayApplicationId, bootpayPrivateKey)
val authId = repository.getAuthIdByMemberId(memberId = memberId)
@ -56,60 +53,62 @@ class AuthService(
certificateResult.receiptId == request.receiptId
) {
val certificate = certificateResult.authenticateData
if (isBlockAuth(certificate)) {
try {
signOut(memberId = memberId)
} catch (_: Exception) {
}
if (!checkBlockAuth(certificate, memberId)) {
throw SodaException(blockMessage)
}
val nowYear = LocalDate.now().year
val certificateYear = certificate.birth.substring(0, 4).toInt()
if (nowYear - certificateYear >= 19) {
val memberIds = repository.getActiveMemberIdsByDi(di = certificate.di)
if (memberIds.size >= 3) {
throw SodaException(
"이미 본인인증한 계정 ${memberIds.size}개 이용중입니다.\n" +
"소다라이브의 본인인증은 최대 3개의 계정만 이용할 수 있습니다."
)
}
val auth = Auth(
name = certificate.name,
birth = certificate.birth,
uniqueCi = certificate.unique,
di = certificate.di,
gender = certificate.gender
)
auth.member = member
repository.save(auth)
} else {
throw SodaException("19세 미만 인증 오류")
val nowYear = LocalDate.now().year
val certificateYear = certificate.birth.substring(0, 4).toInt()
if (nowYear - certificateYear >= 19) {
authenticate(certificate, memberId)
} else {
throw SodaException("19세 미만 인증 오류")
}
}
} else {
throw SodaException("인증정보에 오류가 있습니다.\n다시 시도해 주세요.")
}
}
private fun isBlockAuth(certificate: AuthVerifyCertificate): Boolean {
@Transactional
fun checkBlockAuth(certificate: AuthVerifyCertificate, memberId: Long): Boolean {
val blockAuthId = blockAuthRepository.findByUniqueCiAndDi(certificate.unique, certificate.di)
return blockAuthId != null && blockAuthId > 0
if (blockAuthId != null && blockAuthId > 0) {
val member = memberRepository.findByIdOrNull(memberId) ?: throw SodaException("로그인 정보를 확인해주세요.")
member.isActive = false
val signOut = SignOut(reason = blockMessage)
signOut.member = member
signOutRepository.save(signOut)
memberService.logoutAll(memberId = member.id!!)
return true
}
return false
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
fun signOut(memberId: Long) {
@Transactional
fun authenticate(certificate: AuthVerifyCertificate, memberId: Long) {
val memberIds = repository.getActiveMemberIdsByDi(di = certificate.di)
if (memberIds.size >= 3) {
throw SodaException(
"이미 본인인증한 계정 ${memberIds.size}개 이용중입니다.\n" +
"소다라이브의 본인인증은 최대 3개의 계정만 이용할 수 있습니다."
)
}
val member = memberRepository.findByIdOrNull(memberId) ?: throw SodaException("로그인 정보를 확인해주세요.")
member.isActive = false
val auth = Auth(
name = certificate.name,
birth = certificate.birth,
uniqueCi = certificate.unique,
di = certificate.di,
gender = certificate.gender
)
auth.member = member
val signOut = SignOut(reason = blockMessage)
signOut.member = member
signOutRepository.save(signOut)
memberService.logoutAll(memberId = member.id!!)
repository.save(auth)
}
}