Skip to content

Commit

Permalink
비밀번호 찾기 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
wpdbsx committed Dec 23, 2023
1 parent b6ad9e8 commit 9daae0b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public ResponseEntity<String> passAnswer(@RequestBody Map<String, Object> obj) {
answerService.passAnswer(qNo, email);
return ResponseEntity.ok(msg);
}

/* 답변하지 않은 질문 삭제 */

@Scheduled(cron = "0 0 0 * * *")
/* 답변하지 않은 질문 삭제 */
public ResponseEntity<String> deleteUnanswer() {
answerService.deleteUnanswer();
String msg = "Unanswer delete successful.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public String sendCodeMessage(String to) throws Exception {
public String sendTemporaryPassword(String to, String temporaryPassword) throws Exception {
MimeMessage message = emailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true, "utf-8");

helper.setTo(to); // 수신자 이메일 주소
helper.setSubject("Goming 비밀번호 찾기"); // 제목

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import java.security.NoSuchAlgorithmException;
import java.util.Random;


import com.bside.BSIDE.user.domain.EmailDto;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -23,7 +26,7 @@
* @일자 2023.05.12.
**/

@CrossOrigin
@CrossOrigin(origins = {"http://localhost:3000","http://www.goming.site"},allowCredentials = "true")
@RestController
@RequestMapping("/password")
public class PasswordResetController {
Expand All @@ -38,28 +41,30 @@ public PasswordResetController(UserService userService, EmailService emailServic

@PostMapping("/password-reset")
@Operation(summary = "임시 비밀번호 발급")
public String resetPassword(@RequestParam("email") String email) {
public String resetPassword(@RequestBody EmailDto param) {
System.out.println("@#테스트");
System.out.println(param.getEmail());
// 1. 이메일 주소의 유효성 검사
if (!isValidEmail(email)) {
if (!isValidEmail(param.getEmail())) {
return "유효하지 않은 이메일 주소입니다.";
}

// 2. 이메일 주소의 존재 여부 확인
UserDto user = userService.getUserByEmail(email);
UserDto user = userService.getUserByEmail(param.getEmail());
if (user == null) {
return "해당 이메일로 가입된 사용자가 없습니다.";
}

// 3. 임시 비밀번호 생성 및 이메일 전송
String temporaryPassword = generateTemporaryPassword();
try {
emailService.sendTemporaryPassword(email,temporaryPassword);
emailService.sendTemporaryPassword(param.getEmail(),temporaryPassword);
} catch (Exception e) {
return "이메일 전송에 실패했습니다.";
}

// 4. 임시 비밀번호 저장
userService.saveTemporaryPassword(email, temporaryPassword);
userService.saveTemporaryPassword(param.getEmail(), temporaryPassword);

return "임시 비밀번호가 이메일로 전송되었습니다.";
}
Expand Down

0 comments on commit 9daae0b

Please sign in to comment.