From e9d0db30e52e03863a7ef2140c9e8dd2f5801101 Mon Sep 17 00:00:00 2001 From: kgc91747 Date: Wed, 7 Aug 2024 17:19:07 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9D=B4=EB=A9=94=EC=9D=BC=20=EC=9D=B8?= =?UTF-8?q?=EC=A6=9D=20=EC=BD=94=EB=93=9C=20=EC=9E=AC=EC=9A=94=EC=B2=AD?= =?UTF-8?q?=EC=8B=9C=20=EA=B8=B0=EC=A1=B4=20=EC=BD=94=EB=93=9C=20=EC=82=AD?= =?UTF-8?q?=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");