회원탈퇴 API 추가
This commit is contained in:
@@ -32,6 +32,7 @@ import org.springframework.data.repository.findByIdOrNull
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
|
||||
import org.springframework.security.core.context.SecurityContextHolder
|
||||
import org.springframework.security.core.userdetails.User
|
||||
import org.springframework.security.core.userdetails.UserDetails
|
||||
import org.springframework.security.core.userdetails.UserDetailsService
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException
|
||||
@@ -51,6 +52,7 @@ class MemberService(
|
||||
private val stipulationAgreeRepository: StipulationAgreeRepository,
|
||||
private val creatorFollowingRepository: CreatorFollowingRepository,
|
||||
private val blockMemberRepository: BlockMemberRepository,
|
||||
private val signOutRepository: SignOutRepository,
|
||||
|
||||
private val memberNotificationService: MemberNotificationService,
|
||||
|
||||
@@ -390,4 +392,22 @@ class MemberService(
|
||||
private fun getOrCreateLock(memberId: Long): ReentrantReadWriteLock {
|
||||
return tokenLocks.computeIfAbsent(memberId) { ReentrantReadWriteLock() }
|
||||
}
|
||||
|
||||
@Transactional
|
||||
fun signOut(signOutRequest: SignOutRequest, user: User) {
|
||||
val member = repository.findByEmail(user.username) ?: throw SodaException("로그인 정보를 확인해주세요.")
|
||||
if (!passwordEncoder.matches(signOutRequest.password, member.password)) {
|
||||
throw SodaException("비밀번호가 일치하지 않습니다.")
|
||||
}
|
||||
|
||||
if (signOutRequest.reason.isBlank()) {
|
||||
throw SodaException("탈퇴하려는 이유를 입력해 주세요.")
|
||||
}
|
||||
|
||||
member.isActive = false
|
||||
|
||||
val signOut = SignOut(reason = signOutRequest.reason)
|
||||
signOut.member = member
|
||||
signOutRepository.save(signOut)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user