diff --git a/.gitignore b/.gitignore index 36db6e2..c7cff53 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,8 @@ out/ .vscode/ -application.yml \ No newline at end of file +application.yml +build/resources/main/application.yml +build/tmp/compileJava/previous-compilation-data.bin +src/main/resources/application.yml + diff --git a/build.gradle b/build.gradle index ccabee1..538e3ac 100644 --- a/build.gradle +++ b/build.gradle @@ -72,6 +72,9 @@ dependencies { implementation 'org.springframework.cloud:spring-cloud-starter-openfeign:3.1.4' implementation 'org.springframework.boot:spring-boot-starter-data-redis' + implementation 'jakarta.mail:jakarta.mail-api:2.1.2' + implementation 'org.springframework.boot:spring-boot-starter-mail' + } diff --git a/build/resources/main/application.yml b/build/resources/main/application.yml deleted file mode 100644 index a0bfa35..0000000 --- a/build/resources/main/application.yml +++ /dev/null @@ -1,81 +0,0 @@ -server: - port: 8083 - -spring: - application: - name: MemberService - - h2: - console: - enabled: true - -# main: -# allow-bean-definition-overriding: true - - - - datasource: - driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://gwangjang.cnzf7npwk5iz.ap-northeast-2.rds.amazonaws.com:3306/member?autoReconnection=true;sendStringParametersAsUnicode=false?useSSL=false&serverTimezone=Asia/Seoul&characterEncoding=UTF-8 - - hikari: - pool-name: jpa-hikari-pool - maximum-pool-size: 5 - jdbc-url: jdbc:mysql://gwangjang.cnzf7npwk5iz.ap-northeast-2.rds.amazonaws.com:3306/member?autoReconnection=true;sendStringParametersAsUnicode=false?useSSL=false&serverTimezone=Asia/Seoul&characterEncoding=UTF-8 - username: admin - password: helloworld - driver-class-name: com.mysql.cj.jdbc.Driver - data-source-properties: - rewriteBatchedStatements: true - - jpa: - database: mysql - hibernate: # hibernate 사용 설정 - - # 애플리케이션 실행 시점에 테이블을 다 지우고, 내가 가진 entity 정보를 보고 다시 테이블 자동 생성 - ddl-auto: update - generate-ddl: true - properties: # property 사용 설정 - hibernate: # hibernate property 설정 - format_sql: true - use_sql_comments: true - show-sql: false - open-in-view: true - - data: - redis: - port: 6379 - host: gwangjang.36k9ap.ng.0001.apn2.cache.amazonaws.com - - -eureka: - client: - register-with-eureka: true - fetch-registry: true - service-url: - defaultZone: http://localhost:8761/eureka - instance: - instance-id: ${spring.application.name}:${spring.application.instance_id:${random.value}} - -logging: - level: - com.example.memberservice: DEBUG - -kakao: - client: - id: c1b38a40e2bba2be6a4fd18a38179d5f - redirect-uri: http://localhost:8888/member/auth - token-uri: https://kauth.kakao.com/oauth/token - secret: ZkcLZF7NVt2h45ip2zXxj6QaRJisKeSu - -app-id: #수정해야함 - kakao: 983681 - google: --- - -jwt: - header: Authorization - secret: 2a10q42lY7Y18xqrFt1qbODZIO4OMTeOxnrCe7tF3n9bazJinVE7VH5Pi - access-token-period: 1800000000000000000 # 30분 (30분 * 60초 * 1000밀리초) - refresh-token-period: 1209600000000 # 14일 (14일 * 24시간 * 60분 * 60초 * 1000밀리초) - reissue-token-period: 2592000000000 # 3일 (3일 * 24시간 * 60분 * 60초 * 1000밀리초) - diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin deleted file mode 100644 index 3005fd4..0000000 Binary files a/build/tmp/compileJava/previous-compilation-data.bin and /dev/null differ diff --git a/src/main/java/gwangjang/server/domain/auth/application/dto/request/CheckEmailRequest.java b/src/main/java/gwangjang/server/domain/auth/application/dto/request/CheckEmailRequest.java new file mode 100644 index 0000000..8d6aad2 --- /dev/null +++ b/src/main/java/gwangjang/server/domain/auth/application/dto/request/CheckEmailRequest.java @@ -0,0 +1,13 @@ +package gwangjang.server.domain.auth.application.dto.request; + +import lombok.*; + +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Getter +@Setter +public class CheckEmailRequest { + String email; + String code; +} diff --git a/src/main/java/gwangjang/server/domain/auth/application/dto/request/LocalSignInRequest.java b/src/main/java/gwangjang/server/domain/auth/application/dto/request/LocalSignInRequest.java index 8f47dd9..3b6a5d2 100644 --- a/src/main/java/gwangjang/server/domain/auth/application/dto/request/LocalSignInRequest.java +++ b/src/main/java/gwangjang/server/domain/auth/application/dto/request/LocalSignInRequest.java @@ -1,11 +1,16 @@ package gwangjang.server.domain.auth.application.dto.request; +import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; +@Setter @Getter @NoArgsConstructor +@AllArgsConstructor public class LocalSignInRequest { private String id; private String pw; + } diff --git a/src/main/java/gwangjang/server/domain/auth/application/dto/request/LocalSignUpRequest.java b/src/main/java/gwangjang/server/domain/auth/application/dto/request/LocalSignUpRequest.java index 1d8c2ab..f02b530 100644 --- a/src/main/java/gwangjang/server/domain/auth/application/dto/request/LocalSignUpRequest.java +++ b/src/main/java/gwangjang/server/domain/auth/application/dto/request/LocalSignUpRequest.java @@ -2,11 +2,10 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; -@Data +@Getter +@Setter @NoArgsConstructor @AllArgsConstructor public class LocalSignUpRequest { diff --git a/src/main/java/gwangjang/server/domain/auth/application/dto/request/SignInRequest.java b/src/main/java/gwangjang/server/domain/auth/application/dto/request/SignInRequest.java index 7e4d421..1576f14 100644 --- a/src/main/java/gwangjang/server/domain/auth/application/dto/request/SignInRequest.java +++ b/src/main/java/gwangjang/server/domain/auth/application/dto/request/SignInRequest.java @@ -1,16 +1,14 @@ package gwangjang.server.domain.auth.application.dto.request; import jakarta.validation.constraints.NotBlank; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; @Builder @AllArgsConstructor @NoArgsConstructor @Getter +@Setter public class SignInRequest { @NotBlank(message="token 을 입력해주세요.") private String token; diff --git a/src/main/java/gwangjang/server/domain/auth/application/dto/request/SignUpRequest.java b/src/main/java/gwangjang/server/domain/auth/application/dto/request/SignUpRequest.java index 73ee34f..f7e6730 100644 --- a/src/main/java/gwangjang/server/domain/auth/application/dto/request/SignUpRequest.java +++ b/src/main/java/gwangjang/server/domain/auth/application/dto/request/SignUpRequest.java @@ -3,16 +3,14 @@ import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; @Builder @AllArgsConstructor @NoArgsConstructor @Getter +@Setter public class SignUpRequest { diff --git a/src/main/java/gwangjang/server/domain/auth/application/dto/request/TestRequest.java b/src/main/java/gwangjang/server/domain/auth/application/dto/request/TestRequest.java index 3834b45..d912369 100644 --- a/src/main/java/gwangjang/server/domain/auth/application/dto/request/TestRequest.java +++ b/src/main/java/gwangjang/server/domain/auth/application/dto/request/TestRequest.java @@ -1,14 +1,12 @@ package gwangjang.server.domain.auth.application.dto.request; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; @Builder @AllArgsConstructor @NoArgsConstructor @Getter +@Setter public class TestRequest { private String socialId; diff --git a/src/main/java/gwangjang/server/domain/auth/application/dto/response/CheckEmailResponse.java b/src/main/java/gwangjang/server/domain/auth/application/dto/response/CheckEmailResponse.java new file mode 100644 index 0000000..b8dbe5d --- /dev/null +++ b/src/main/java/gwangjang/server/domain/auth/application/dto/response/CheckEmailResponse.java @@ -0,0 +1,14 @@ +package gwangjang.server.domain.auth.application.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Getter +public class CheckEmailResponse { + private Boolean isChecked; +} diff --git a/src/main/java/gwangjang/server/domain/auth/application/service/CheckEmailUserCase.java b/src/main/java/gwangjang/server/domain/auth/application/service/CheckEmailUserCase.java new file mode 100644 index 0000000..cd12426 --- /dev/null +++ b/src/main/java/gwangjang/server/domain/auth/application/service/CheckEmailUserCase.java @@ -0,0 +1,77 @@ +package gwangjang.server.domain.auth.application.service; + +import gwangjang.server.domain.auth.application.dto.request.CheckEmailRequest; +import gwangjang.server.domain.auth.application.dto.response.CheckEmailResponse; +import gwangjang.server.domain.auth.application.dto.response.CheckNicknameResponse; +import gwangjang.server.domain.auth.exception.EmailAuthException; +import gwangjang.server.domain.member.domain.service.MemberCheckService; +import gwangjang.server.global.security.jwt.redis.RedisUtil; +import gwangjang.server.global.utils.EmailUtil; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.mail.SimpleMailMessage; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.stereotype.Service; + +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.util.Random; + +@Slf4j +@Service +@Transactional +@RequiredArgsConstructor +public class CheckEmailUserCase { + + private final MemberCheckService memberCheckService; + + private final EmailUtil emailUtil; + private final RedisUtil redisUtil; + + private static final String AUTH_CODE_PREFIX = "AuthCode "; + + + public CheckEmailResponse requestEmail(String email){ + boolean isDuplicated=memberCheckService.checkEmail(email); + + if (!isDuplicated) { + log.info("createCode Before"); + String code = createCode(); + log.info("sendEmail Before"); + emailUtil.sendEmail(email,"광장 이메일 인증","인증번호 : "+code); + redisUtil.save(code,email); + log.info("code"+code); + } + return new CheckEmailResponse(isDuplicated); + } + + + public CheckEmailResponse checkEmailAuth(CheckEmailRequest checkEmailRequest) { + + return verifiedCode(checkEmailRequest.getEmail(), checkEmailRequest.getCode()); + } + + private String createCode() { + int lenth = 6; + try { + Random random = SecureRandom.getInstanceStrong(); + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < lenth; i++) { + builder.append(random.nextInt(10)); + } + return builder.toString(); + } catch (NoSuchAlgorithmException e) { + log.debug("MemberService.createCode() exception occur"); + throw new EmailAuthException(); + } + } + + public CheckEmailResponse verifiedCode(String email, String authCode) { + String redisAuthCode = redisUtil.getEmailValues (email).get().toString(); + log.info(String.valueOf(redisUtil.checkExistsValue(redisAuthCode))+"checkExistsValue"); + log.info(String.valueOf(redisAuthCode.equals(authCode))+"redisauthCodeEquals"); + boolean authResult = redisUtil.checkExistsValue(redisAuthCode) && redisAuthCode.equals(authCode); + return new CheckEmailResponse(authResult); + } +} diff --git a/src/main/java/gwangjang/server/domain/auth/application/service/SignUpUserCase.java b/src/main/java/gwangjang/server/domain/auth/application/service/SignUpUserCase.java index fd4d4bc..edcaf23 100644 --- a/src/main/java/gwangjang/server/domain/auth/application/service/SignUpUserCase.java +++ b/src/main/java/gwangjang/server/domain/auth/application/service/SignUpUserCase.java @@ -74,4 +74,5 @@ public SignInResponse localSignUp(LocalSignUpRequest localSignUpRequest) { return SignInResponse.from(tokenResponse, member.getRegistrationStatus()); } + } diff --git a/src/main/java/gwangjang/server/domain/auth/exception/EmailAuthException.java b/src/main/java/gwangjang/server/domain/auth/exception/EmailAuthException.java new file mode 100644 index 0000000..54ebf65 --- /dev/null +++ b/src/main/java/gwangjang/server/domain/auth/exception/EmailAuthException.java @@ -0,0 +1,12 @@ +package gwangjang.server.domain.auth.exception; + +import gwangjang.server.global.response.ErrorCode; +import org.springframework.http.HttpStatus; + +public class EmailAuthException extends AuthException { + public EmailAuthException() { + super(ErrorCode.EMAIL_AUTH_ERROR, + HttpStatus.UNAUTHORIZED); + } +} + diff --git a/src/main/java/gwangjang/server/domain/auth/presentation/AuthController.java b/src/main/java/gwangjang/server/domain/auth/presentation/AuthController.java index 0262c61..6a57b77 100644 --- a/src/main/java/gwangjang/server/domain/auth/presentation/AuthController.java +++ b/src/main/java/gwangjang/server/domain/auth/presentation/AuthController.java @@ -1,19 +1,18 @@ package gwangjang.server.domain.auth.presentation; import gwangjang.server.domain.auth.application.dto.request.*; +import gwangjang.server.domain.auth.application.dto.response.CheckEmailResponse; import gwangjang.server.domain.auth.application.dto.response.CheckNicknameResponse; import gwangjang.server.domain.auth.application.dto.response.ReissueTokenResponse; import gwangjang.server.domain.auth.application.dto.response.SignInResponse; -import gwangjang.server.domain.auth.application.service.CheckNicknameUserCase; -import gwangjang.server.domain.auth.application.service.ReissueTokenUserCase; -import gwangjang.server.domain.auth.application.service.SignInUserCase; -import gwangjang.server.domain.auth.application.service.SignUpUserCase; +import gwangjang.server.domain.auth.application.service.*; import gwangjang.server.domain.auth.application.service.kakao.KakaoTokenUserCase; import gwangjang.server.global.response.SuccessResponse; import gwangjang.server.global.security.dto.User; import jakarta.validation.Valid; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.security.core.parameters.P; @@ -24,7 +23,8 @@ @RestController @AllArgsConstructor -@RequestMapping("/auth") +@CrossOrigin(origins = "*") +@RequestMapping(value = "/auth",consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) @Slf4j public class AuthController { @@ -35,18 +35,18 @@ public class AuthController { private final ReissueTokenUserCase reissueTokenService; private final CheckNicknameUserCase checkNicknameService; private final KakaoTokenUserCase kakaoTokenUserCase; + private final CheckEmailUserCase checkEmailUserCase; @PostMapping("/signIn") - public ResponseEntity> signIn( - @Valid @RequestBody LocalSignInRequest localSignInRequest) { + public ResponseEntity> signIn(LocalSignInRequest localSignInRequest) { return ResponseEntity.ok(SuccessResponse.create(SIGN_IN_SUCCESS.getMessage(), this.authService.localSignIn(localSignInRequest))); } @PostMapping("/signIn/{provider}") public ResponseEntity> socialSignIn(@PathVariable String provider, - @Valid @RequestBody SignInRequest signInRequest) { + SignInRequest signInRequest) { return ResponseEntity.ok(SuccessResponse.create(SIGN_IN_SUCCESS.getMessage(), this.authService.signIn(signInRequest.getToken(), provider))); } @@ -54,13 +54,13 @@ public ResponseEntity> socialSignIn(@PathVariabl @PutMapping("/signUp/{provider}") public ResponseEntity> socialSignUp(@PathVariable String provider, @RequestHeader(value = "Authorization") String token, - @Valid @RequestBody SignUpRequest signUpRequest) { + SignUpRequest signUpRequest) { token = (token != null && token.startsWith("Bearer ")) ? token.substring(7) : token; return ResponseEntity.ok(SuccessResponse.create(SIGN_UP_SUCCESS.getMessage(), this.signUpService.signUp(token, signUpRequest))); } @PostMapping("/signUp") - public ResponseEntity> signUp(@Valid @RequestBody LocalSignUpRequest signUpRequest) { + public ResponseEntity> signUp(LocalSignUpRequest signUpRequest) { return ResponseEntity.ok(SuccessResponse.create(SIGN_UP_SUCCESS.getMessage(), this.signUpService.localSignUp(signUpRequest))); } @@ -79,13 +79,12 @@ public ResponseEntity> checkNickname(@Pat @PostMapping("/test/{provider}") public ResponseEntity> testLogin(@PathVariable String provider, - @RequestBody TestRequest testRequest){ + TestRequest testRequest){ return ResponseEntity.ok(SuccessResponse.create(SIGN_IN_SUCCESS.getMessage(), this.authService.testSignIn(testRequest.getSocialId(),provider))); } @PostMapping("/test/hi") - public ResponseEntity> test(@AuthenticationPrincipal User user - ){ + public ResponseEntity> test(@AuthenticationPrincipal User user){ log.info("/test/hi -> start "); log.info(user.getEmail()); @@ -98,5 +97,15 @@ public ResponseEntity> kakaoCallBack(@RequestParam Strin return ResponseEntity.ok(SuccessResponse.create(KAKAO_CALL_BACK_SUCCESS.getMessage(),kakaoTokenUserCase.getAccessToken(code).getAccess_token())); } + @PostMapping("/email/{email}") + public ResponseEntity> sendEmailAuth(@PathVariable String email){ + return ResponseEntity.ok(SuccessResponse.create(CHECK_EMAIL_SUCCESS.getMessage(),checkEmailUserCase.requestEmail(email))); + } + + @PostMapping("/email") + public ResponseEntity> checkEmailAuth(CheckEmailRequest checkEmailRequest){ + return ResponseEntity.ok(SuccessResponse.create(CHECK_EMAIL_AUTH_SUCCESS.getMessage(),checkEmailUserCase.checkEmailAuth(checkEmailRequest))); + } + } \ No newline at end of file diff --git a/src/main/java/gwangjang/server/domain/auth/presentation/AuthRedirectController.java b/src/main/java/gwangjang/server/domain/auth/presentation/AuthRedirectController.java deleted file mode 100644 index aee00e9..0000000 --- a/src/main/java/gwangjang/server/domain/auth/presentation/AuthRedirectController.java +++ /dev/null @@ -1,28 +0,0 @@ -package gwangjang.server.domain.auth.presentation; - -//@RestController -//@AllArgsConstructor -//public class AuthRedirectController { -// @Value("${android.package}") -// private String androidPackage; -// -// @Value("${android.scheme}") -// private String androidScheme; -// -// /** -// * 애플 로그인 리다이렉트 -// */ -// @CrossOrigin(origins = "https://appleid.apple.com") -// @PostMapping(value = "/auth/apple/callback", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) -// public ResponseEntity userLoginAppleCallback(@RequestParam("code") String code, -// @RequestParam("id_token") String idToken) throws URISyntaxException { -// // Deep link 생성 -// String callback = String.format("intent://callback?code=%s&id_token=%s#Intent;package=%s;scheme=%s;end", -// code, idToken, androidPackage, androidScheme); -// -// // 리다이렉트 -// HttpHeaders httpHeaders = new HttpHeaders(); -// httpHeaders.setLocation(new URI(callback)); -// return new ResponseEntity<>(httpHeaders, HttpStatus.TEMPORARY_REDIRECT); -// } -//} diff --git a/src/main/java/gwangjang/server/domain/auth/presentation/constant/AuthResponseMessage.java b/src/main/java/gwangjang/server/domain/auth/presentation/constant/AuthResponseMessage.java index 6c999db..3bbd889 100644 --- a/src/main/java/gwangjang/server/domain/auth/presentation/constant/AuthResponseMessage.java +++ b/src/main/java/gwangjang/server/domain/auth/presentation/constant/AuthResponseMessage.java @@ -10,6 +10,8 @@ public enum AuthResponseMessage { SIGN_UP_SUCCESS("회원 가입을 했습니다"), REISSUE_TOKEN_SUCCESS("토큰을 재발급했습니다"), CHECK_NICKNAME_SUCCESS("닉네임 중복검사를 했습니다"), + CHECK_EMAIL_SUCCESS("이메일 인증을 요청 했습니다"), + CHECK_EMAIL_AUTH_SUCCESS("이메일 인증을 성공 했습니다"), KAKAO_CALL_BACK_SUCCESS("카카오 리다이렉트를 완료 했습니다"); private final String message; } diff --git a/src/main/java/gwangjang/server/domain/member/domain/service/MemberCheckService.java b/src/main/java/gwangjang/server/domain/member/domain/service/MemberCheckService.java index 58db3b9..7476500 100644 --- a/src/main/java/gwangjang/server/domain/member/domain/service/MemberCheckService.java +++ b/src/main/java/gwangjang/server/domain/member/domain/service/MemberCheckService.java @@ -4,8 +4,9 @@ import gwangjang.server.global.annotation.DomainService; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; - +@Slf4j @DomainService @Transactional @RequiredArgsConstructor @@ -15,6 +16,7 @@ public boolean checkNickname(String nickname) { return memberRepository.checkNickname(nickname); } public boolean checkEmail(String email) { + log.info("checkEmail done"); return memberRepository.checkEmail(email); } diff --git a/src/main/java/gwangjang/server/global/config/EmailConfig.java b/src/main/java/gwangjang/server/global/config/EmailConfig.java new file mode 100644 index 0000000..f7cb38e --- /dev/null +++ b/src/main/java/gwangjang/server/global/config/EmailConfig.java @@ -0,0 +1,68 @@ +package gwangjang.server.global.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.mail.javamail.JavaMailSenderImpl; + +import java.util.Properties; + +@Configuration +public class EmailConfig { + + @Value("${spring.mail.host}") + private String host; + + @Value("${spring.mail.port}") + private int port; + + @Value("${spring.mail.username}") + private String username; + + @Value("${spring.mail.password}") + private String password; + + @Value("${spring.mail.properties.mail.smtp.auth}") + private boolean auth; + + @Value("${spring.mail.properties.mail.smtp.starttls.enable}") + private boolean starttlsEnable; + + @Value("${spring.mail.properties.mail.smtp.starttls.required}") + private boolean starttlsRequired; + + @Value("${spring.mail.properties.mail.smtp.connectiontimeout}") + private int connectionTimeout; + + @Value("${spring.mail.properties.mail.smtp.timeout}") + private int timeout; + + @Value("${spring.mail.properties.mail.smtp.writetimeout}") + private int writeTimeout; + + @Bean + public JavaMailSender javaMailSender() { + JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); + mailSender.setHost(host); + mailSender.setPort(port); + mailSender.setUsername(username); + mailSender.setPassword(password); + mailSender.setDefaultEncoding("UTF-8"); + mailSender.setJavaMailProperties(getMailProperties()); + + return mailSender; + } + + private Properties getMailProperties() { + Properties properties = new Properties(); + properties.put("mail.smtp.auth", auth); + properties.put("mail.smtp.starttls.enable", starttlsEnable); + properties.put("mail.smtp.starttls.required", starttlsRequired); + properties.put("mail.smtp.connectiontimeout", connectionTimeout); + properties.put("mail.smtp.timeout", timeout); + properties.put("mail.smtp.writetimeout", writeTimeout); + + return properties; + } +} diff --git a/src/main/java/gwangjang/server/global/response/ErrorCode.java b/src/main/java/gwangjang/server/global/response/ErrorCode.java index db89ec2..d7eb3be 100644 --- a/src/main/java/gwangjang/server/global/response/ErrorCode.java +++ b/src/main/java/gwangjang/server/global/response/ErrorCode.java @@ -23,7 +23,9 @@ public enum ErrorCode { TOKEN_INVALID_ERROR("AU0002", "입력 토큰이 유효하지 않습니다."), APPID_INVALID_ERROR("AU0003", "appId가 유효하지 않습니다"), NICKNAME_DUPLICATION_ERROR("AU0004", "닉네임이 중복됩니다."), - EMAIL_DUPLICATION_ERROR("AU0005", "닉네임이 중복됩니다."), + EMAIL_DUPLICATION_ERROR("AU0005", "이메일이 중복됩니다."), + EMAIL_AUTH_ERROR("AU0005", "이메일이 중복됩니다."), + NOT_FOUND_BY_LOGIN_ID_ERROR("L001","해당 id인 유저가 존재하지 않습니다"), INCORRECT_PASSWORD("L002","비밀번호가 틀렸습니다"); diff --git a/src/main/java/gwangjang/server/global/security/SecurityConfig.java b/src/main/java/gwangjang/server/global/security/SecurityConfig.java index fc62f32..8c08c89 100644 --- a/src/main/java/gwangjang/server/global/security/SecurityConfig.java +++ b/src/main/java/gwangjang/server/global/security/SecurityConfig.java @@ -70,18 +70,18 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { return http.build(); } - @Bean - public CorsConfigurationSource corsConfigurationSource() { - CorsConfiguration configuration = new CorsConfiguration(); - - configuration.addAllowedOriginPattern("*"); - configuration.addAllowedHeader("*"); - configuration.addAllowedMethod("*"); - configuration.setAllowCredentials(false); - - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - source.registerCorsConfiguration("/**", configuration); - return source; - } +// @Bean +// public CorsConfigurationSource corsConfigurationSource() { +// CorsConfiguration configuration = new CorsConfiguration(); +// +// configuration.addAllowedOriginPattern("*"); +// configuration.addAllowedHeader("*"); +// configuration.addAllowedMethod("*"); +// configuration.setAllowCredentials(false); +// +// UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); +// source.registerCorsConfiguration("/**", configuration); +// return source; +// } } \ No newline at end of file diff --git a/src/main/java/gwangjang/server/global/security/jwt/redis/RedisUtil.java b/src/main/java/gwangjang/server/global/security/jwt/redis/RedisUtil.java index 52969f7..31d21f3 100644 --- a/src/main/java/gwangjang/server/global/security/jwt/redis/RedisUtil.java +++ b/src/main/java/gwangjang/server/global/security/jwt/redis/RedisUtil.java @@ -1,5 +1,6 @@ package gwangjang.server.global.security.jwt.redis; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Repository; @@ -7,6 +8,7 @@ import java.util.Optional; import java.util.concurrent.TimeUnit; +@Slf4j @Repository public class RedisUtil { @@ -20,6 +22,7 @@ public RedisUtil(final RedisTemplate redisTemplate) { } public void save(String refreshToken, String socialId) { + log.info("save redis"); //동일한 key 값으로 저장하면 value값 updat됨 redisTemplate.opsForValue().set(socialId, refreshToken, refreshTokenValidityTime, TimeUnit.SECONDS); } @@ -32,4 +35,18 @@ public Optional findById(final String socialId) { String refreshToken = (String) redisTemplate.opsForValue().get(socialId); return Optional.ofNullable(refreshToken); } + + public Optional getEmailValues(String value) { + String check = (String) redisTemplate.opsForValue().get(value); + log.info("chek"+check); + return Optional.ofNullable(check); + } + + public boolean checkExistsValue(String key) { + String value = (String) redisTemplate.opsForValue().get(key); + log.info("value"+value); + return value == null; + } + + } diff --git a/src/main/java/gwangjang/server/global/security/jwt/service/TokenUtil.java b/src/main/java/gwangjang/server/global/security/jwt/service/TokenUtil.java index 58cd347..7e31082 100644 --- a/src/main/java/gwangjang/server/global/security/jwt/service/TokenUtil.java +++ b/src/main/java/gwangjang/server/global/security/jwt/service/TokenUtil.java @@ -107,7 +107,7 @@ public boolean verifyToken(String token) { //refresh token 관련 public void storeRefreshToken(String socialId, TokenInfoResponse token) { -// redisUtil.save(token.getRefreshToken(), socialId); + redisUtil.save(token.getRefreshToken(), socialId); } public TokenInfoResponse tokenReissue(String token) { diff --git a/src/main/java/gwangjang/server/global/utils/EmailUtil.java b/src/main/java/gwangjang/server/global/utils/EmailUtil.java new file mode 100644 index 0000000..1178622 --- /dev/null +++ b/src/main/java/gwangjang/server/global/utils/EmailUtil.java @@ -0,0 +1,50 @@ +package gwangjang.server.global.utils; + +import gwangjang.server.domain.auth.exception.EmailAuthException; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.mail.SimpleMailMessage; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; + +@Slf4j +@Transactional +@RequiredArgsConstructor +@Component +public class EmailUtil { + + private final JavaMailSender emailSender; + + public void sendEmail(String toEmail, + String title, + String text) { + SimpleMailMessage emailForm = createEmailForm(toEmail, title, text); +// try { + log.info("email send before"); + emailSender.send(emailForm); + log.info("email send after"); + +// } catch (RuntimeException e) { + log.info("MailService.sendEmail exception occur toEmail: {}, " + + "title: {}, text: {}", toEmail, title, text); +// throw new EmailAuthException(); +// } + } + + // 발신할 이메일 데이터 세팅 + private SimpleMailMessage createEmailForm(String toEmail, + String title, + String text) { + SimpleMailMessage message = new SimpleMailMessage(); + message.setTo(toEmail); + message.setSubject(title); + message.setText(text); + + return message; + } + + +} + diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml deleted file mode 100644 index a0bfa35..0000000 --- a/src/main/resources/application.yml +++ /dev/null @@ -1,81 +0,0 @@ -server: - port: 8083 - -spring: - application: - name: MemberService - - h2: - console: - enabled: true - -# main: -# allow-bean-definition-overriding: true - - - - datasource: - driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://gwangjang.cnzf7npwk5iz.ap-northeast-2.rds.amazonaws.com:3306/member?autoReconnection=true;sendStringParametersAsUnicode=false?useSSL=false&serverTimezone=Asia/Seoul&characterEncoding=UTF-8 - - hikari: - pool-name: jpa-hikari-pool - maximum-pool-size: 5 - jdbc-url: jdbc:mysql://gwangjang.cnzf7npwk5iz.ap-northeast-2.rds.amazonaws.com:3306/member?autoReconnection=true;sendStringParametersAsUnicode=false?useSSL=false&serverTimezone=Asia/Seoul&characterEncoding=UTF-8 - username: admin - password: helloworld - driver-class-name: com.mysql.cj.jdbc.Driver - data-source-properties: - rewriteBatchedStatements: true - - jpa: - database: mysql - hibernate: # hibernate 사용 설정 - - # 애플리케이션 실행 시점에 테이블을 다 지우고, 내가 가진 entity 정보를 보고 다시 테이블 자동 생성 - ddl-auto: update - generate-ddl: true - properties: # property 사용 설정 - hibernate: # hibernate property 설정 - format_sql: true - use_sql_comments: true - show-sql: false - open-in-view: true - - data: - redis: - port: 6379 - host: gwangjang.36k9ap.ng.0001.apn2.cache.amazonaws.com - - -eureka: - client: - register-with-eureka: true - fetch-registry: true - service-url: - defaultZone: http://localhost:8761/eureka - instance: - instance-id: ${spring.application.name}:${spring.application.instance_id:${random.value}} - -logging: - level: - com.example.memberservice: DEBUG - -kakao: - client: - id: c1b38a40e2bba2be6a4fd18a38179d5f - redirect-uri: http://localhost:8888/member/auth - token-uri: https://kauth.kakao.com/oauth/token - secret: ZkcLZF7NVt2h45ip2zXxj6QaRJisKeSu - -app-id: #수정해야함 - kakao: 983681 - google: --- - -jwt: - header: Authorization - secret: 2a10q42lY7Y18xqrFt1qbODZIO4OMTeOxnrCe7tF3n9bazJinVE7VH5Pi - access-token-period: 1800000000000000000 # 30분 (30분 * 60초 * 1000밀리초) - refresh-token-period: 1209600000000 # 14일 (14일 * 24시간 * 60분 * 60초 * 1000밀리초) - reissue-token-period: 2592000000000 # 3일 (3일 * 24시간 * 60분 * 60초 * 1000밀리초) -