parent
60012a7aad
commit
8be8d15e4c
|
@ -10,7 +10,6 @@ import kr.co.vividnext.sodalive.member.SignOutRepository
|
||||||
import org.springframework.beans.factory.annotation.Value
|
import org.springframework.beans.factory.annotation.Value
|
||||||
import org.springframework.data.repository.findByIdOrNull
|
import org.springframework.data.repository.findByIdOrNull
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import org.springframework.transaction.annotation.Propagation
|
|
||||||
import org.springframework.transaction.annotation.Transactional
|
import org.springframework.transaction.annotation.Transactional
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
|
|
||||||
|
@ -32,9 +31,7 @@ class AuthService(
|
||||||
) {
|
) {
|
||||||
private val blockMessage = "운영정책을 위반하여 이용을 제한합니다."
|
private val blockMessage = "운영정책을 위반하여 이용을 제한합니다."
|
||||||
|
|
||||||
@Transactional
|
|
||||||
fun verify(memberId: Long, request: AuthVerifyRequest) {
|
fun verify(memberId: Long, request: AuthVerifyRequest) {
|
||||||
val member = memberRepository.findByIdOrNull(memberId) ?: throw SodaException("로그인 정보를 확인해주세요.")
|
|
||||||
val bootpay = Bootpay(bootpayApplicationId, bootpayPrivateKey)
|
val bootpay = Bootpay(bootpayApplicationId, bootpayPrivateKey)
|
||||||
|
|
||||||
val authId = repository.getAuthIdByMemberId(memberId = memberId)
|
val authId = repository.getAuthIdByMemberId(memberId = memberId)
|
||||||
|
@ -56,20 +53,44 @@ class AuthService(
|
||||||
certificateResult.receiptId == request.receiptId
|
certificateResult.receiptId == request.receiptId
|
||||||
) {
|
) {
|
||||||
val certificate = certificateResult.authenticateData
|
val certificate = certificateResult.authenticateData
|
||||||
|
if (!checkBlockAuth(certificate, memberId)) {
|
||||||
if (isBlockAuth(certificate)) {
|
|
||||||
try {
|
|
||||||
signOut(memberId = memberId)
|
|
||||||
} catch (_: Exception) {
|
|
||||||
}
|
|
||||||
|
|
||||||
throw SodaException(blockMessage)
|
throw SodaException(blockMessage)
|
||||||
}
|
} else {
|
||||||
|
|
||||||
val nowYear = LocalDate.now().year
|
val nowYear = LocalDate.now().year
|
||||||
val certificateYear = certificate.birth.substring(0, 4).toInt()
|
val certificateYear = certificate.birth.substring(0, 4).toInt()
|
||||||
|
|
||||||
if (nowYear - certificateYear >= 19) {
|
if (nowYear - certificateYear >= 19) {
|
||||||
|
authenticate(certificate, memberId)
|
||||||
|
} else {
|
||||||
|
throw SodaException("19세 미만 인증 오류")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw SodaException("인증정보에 오류가 있습니다.\n다시 시도해 주세요.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
fun checkBlockAuth(certificate: AuthVerifyCertificate, memberId: Long): Boolean {
|
||||||
|
val blockAuthId = blockAuthRepository.findByUniqueCiAndDi(certificate.unique, certificate.di)
|
||||||
|
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
|
||||||
|
fun authenticate(certificate: AuthVerifyCertificate, memberId: Long) {
|
||||||
val memberIds = repository.getActiveMemberIdsByDi(di = certificate.di)
|
val memberIds = repository.getActiveMemberIdsByDi(di = certificate.di)
|
||||||
if (memberIds.size >= 3) {
|
if (memberIds.size >= 3) {
|
||||||
throw SodaException(
|
throw SodaException(
|
||||||
|
@ -78,6 +99,7 @@ class AuthService(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val member = memberRepository.findByIdOrNull(memberId) ?: throw SodaException("로그인 정보를 확인해주세요.")
|
||||||
val auth = Auth(
|
val auth = Auth(
|
||||||
name = certificate.name,
|
name = certificate.name,
|
||||||
birth = certificate.birth,
|
birth = certificate.birth,
|
||||||
|
@ -88,28 +110,5 @@ class AuthService(
|
||||||
auth.member = member
|
auth.member = member
|
||||||
|
|
||||||
repository.save(auth)
|
repository.save(auth)
|
||||||
} else {
|
|
||||||
throw SodaException("19세 미만 인증 오류")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw SodaException("인증정보에 오류가 있습니다.\n다시 시도해 주세요.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isBlockAuth(certificate: AuthVerifyCertificate): Boolean {
|
|
||||||
val blockAuthId = blockAuthRepository.findByUniqueCiAndDi(certificate.unique, certificate.di)
|
|
||||||
return blockAuthId != null && blockAuthId > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
|
||||||
fun signOut(memberId: Long) {
|
|
||||||
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!!)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue