Skip to content

Commit

Permalink
Merge pull request #447 from Team-Ampersand/develop
Browse files Browse the repository at this point in the history
Develop 변경사항 마스터 반영
  • Loading branch information
esperar authored Sep 30, 2024
2 parents 6647b1f + 7c16c2f commit b7308d0
Show file tree
Hide file tree
Showing 27 changed files with 94 additions and 822 deletions.
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ dependencies {
implementation(Dependencies.GOOGLE_OAUTH_CLIENT)
implementation(Dependencies.YOUTUBE_ANALYTICS)
implementation(Dependencies.GOOGLE_API_SERVICE)
implementation(Dependencies.GAUTH)

// monitoring
implementation(Dependencies.ACTUATOR)
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.dotori.v2.domain.auth.presentation

import com.dotori.v2.domain.auth.util.AuthConverter
import com.dotori.v2.domain.auth.presentation.data.req.SignInGAuthReqDto
import com.dotori.v2.domain.auth.presentation.data.req.SignInEmailAndPasswordReqDto
import com.dotori.v2.domain.auth.presentation.data.req.SignUpReqDto
import com.dotori.v2.domain.auth.presentation.data.res.RefreshResDto
Expand All @@ -17,23 +16,16 @@ import javax.validation.Valid
@RequestMapping("/v2/auth")
class AuthController (
private val signUpService: SignUpService,
private val signInGAuthService: SignInGAuthService,
private val signInEmailAndPasswordService: SignInEmailAndPasswordService,
private val refreshTokenService: RefreshTokenService,
private val changePasswordService: ChangePasswordService,
private val logoutService: LogoutService,
private val authConverter: AuthConverter,
) {
@PostMapping("/signup")
fun signup(@Valid @RequestBody signupReqDto: SignUpReqDto): ResponseEntity<Void> =
signUpService.execute(signupReqDto)
.run { ResponseEntity.ok().build() }

@PostMapping("/gauth")
fun signInGAuth(@Valid @RequestBody signInGAuthReqDto: SignInGAuthReqDto): ResponseEntity<SignInResDto> =
authConverter.toDto(signInGAuthReqDto)
.let { ResponseEntity.ok(signInGAuthService.execute(it)) }

@PostMapping
fun signInEmailAndPassword(@Valid @RequestBody signInEmailAndPasswordReqDto: SignInEmailAndPasswordReqDto): ResponseEntity<SignInResDto> =
authConverter.toDto(signInEmailAndPasswordReqDto)
Expand All @@ -43,11 +35,6 @@ class AuthController (
fun getNewRefreshToken(@RequestHeader("Refresh-Token") refreshToken: String): ResponseEntity<RefreshResDto> =
ResponseEntity.ok().body(refreshTokenService.execute(refreshToken = refreshToken))

@DeleteMapping("/logout")
fun logout(): ResponseEntity<Void> =
logoutService.execute()
.run { ResponseEntity.ok().build() }

@PatchMapping("/password")
fun changePassword(@Valid @RequestBody newPasswordReqDto: NoAuthNewPasswordReqDto): ResponseEntity<Void> =
changePasswordService.execute(newPasswordReqDto)
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import org.springframework.stereotype.Service
import java.time.ZonedDateTime

@Service
@Deprecated("GAuth 로그인으로 변환")
class SignInEmailAndPasswordServiceImpl(
private val memberRepository: MemberRepository,
private val tokenProvider: TokenProvider,
Expand All @@ -27,32 +26,32 @@ class SignInEmailAndPasswordServiceImpl(
val member = memberRepository.findByEmail(signInEmailAndPasswordDto.email)
?: throw MemberNotFoundException()

if (passwordEncoder.matches(signInEmailAndPasswordDto.password, member.password)) {
val accessToken =
tokenProvider.generateAccessToken(signInEmailAndPasswordDto.email, role = member.roles.first())
val accessExp = tokenProvider.accessExpiredTime
val expiresAt = tokenProvider.accessExpiredTime
val refreshToken =
tokenProvider.generateRefreshToken(signInEmailAndPasswordDto.email, role = member.roles.first())
val refreshExp = tokenProvider.refreshExpiredTime

refreshTokenRepository.save(
RefreshToken(
memberId = member.id,
token = refreshToken
)
)
return toResponse(
accessToken,
refreshToken,
accessExp,
refreshExp,
member.roles,
expiresAt
)
} else {
if (!passwordEncoder.matches(signInEmailAndPasswordDto.password, member.password)) {
throw PasswordMismatchException()
}

val accessToken =
tokenProvider.generateAccessToken(signInEmailAndPasswordDto.email, role = member.roles.first())
val accessExp = tokenProvider.accessExpiredTime
val expiresAt = tokenProvider.accessExpiredTime
val refreshToken =
tokenProvider.generateRefreshToken(signInEmailAndPasswordDto.email, role = member.roles.first())
val refreshExp = tokenProvider.refreshExpiredTime

refreshTokenRepository.save(
RefreshToken(
memberId = member.id,
token = refreshToken
)
)
return toResponse(
accessToken = accessToken,
refreshToken = refreshToken,
accessExp = accessExp,
refreshExp = refreshExp,
roles = member.roles,
expiresAt = expiresAt
)
}

private fun toResponse(
Expand Down

This file was deleted.

14 changes: 0 additions & 14 deletions src/main/kotlin/com/dotori/v2/domain/auth/util/AuthConverter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,12 @@ package com.dotori.v2.domain.auth.util
import com.dotori.v2.domain.auth.domain.entity.RefreshToken
import com.dotori.v2.domain.auth.presentation.data.dto.SignInEmailAndPasswordDto
import com.dotori.v2.domain.member.domain.entity.Member
import com.dotori.v2.domain.auth.presentation.data.dto.SignInGAuthDto
import com.dotori.v2.domain.auth.presentation.data.req.SignInEmailAndPasswordReqDto
import com.dotori.v2.domain.auth.presentation.data.req.SignInGAuthReqDto
import com.dotori.v2.domain.member.enums.Role
import gauth.GAuthUserInfo

interface AuthConverter {

fun toDto(signInGAuthReqDto: SignInGAuthReqDto): SignInGAuthDto

fun toDto(signInEmailAndPasswordReqDto: SignInEmailAndPasswordReqDto): SignInEmailAndPasswordDto

fun toEntity(gAuthUserInfo: GAuthUserInfo, role: Role): Member

fun toAdminEntity(gAuthUserInfo: GAuthUserInfo): Member

fun toCouncillorEntity(gAuthUserInfo: GAuthUserInfo): Member

fun toDeveloperEntity(gAuthUserInfo: GAuthUserInfo): Member

fun toEntity(memberInfo: Member, refreshToken: String): RefreshToken

fun toEntity(memberId: Long?, refreshToken: String): RefreshToken
Expand Down
Loading

0 comments on commit b7308d0

Please sign in to comment.