Merge branch 'backend' into 'BE/userinfo'

# Conflicts:
#   backend/src/main/java/com/edufocus/edufocus/mail/service/MailServiceImpl.java
This commit is contained in:
박정민 2024-08-07 17:46:16 +09:00
commit c517413845
7 changed files with 22 additions and 12 deletions

View File

@ -31,7 +31,7 @@ public class MailController {
@GetMapping("/verify") @GetMapping("/verify")
public ResponseEntity<?> verifyCode(@RequestParam String code, @RequestParam String email) { public ResponseEntity<?> verifyCode(@RequestParam String code, @RequestParam String email) {
if (!mailService.verifyCode(code, email)) { if (!mailService.verifyCode(code, email)) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST); return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} }
return new ResponseEntity<>(HttpStatus.OK); return new ResponseEntity<>(HttpStatus.OK);
} }

View File

@ -1,7 +1,6 @@
package com.edufocus.edufocus.mail.service; package com.edufocus.edufocus.mail.service;
import com.edufocus.edufocus.redis.util.RedisUtil; 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.repository.UserRepository;
import com.edufocus.edufocus.user.model.service.UserService; import com.edufocus.edufocus.user.model.service.UserService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -11,7 +10,6 @@ import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.NoSuchElementException;
import java.util.Random; import java.util.Random;
@Service @Service
@ -31,10 +29,16 @@ public class MailServiceImpl implements MailService {
@Override @Override
public void sendMail(String email) { public void sendMail(String email) {
String code = createRandomCode(); String code = createRandomCode();
redisUtil.setDataExpire(code, email, 60 * 5L);
SimpleMailMessage mail = createEmail(email, "[EDUFOCUS] 비밀번호 찾기 안내", code); if (redisUtil.exists(email)) {
//mailSender.send(mail); 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 @Override
@ -46,6 +50,7 @@ public class MailServiceImpl implements MailService {
private SimpleMailMessage createEmail(String to, String title, String code) { private SimpleMailMessage createEmail(String to, String title, String code) {
SimpleMailMessage message = new SimpleMailMessage(); SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("EDUFOCUS");
message.setTo(to); message.setTo(to);
message.setSubject(title); message.setSubject(title);
message.setText("인증번호 6자리입니다 : " + code); message.setText("인증번호 6자리입니다 : " + code);

View File

@ -33,4 +33,8 @@ public class RedisUtil {
stringRedisTemplate.delete(key); stringRedisTemplate.delete(key);
} }
public boolean exists(String key) {
return stringRedisTemplate.hasKey(key);
}
} }

View File

@ -71,9 +71,9 @@ public class UserController {
// 비밀번호 찾기를 통한 변경 // 비밀번호 찾기를 통한 변경
@PutMapping("/updateforgottenpassword") @PutMapping("/updateforgottenpassword")
public ResponseEntity<String> updatePassword(@RequestParam long userId, public ResponseEntity<String> updatePassword(@RequestParam String email,
@RequestParam String newPassword) { @RequestParam String newPassword) {
userService.changeForgottenPassword(userId, newPassword); userService.changeForgottenPassword(email, newPassword);
return new ResponseEntity<>(HttpStatus.OK); return new ResponseEntity<>(HttpStatus.OK);
} }

View File

@ -28,5 +28,5 @@ public interface UserService {
boolean isEmailExist(String email); boolean isEmailExist(String email);
void changeForgottenPassword(Long id, String newPassword); void changeForgottenPassword(String email, String newPassword);
} }

View File

@ -145,8 +145,8 @@ public class UserServiceImpl implements UserService {
} }
@Override @Override
public void changeForgottenPassword(Long id, String newPassword) { public void changeForgottenPassword(String email, String newPassword) {
User user = userRepository.findById(id).orElse(null); User user = userRepository.findByEmail(email).orElse(null);
if (user == null) { if (user == null) {
throw new UserException("User not found"); throw new UserException("User not found");

View File

@ -39,3 +39,4 @@ spring.mail.properties.mail.smtp.timeout=5000
spring.mail.properties.mail.smtp.starttls.enable=true spring.mail.properties.mail.smtp.starttls.enable=true
spring.data.redis.host=${REDIS_HOST} spring.data.redis.host=${REDIS_HOST}
spring.data.redis.port=${REDIS_PORT} spring.data.redis.port=${REDIS_PORT}
spring.data.redis.password=${REDIS_PASSWORD}