From 9032a156c4553ff7571cd80d713722eb194e8c1f Mon Sep 17 00:00:00 2001 From: kgc91747 Date: Wed, 7 Aug 2024 14:23:44 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20redis=20password=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/resources/application.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index 483ec8b..d46f4df 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -38,4 +38,5 @@ spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.timeout=5000 spring.mail.properties.mail.smtp.starttls.enable=true spring.data.redis.host=${REDIS_HOST} -spring.data.redis.port=${REDIS_PORT} \ No newline at end of file +spring.data.redis.port=${REDIS_PORT} +spring.data.redis.password=${REDIS_PASSWORD} \ No newline at end of file From e9d0db30e52e03863a7ef2140c9e8dd2f5801101 Mon Sep 17 00:00:00 2001 From: kgc91747 Date: Wed, 7 Aug 2024 17:19:07 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=EC=9D=B4=EB=A9=94=EC=9D=BC=20?= =?UTF-8?q?=EC=9D=B8=EC=A6=9D=20=EC=BD=94=EB=93=9C=20=EC=9E=AC=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=EC=8B=9C=20=EA=B8=B0=EC=A1=B4=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edufocus/mail/service/MailServiceImpl.java | 15 ++++++++++----- .../edufocus/edufocus/redis/util/RedisUtil.java | 4 ++++ .../edufocus/user/controller/UserController.java | 4 ++-- .../edufocus/user/model/service/UserService.java | 2 +- .../user/model/service/UserServiceImpl.java | 4 ++-- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/backend/src/main/java/com/edufocus/edufocus/mail/service/MailServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/mail/service/MailServiceImpl.java index 20859de..f5c08b6 100644 --- a/backend/src/main/java/com/edufocus/edufocus/mail/service/MailServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/mail/service/MailServiceImpl.java @@ -1,7 +1,6 @@ package com.edufocus.edufocus.mail.service; import com.edufocus.edufocus.redis.util.RedisUtil; -import com.edufocus.edufocus.user.model.entity.vo.User; import com.edufocus.edufocus.user.model.repository.UserRepository; import com.edufocus.edufocus.user.model.service.UserService; import lombok.RequiredArgsConstructor; @@ -11,7 +10,6 @@ import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.stereotype.Service; -import java.util.NoSuchElementException; import java.util.Random; @Service @@ -31,10 +29,16 @@ public class MailServiceImpl implements MailService { @Override public void sendMail(String email) { String code = createRandomCode(); - redisUtil.setDataExpire(code, email, 60 * 5L); - SimpleMailMessage mail = createEmail(email, "[EDUFOCUS] 비밀번호 찾기 안내", code); - mailSender.send(mail); + if (redisUtil.exists(email)) { + redisUtil.deleteData(redisUtil.getData(email)); + } + + redisUtil.setDataExpire(code, email, 60 * 5L); + redisUtil.setDataExpire(email, code, 60 * 5L); + +// SimpleMailMessage mail = createEmail(email, "[EDUFOCUS] 비밀번호 찾기 안내", code); +// mailSender.send(mail); } @Override @@ -46,6 +50,7 @@ public class MailServiceImpl implements MailService { private SimpleMailMessage createEmail(String to, String title, String code) { SimpleMailMessage message = new SimpleMailMessage(); + message.setFrom("EDUFOCUS"); message.setTo(to); message.setSubject(title); message.setText("인증번호 6자리입니다 : " + code); diff --git a/backend/src/main/java/com/edufocus/edufocus/redis/util/RedisUtil.java b/backend/src/main/java/com/edufocus/edufocus/redis/util/RedisUtil.java index ad9bf09..d13b40f 100644 --- a/backend/src/main/java/com/edufocus/edufocus/redis/util/RedisUtil.java +++ b/backend/src/main/java/com/edufocus/edufocus/redis/util/RedisUtil.java @@ -33,4 +33,8 @@ public class RedisUtil { stringRedisTemplate.delete(key); } + public boolean exists(String key) { + return stringRedisTemplate.hasKey(key); + } + } \ No newline at end of file diff --git a/backend/src/main/java/com/edufocus/edufocus/user/controller/UserController.java b/backend/src/main/java/com/edufocus/edufocus/user/controller/UserController.java index 791fa4b..bb3818f 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/controller/UserController.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/controller/UserController.java @@ -71,9 +71,9 @@ public class UserController { // 비밀번호 찾기를 통한 변경 @PutMapping("/updateforgottenpassword") - public ResponseEntity updatePassword(@RequestParam long userId, + public ResponseEntity updatePassword(@RequestParam String email, @RequestParam String newPassword) { - userService.changeForgottenPassword(userId, newPassword); + userService.changeForgottenPassword(email, newPassword); return new ResponseEntity<>(HttpStatus.OK); } diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserService.java b/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserService.java index 0737045..9a4b9ef 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserService.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserService.java @@ -28,5 +28,5 @@ public interface UserService { boolean isEmailExist(String email); - void changeForgottenPassword(Long id, String newPassword); + void changeForgottenPassword(String email, String newPassword); } diff --git a/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java index c50e1c9..d211644 100644 --- a/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/user/model/service/UserServiceImpl.java @@ -143,8 +143,8 @@ public class UserServiceImpl implements UserService { } @Override - public void changeForgottenPassword(Long id, String newPassword) { - User user = userRepository.findById(id).orElse(null); + public void changeForgottenPassword(String email, String newPassword) { + User user = userRepository.findByEmail(email).orElse(null); if (user == null) { throw new UserException("User not found"); From 78cfed17e7e62b88a5254310fbf6c361231e1adc Mon Sep 17 00:00:00 2001 From: kgc91747 Date: Wed, 7 Aug 2024 17:27:46 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=EC=9D=B4=EB=A9=94=EC=9D=BC=20?= =?UTF-8?q?=EC=9D=B8=EC=A6=9D=20=EC=8B=A4=ED=8C=A8=EC=8B=9C=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=EA=B0=92=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/edufocus/edufocus/mail/controller/MailController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/edufocus/edufocus/mail/controller/MailController.java b/backend/src/main/java/com/edufocus/edufocus/mail/controller/MailController.java index ee2c38d..bc6be99 100644 --- a/backend/src/main/java/com/edufocus/edufocus/mail/controller/MailController.java +++ b/backend/src/main/java/com/edufocus/edufocus/mail/controller/MailController.java @@ -31,7 +31,7 @@ public class MailController { @GetMapping("/verify") public ResponseEntity verifyCode(@RequestParam String code, @RequestParam String email) { if (!mailService.verifyCode(code, email)) { - return new ResponseEntity<>(HttpStatus.BAD_REQUEST); + return new ResponseEntity<>(HttpStatus.NOT_FOUND); } return new ResponseEntity<>(HttpStatus.OK); }