From bbafc91e57e41706db83809d72f711f828bc0585 Mon Sep 17 00:00:00 2001 From: Chanyeong Lim Date: Sun, 22 Sep 2024 23:16:20 +0900 Subject: [PATCH] =?UTF-8?q?=EC=86=8C=EC=85=9C=EB=A1=9C=EA=B7=B8=EC=9D=B8?= =?UTF-8?q?=20=EC=8B=9C=EC=97=90=20=EA=B0=95=EC=9D=98=ED=8F=89=20=EC=9D=B4?= =?UTF-8?q?=EB=A9=94=EC=9D=BC=20=EC=9D=B8=EC=A6=9D=20=EC=97=AC=EB=B6=80=20?= =?UTF-8?q?false=EB=A1=9C=20=EC=84=A4=EC=A0=95,=20=EC=9D=B8=EC=A6=9D?= =?UTF-8?q?=EB=B0=9B=EC=9D=84=EB=95=8C=20=EC=8A=A4=EB=88=84=EB=A9=94?= =?UTF-8?q?=EC=9D=BC=EC=9D=B8=EC=A7=80=20=EC=B2=B4=ED=81=AC=20(#275)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/main/kotlin/users/service/AuthService.kt | 4 ++++ core/src/main/kotlin/users/service/UserService.kt | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/src/main/kotlin/users/service/AuthService.kt b/core/src/main/kotlin/users/service/AuthService.kt index 6380080a..0cc4a091 100644 --- a/core/src/main/kotlin/users/service/AuthService.kt +++ b/core/src/main/kotlin/users/service/AuthService.kt @@ -20,6 +20,8 @@ interface AuthService { fun isValidEmail(email: String): Boolean + fun isValidSnuMail(email: String): Boolean + fun isMatchedPassword( user: User, password: String, @@ -65,6 +67,8 @@ class AuthServiceImpl( override fun isValidEmail(email: String) = email.matches(emailRegex) + override fun isValidSnuMail(email: String) = email.matches(emailRegex) && email.endsWith("@snu.ac.kr") + override fun isMatchedPassword( user: User, password: String, diff --git a/core/src/main/kotlin/users/service/UserService.kt b/core/src/main/kotlin/users/service/UserService.kt index b0f134a4..c28a4dd9 100644 --- a/core/src/main/kotlin/users/service/UserService.kt +++ b/core/src/main/kotlin/users/service/UserService.kt @@ -222,7 +222,7 @@ class UserServiceImpl( log.warn("facebook email is null: $oauth2UserResponse") } - return signup(credential, oauth2UserResponse.email, oauth2UserResponse.isEmailVerified) + return signup(credential, oauth2UserResponse.email, false) } override suspend fun loginGoogle(socialLoginRequest: SocialLoginRequest): LoginResponse { @@ -245,7 +245,7 @@ class UserServiceImpl( val credential = authService.buildGoogleCredential(oauth2UserResponse) - return signup(credential, oauth2UserResponse.email, oauth2UserResponse.isEmailVerified) + return signup(credential, oauth2UserResponse.email, false) } override suspend fun loginKakao(socialLoginRequest: SocialLoginRequest): LoginResponse { @@ -268,7 +268,7 @@ class UserServiceImpl( val credential = authService.buildKakaoCredential(oauth2UserResponse) - return signup(credential, oauth2UserResponse.email, oauth2UserResponse.isEmailVerified) + return signup(credential, oauth2UserResponse.email, false) } private fun getSocialProvider(user: User): SocialProvider { @@ -326,7 +326,7 @@ class UserServiceImpl( email: String, ) { if (user.isEmailVerified == true) throw EmailAlreadyVerifiedException - if (!authService.isValidEmail(email)) throw InvalidEmailException + if (!authService.isValidSnuMail(email)) throw InvalidEmailException if (userRepository.existsByEmailAndIsEmailVerifiedTrueAndActiveTrue(email)) throw DuplicateEmailException(getSocialProvider(user)) val key = VERIFICATION_CODE_PREFIX + user.id val code = (Math.random() * 1000000).toInt().toString().padStart(6, '0')