feat: 이메일 인증 코드 재요청시 기존 코드 삭제 추가
This commit is contained in:
parent
9032a156c4
commit
e9d0db30e5
@ -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);
|
||||
|
@ -33,4 +33,8 @@ public class RedisUtil {
|
||||
stringRedisTemplate.delete(key);
|
||||
}
|
||||
|
||||
public boolean exists(String key) {
|
||||
return stringRedisTemplate.hasKey(key);
|
||||
}
|
||||
|
||||
}
|
@ -71,9 +71,9 @@ public class UserController {
|
||||
|
||||
// 비밀번호 찾기를 통한 변경
|
||||
@PutMapping("/updateforgottenpassword")
|
||||
public ResponseEntity<String> updatePassword(@RequestParam long userId,
|
||||
public ResponseEntity<String> updatePassword(@RequestParam String email,
|
||||
@RequestParam String newPassword) {
|
||||
userService.changeForgottenPassword(userId, newPassword);
|
||||
userService.changeForgottenPassword(email, newPassword);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
@ -28,5 +28,5 @@ public interface UserService {
|
||||
|
||||
boolean isEmailExist(String email);
|
||||
|
||||
void changeForgottenPassword(Long id, String newPassword);
|
||||
void changeForgottenPassword(String email, String newPassword);
|
||||
}
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user