본인인증 #64
| @@ -13,6 +13,8 @@ interface AuthRepository : JpaRepository<Auth, Long>, AuthQueryRepository | ||||
| interface AuthQueryRepository { | ||||
|     fun getOldestCreatedAtByDi(di: String): LocalDateTime | ||||
|     fun getMemberIdsByDi(di: String): List<Long> | ||||
|     fun getAuthIdByMemberId(memberId: Long): Long? | ||||
|     fun getActiveMemberIdsByDi(di: String): List<Long> | ||||
| } | ||||
|  | ||||
| class AuthQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : AuthQueryRepository { | ||||
| @@ -33,4 +35,25 @@ class AuthQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : AuthQ | ||||
|             .where(auth.di.eq(di)) | ||||
|             .fetch() | ||||
|     } | ||||
|  | ||||
|     override fun getAuthIdByMemberId(memberId: Long): Long? { | ||||
|         return queryFactory | ||||
|             .select(auth.id) | ||||
|             .from(auth) | ||||
|             .innerJoin(auth.member, member) | ||||
|             .where(auth.member.id.eq(memberId)) | ||||
|             .fetchFirst() | ||||
|     } | ||||
|  | ||||
|     override fun getActiveMemberIdsByDi(di: String): List<Long> { | ||||
|         return queryFactory | ||||
|             .select(member.id) | ||||
|             .from(member) | ||||
|             .leftJoin(member.auth, auth) | ||||
|             .where( | ||||
|                 auth.di.eq(di) | ||||
|                     .and(member.isActive.isTrue) | ||||
|             ) | ||||
|             .fetch() | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -23,6 +23,10 @@ class AuthService( | ||||
|     @Transactional | ||||
|     fun verify(member: Member, request: AuthVerifyRequest) { | ||||
|         val bootpay = Bootpay(bootpayApplicationId, bootpayPrivateKey) | ||||
|  | ||||
|         val authId = repository.getAuthIdByMemberId(memberId = member.id!!) | ||||
|         if (authId != null) throw SodaException("이미 인증된 계정입니다.") | ||||
|  | ||||
|         try { | ||||
|             val token = bootpay.accessToken | ||||
|             if (token["error_code"] != null) throw SodaException("인증정보에 오류가 있습니다.\n다시 시도해 주세요.") | ||||
| @@ -39,6 +43,14 @@ class AuthService( | ||||
|                 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, | ||||
| @@ -56,7 +68,7 @@ class AuthService( | ||||
|                 throw SodaException("인증정보에 오류가 있습니다.\n다시 시도해 주세요.") | ||||
|             } | ||||
|         } catch (e: Exception) { | ||||
|             throw SodaException("인증정보에 오류가 있습니다.\n다시 시도해 주세요.") | ||||
|             throw SodaException(e.message ?: "인증정보에 오류가 있습니다.\n다시 시도해 주세요.") | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user