test #74
|
@ -19,6 +19,14 @@ class AuthController(private val service: AuthService) {
|
||||||
) = run {
|
) = run {
|
||||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||||
|
|
||||||
ApiResponse.ok(service.verify(member.id!!, request))
|
val authenticateData = service.certificate(request, memberId = member.id!!)
|
||||||
|
|
||||||
|
if (service.isBlockAuth(authenticateData)) {
|
||||||
|
service.signOut(member.id!!)
|
||||||
|
} else {
|
||||||
|
service.authenticate(authenticateData, member.id!!)
|
||||||
|
}
|
||||||
|
|
||||||
|
ApiResponse.ok(null, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ 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.Transactional
|
import org.springframework.transaction.annotation.Transactional
|
||||||
import java.time.LocalDate
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class AuthService(
|
class AuthService(
|
||||||
|
@ -30,7 +29,7 @@ class AuthService(
|
||||||
) {
|
) {
|
||||||
private val blockMessage = "운영정책을 위반하여 이용을 제한합니다."
|
private val blockMessage = "운영정책을 위반하여 이용을 제한합니다."
|
||||||
|
|
||||||
fun verify(memberId: Long, request: AuthVerifyRequest) {
|
fun certificate(request: AuthVerifyRequest, memberId: Long): AuthVerifyCertificate {
|
||||||
val bootpay = Bootpay(bootpayApplicationId, bootpayPrivateKey)
|
val bootpay = Bootpay(bootpayApplicationId, bootpayPrivateKey)
|
||||||
|
|
||||||
val authId = repository.getAuthIdByMemberId(memberId = memberId)
|
val authId = repository.getAuthIdByMemberId(memberId = memberId)
|
||||||
|
@ -51,41 +50,27 @@ class AuthService(
|
||||||
certificateResult.statusLocale == "본인인증완료" &&
|
certificateResult.statusLocale == "본인인증완료" &&
|
||||||
certificateResult.receiptId == request.receiptId
|
certificateResult.receiptId == request.receiptId
|
||||||
) {
|
) {
|
||||||
val certificate = certificateResult.authenticateData
|
return certificateResult.authenticateData
|
||||||
if (!checkBlockAuth(certificate, memberId)) {
|
|
||||||
throw SodaException(blockMessage)
|
|
||||||
} else {
|
|
||||||
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 {
|
} else {
|
||||||
throw SodaException("인증정보에 오류가 있습니다.\n다시 시도해 주세요.")
|
throw SodaException("인증정보에 오류가 있습니다.\n다시 시도해 주세요.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
fun isBlockAuth(certificate: AuthVerifyCertificate): Boolean {
|
||||||
fun checkBlockAuth(certificate: AuthVerifyCertificate, memberId: Long): Boolean {
|
|
||||||
val blockAuthId = blockAuthRepository.findByUniqueCiAndDi(certificate.unique, certificate.di)
|
val blockAuthId = blockAuthRepository.findByUniqueCiAndDi(certificate.unique, certificate.di)
|
||||||
if (blockAuthId != null && blockAuthId > 0) {
|
return blockAuthId != null && blockAuthId > 0
|
||||||
val member = memberRepository.findByIdOrNull(memberId) ?: throw SodaException("로그인 정보를 확인해주세요.")
|
}
|
||||||
member.isActive = false
|
|
||||||
|
|
||||||
val signOut = SignOut(reason = blockMessage)
|
@Transactional
|
||||||
signOut.member = member
|
fun signOut(memberId: Long) {
|
||||||
signOutRepository.save(signOut)
|
val member = memberRepository.findByIdOrNull(memberId) ?: throw SodaException("로그인 정보를 확인해주세요.")
|
||||||
|
member.isActive = false
|
||||||
|
|
||||||
memberService.logoutAll(memberId = member.id!!)
|
val signOut = SignOut(reason = blockMessage)
|
||||||
|
signOut.member = member
|
||||||
|
signOutRepository.save(signOut)
|
||||||
|
|
||||||
return true
|
memberService.logoutAll(memberId = memberId)
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
|
Loading…
Reference in New Issue