Compare commits
No commits in common. "b848d6b4e0a141bbd0e65da35e59ac59db011f49" and "d8139d2ab013940ba230549ef5e1f1f969680f9b" have entirely different histories.
b848d6b4e0
...
d8139d2ab0
|
@ -19,15 +19,6 @@ class AuthController(private val service: AuthService) {
|
||||||
) = run {
|
) = run {
|
||||||
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
|
||||||
|
|
||||||
val authenticateData = service.certificate(request, memberId = member.id!!)
|
ApiResponse.ok(service.verify(member, request))
|
||||||
|
|
||||||
if (service.isBlockAuth(authenticateData)) {
|
|
||||||
service.signOut(member.id!!)
|
|
||||||
throw SodaException("운영정책을 위반하여 이용을 제한합니다.")
|
|
||||||
} else {
|
|
||||||
service.authenticate(authenticateData, member.id!!)
|
|
||||||
}
|
|
||||||
|
|
||||||
ApiResponse.ok(null, null)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,76 +3,46 @@ package kr.co.vividnext.sodalive.member.auth
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import kr.co.bootpay.Bootpay
|
import kr.co.bootpay.Bootpay
|
||||||
import kr.co.vividnext.sodalive.common.SodaException
|
import kr.co.vividnext.sodalive.common.SodaException
|
||||||
import kr.co.vividnext.sodalive.member.MemberRepository
|
import kr.co.vividnext.sodalive.member.Member
|
||||||
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.beans.factory.annotation.Value
|
||||||
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
|
||||||
|
@Transactional(readOnly = true)
|
||||||
class AuthService(
|
class AuthService(
|
||||||
private val repository: AuthRepository,
|
private val repository: AuthRepository,
|
||||||
private val objectMapper: ObjectMapper,
|
private val objectMapper: ObjectMapper,
|
||||||
private val blockAuthRepository: BlockAuthRepository,
|
|
||||||
|
|
||||||
private val memberService: MemberService,
|
|
||||||
private val memberRepository: MemberRepository,
|
|
||||||
private val signOutRepository: SignOutRepository,
|
|
||||||
|
|
||||||
@Value("\${bootpay.application-id}")
|
@Value("\${bootpay.application-id}")
|
||||||
private val bootpayApplicationId: String,
|
private val bootpayApplicationId: String,
|
||||||
@Value("\${bootpay.private-key}")
|
@Value("\${bootpay.private-key}")
|
||||||
private val bootpayPrivateKey: String
|
private val bootpayPrivateKey: String
|
||||||
) {
|
) {
|
||||||
fun certificate(request: AuthVerifyRequest, memberId: Long): AuthVerifyCertificate {
|
@Transactional
|
||||||
|
fun verify(member: Member, request: AuthVerifyRequest) {
|
||||||
val bootpay = Bootpay(bootpayApplicationId, bootpayPrivateKey)
|
val bootpay = Bootpay(bootpayApplicationId, bootpayPrivateKey)
|
||||||
|
|
||||||
val authId = repository.getAuthIdByMemberId(memberId = memberId)
|
val authId = repository.getAuthIdByMemberId(memberId = member.id!!)
|
||||||
if (authId != null) throw SodaException("이미 인증된 계정입니다.")
|
if (authId != null) throw SodaException("이미 인증된 계정입니다.")
|
||||||
|
|
||||||
val certificateResult: AuthCertificateResult = try {
|
try {
|
||||||
val token = bootpay.accessToken
|
val token = bootpay.accessToken
|
||||||
if (token["error_code"] != null) throw SodaException("인증정보에 오류가 있습니다.\n다시 시도해 주세요.")
|
if (token["error_code"] != null) throw SodaException("인증정보에 오류가 있습니다.\n다시 시도해 주세요.")
|
||||||
|
|
||||||
val res = bootpay.certificate(request.receiptId)
|
val res = bootpay.certificate(request.receiptId)
|
||||||
objectMapper.convertValue(res, AuthCertificateResult::class.java)
|
val certificateResult = objectMapper.convertValue(res, AuthCertificateResult::class.java)
|
||||||
} catch (e: Exception) {
|
|
||||||
throw SodaException(e.message ?: "인증정보에 오류가 있습니다.\n다시 시도해 주세요.")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
certificateResult.status == 12 &&
|
certificateResult.status == 12 &&
|
||||||
certificateResult.statusLocale == "본인인증완료" &&
|
certificateResult.statusLocale == "본인인증완료" &&
|
||||||
certificateResult.receiptId == request.receiptId
|
certificateResult.receiptId == request.receiptId
|
||||||
) {
|
) {
|
||||||
return certificateResult.authenticateData
|
val certificate = certificateResult.authenticateData
|
||||||
} else {
|
val nowYear = LocalDate.now().year
|
||||||
throw SodaException("인증정보에 오류가 있습니다.\n다시 시도해 주세요.")
|
val certificateYear = certificate.birth.substring(0, 4).toInt()
|
||||||
}
|
if (nowYear - certificateYear >= 19) {
|
||||||
}
|
|
||||||
|
|
||||||
fun isBlockAuth(certificate: AuthVerifyCertificate): Boolean {
|
|
||||||
val blockAuthId = blockAuthRepository.findByUniqueCiAndDi(certificate.unique, certificate.di)
|
|
||||||
return blockAuthId != null && blockAuthId > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
fun signOut(memberId: Long) {
|
|
||||||
val member = memberRepository.findByIdOrNull(memberId) ?: throw SodaException("로그인 정보를 확인해주세요.")
|
|
||||||
member.isActive = false
|
|
||||||
|
|
||||||
val signOut = SignOut(reason = "운영정책을 위반하여 이용을 제한합니다.")
|
|
||||||
signOut.member = member
|
|
||||||
signOutRepository.save(signOut)
|
|
||||||
|
|
||||||
memberService.logoutAll(memberId = memberId)
|
|
||||||
}
|
|
||||||
|
|
||||||
@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(
|
||||||
|
@ -81,7 +51,6 @@ 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,
|
||||||
|
@ -92,5 +61,14 @@ class AuthService(
|
||||||
auth.member = member
|
auth.member = member
|
||||||
|
|
||||||
repository.save(auth)
|
repository.save(auth)
|
||||||
|
} else {
|
||||||
|
throw SodaException("19세 미만 인증 오류")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw SodaException("인증정보에 오류가 있습니다.\n다시 시도해 주세요.")
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
throw SodaException(e.message ?: "인증정보에 오류가 있습니다.\n다시 시도해 주세요.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
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()
|
|
|
@ -1,27 +0,0 @@
|
||||||
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<BlockAuth, Long>, 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()
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue