Merge branch 'backend' into 'BE/userinfo'
# Conflicts: # backend/src/main/java/com/edufocus/edufocus/mail/service/MailServiceImpl.java
This commit is contained in:
commit
c517413845
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -145,8 +145,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");
|
||||
|
@ -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}
|
||||
spring.data.redis.port=${REDIS_PORT}
|
||||
spring.data.redis.password=${REDIS_PASSWORD}
|
Loading…
Reference in New Issue
Block a user