-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
698 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,13 @@ | |
import java.text.DateFormat; | ||
import java.util.Date; | ||
import java.util.Locale; | ||
import java.util.Properties; | ||
|
||
import javax.mail.Message; | ||
import javax.mail.PasswordAuthentication; | ||
import javax.mail.Session; | ||
import javax.mail.Transport; | ||
import javax.mail.internet.MimeMessage; | ||
import javax.servlet.http.HttpSession; | ||
|
||
import org.slf4j.Logger; | ||
|
@@ -12,6 +18,8 @@ | |
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.servlet.mvc.support.RedirectAttributes; | ||
|
||
/** | ||
* Handles requests for the application home page. | ||
|
@@ -106,6 +114,90 @@ public String consultationGET(Model model, HttpSession session) throws Exception | |
return "consultation"; | ||
} | ||
|
||
|
||
// 상담하기 email - POST | ||
@RequestMapping(value = "/", method = RequestMethod.POST) | ||
public String sendConsultation( | ||
@RequestParam("company") String company, | ||
@RequestParam("name") String name, | ||
@RequestParam("contact") String contact, | ||
@RequestParam("email") String email, | ||
@RequestParam("inquiry") String inquiry, | ||
RedirectAttributes rttr) { | ||
|
||
final String fromEmail = "[email protected]"; // 네이버 이메일 계정 | ||
final String password = "571TT3J3UMVY"; // 네이버 이메일 비밀번호 | ||
|
||
String toEmail = "[email protected]"; // 수신 이메일 주소 | ||
|
||
// SMTP 설정 | ||
Properties props = new Properties(); | ||
props.put("mail.smtp.host", "smtp.naver.com"); | ||
props.put("mail.smtp.port", "465"); | ||
props.put("mail.smtp.auth", "true"); | ||
props.put("mail.smtp.ssl.enable", "true"); // SSL 활성화 | ||
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); | ||
|
||
Session session = Session.getInstance(props, new javax.mail.Authenticator() { | ||
protected PasswordAuthentication getPasswordAuthentication() { | ||
return new PasswordAuthentication(fromEmail, password); | ||
} | ||
}); | ||
|
||
try { | ||
// 이메일 내용 설정 | ||
MimeMessage message = new MimeMessage(session); | ||
message.setFrom(new javax.mail.internet.InternetAddress(fromEmail)); | ||
message.addRecipient(Message.RecipientType.TO, new javax.mail.internet.InternetAddress(toEmail)); | ||
message.setSubject("상담 신청 정보"); | ||
|
||
// HTML 형식 이메일 본문 | ||
String content = "<html>" | ||
+ "<body style='font-family: Arial, sans-serif; margin: 0; padding: 0;'>" | ||
+ "<div style='width: 100%; max-width: 600px; margin: 20px auto; border: 2px solid #005bac; border-radius: 10px; padding: 15px;'>" | ||
+ "<h2 style='color: #005bac; text-align: center;'>상담 신청 정보</h2>" | ||
+ "<table style='width: 100%; border-collapse: collapse;'>" | ||
+ " <tr style='background-color: #f2f9ff;'>" | ||
+ " <th style='text-align: left; padding: 8px; border: 1px solid #005bac; color: #005bac;'>회사명</th>" | ||
+ " <td style='padding: 8px; border: 1px solid #005bac;'>" + company + "</td>" | ||
+ " </tr>" | ||
+ " <tr>" | ||
+ " <th style='text-align: left; padding: 8px; border: 1px solid #005bac; color: #005bac;'>이름</th>" | ||
+ " <td style='padding: 8px; border: 1px solid #005bac;'>" + name + "</td>" | ||
+ " </tr>" | ||
+ " <tr style='background-color: #f2f9ff;'>" | ||
+ " <th style='text-align: left; padding: 8px; border: 1px solid #005bac; color: #005bac;'>연락처</th>" | ||
+ " <td style='padding: 8px; border: 1px solid #005bac;'>" + contact + "</td>" | ||
+ " </tr>" | ||
+ " <tr>" | ||
+ " <th style='text-align: left; padding: 8px; border: 1px solid #005bac; color: #005bac;'>이메일</th>" | ||
+ " <td style='padding: 8px; border: 1px solid #005bac;'>" + email + "</td>" | ||
+ " </tr>" | ||
+ " <tr style='background-color: #f2f9ff;'>" | ||
+ " <th style='text-align: left; padding: 8px; border: 1px solid #005bac; color: #005bac;'>문의 내용</th>" | ||
+ " <td style='padding: 8px; border: 1px solid #005bac;'>" + inquiry + "</td>" | ||
+ " </tr>" | ||
+ "</table>" | ||
+ "<p style='text-align: center; margin-top: 16px; color: #555;'>상담 신청해주셔서 감사합니다.</p>" | ||
+ "</div>" | ||
+ "</body></html>"; | ||
|
||
// 이메일 본문을 HTML로 설정 | ||
message.setContent(content, "text/html; charset=UTF-8"); | ||
|
||
// 메일 전송 | ||
Transport.send(message); | ||
rttr.addFlashAttribute("message", "상담 신청이 성공적으로 전송되었습니다."); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
rttr.addFlashAttribute("error", "이메일 전송에 실패했습니다. 다시 시도해주세요."); | ||
} | ||
|
||
// http://localhost:8088/로 리다이렉트 | ||
return "redirect:/"; | ||
} | ||
|
||
|
||
// 회사소개 - /intro (GET) | ||
@RequestMapping(value = "/intro", method = RequestMethod.GET) | ||
public String introGET(Model model, HttpSession session) throws Exception { | ||
|
@@ -118,4 +210,32 @@ public String introGET(Model model, HttpSession session) throws Exception { | |
// model.addAttribute("resultVO", resultVO); | ||
return "/intro"; | ||
} | ||
|
||
// 회사소개 - /price (GET) | ||
@RequestMapping(value = "/price", method = RequestMethod.GET) | ||
public String priceGET(Model model, HttpSession session) throws Exception { | ||
Long userId = (Long) session.getAttribute("userId"); | ||
// if (id == null) { | ||
// // 세션에 id가 없으면 에러 처리 | ||
// return "redirect:/user/main"; | ||
// } | ||
// UserVO resultVO = userService.getUser(userId); | ||
// model.addAttribute("resultVO", resultVO); | ||
return "/price"; | ||
} | ||
|
||
|
||
// 약도 - /minimap (GET) | ||
@RequestMapping(value = "/minimap", method = RequestMethod.GET) | ||
public String minimapGET(Model model, HttpSession session) throws Exception { | ||
Long userId = (Long) session.getAttribute("userId"); | ||
// if (id == null) { | ||
// // 세션에 id가 없으면 에러 처리 | ||
// return "redirect:/user/main"; | ||
// } | ||
// UserVO resultVO = userService.getUser(userId); | ||
// model.addAttribute("resultVO", resultVO); | ||
return "/minimap"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,12 +43,10 @@ public class UserController { | |
|
||
@Autowired | ||
private UserService userService; | ||
|
||
// http://localhost:8088 (o) | ||
|
||
// http://localhost:8088/user/signup (o) | ||
// http://localhost:8088/user/signin (o) | ||
// http://localhost:8088/user/main (o) | ||
// http://localhost:8088/ (o) | ||
// http://localhost:8088/user/info1 (o) | ||
// http://localhost:8088/user/info2 (o) | ||
// http://localhost:8088/dashboard (o) | ||
|
@@ -253,7 +251,7 @@ public String changepassword1GET(HttpSession session) { | |
return "/user/changepassword1"; // 비밀번호 입력 페이지로 이동 | ||
} | ||
|
||
// 회원정보 수정 | ||
|
||
@RequestMapping(value = "/changepassword1", method = RequestMethod.POST) | ||
public String changepassword2POST(@RequestParam("password") String password, RedirectAttributes rttr, HttpSession session) { | ||
Long userId = (Long) session.getAttribute("userId"); | ||
|
@@ -283,7 +281,7 @@ public String changepassword2POST(@RequestParam("password") String password, Red | |
} | ||
} | ||
|
||
// - GET | ||
|
||
@RequestMapping(value = "/changepassword2", method = RequestMethod.GET) | ||
public String changepassword2GET(@ModelAttribute("currentPassword") String currentPassword, Model model) { | ||
if (currentPassword == null || currentPassword.isEmpty()) { | ||
|
@@ -294,7 +292,6 @@ public String changepassword2GET(@ModelAttribute("currentPassword") String curre | |
return "/user/changepassword2"; // JSP 페이지 반환 | ||
} | ||
|
||
// - POST | ||
@RequestMapping(value = "/changepassword2", method = RequestMethod.POST) | ||
public void changePasswordPOST( | ||
@RequestParam("newPassword") String newPassword, | ||
|
@@ -340,96 +337,17 @@ public void changePasswordPOST( | |
} | ||
} | ||
|
||
// 상담하기 email - GET | ||
@RequestMapping(value = "/sendConsultation", method = RequestMethod.POST) | ||
public String sendConsultation( | ||
@RequestParam("company") String company, | ||
@RequestParam("name") String name, | ||
@RequestParam("contact") String contact, | ||
@RequestParam("email") String email, | ||
@RequestParam("inquiry") String inquiry, | ||
RedirectAttributes rttr) { | ||
|
||
final String fromEmail = "[email protected]"; // 네이버 이메일 계정 | ||
final String password = "571TT3J3UMVY"; // 네이버 이메일 비밀번호 | ||
|
||
String toEmail = "[email protected]"; // 수신 이메일 주소 | ||
|
||
// SMTP 설정 | ||
Properties props = new Properties(); | ||
props.put("mail.smtp.host", "smtp.naver.com"); | ||
props.put("mail.smtp.port", "465"); | ||
props.put("mail.smtp.auth", "true"); | ||
props.put("mail.smtp.ssl.enable", "true"); // SSL 활성화 | ||
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); | ||
|
||
Session session = Session.getInstance(props, new javax.mail.Authenticator() { | ||
protected PasswordAuthentication getPasswordAuthentication() { | ||
return new PasswordAuthentication(fromEmail, password); | ||
} | ||
}); | ||
|
||
try { | ||
// 이메일 내용 설정 | ||
MimeMessage message = new MimeMessage(session); | ||
message.setFrom(new javax.mail.internet.InternetAddress(fromEmail)); | ||
message.addRecipient(Message.RecipientType.TO, new javax.mail.internet.InternetAddress(toEmail)); | ||
message.setSubject("상담 신청 정보"); | ||
|
||
// HTML 형식 이메일 본문 | ||
String content = "<html>" | ||
+ "<body style='font-family: Arial, sans-serif; margin: 0; padding: 0;'>" | ||
+ "<div style='width: 100%; max-width: 600px; margin: 20px auto; border: 2px solid #005bac; border-radius: 10px; padding: 15px;'>" | ||
+ "<h2 style='color: #005bac; text-align: center;'>상담 신청 정보</h2>" | ||
+ "<table style='width: 100%; border-collapse: collapse;'>" | ||
+ " <tr style='background-color: #f2f9ff;'>" | ||
+ " <th style='text-align: left; padding: 8px; border: 1px solid #005bac; color: #005bac;'>회사명</th>" | ||
+ " <td style='padding: 8px; border: 1px solid #005bac;'>" + company + "</td>" | ||
+ " </tr>" | ||
+ " <tr>" | ||
+ " <th style='text-align: left; padding: 8px; border: 1px solid #005bac; color: #005bac;'>이름</th>" | ||
+ " <td style='padding: 8px; border: 1px solid #005bac;'>" + name + "</td>" | ||
+ " </tr>" | ||
+ " <tr style='background-color: #f2f9ff;'>" | ||
+ " <th style='text-align: left; padding: 8px; border: 1px solid #005bac; color: #005bac;'>연락처</th>" | ||
+ " <td style='padding: 8px; border: 1px solid #005bac;'>" + contact + "</td>" | ||
+ " </tr>" | ||
+ " <tr>" | ||
+ " <th style='text-align: left; padding: 8px; border: 1px solid #005bac; color: #005bac;'>이메일</th>" | ||
+ " <td style='padding: 8px; border: 1px solid #005bac;'>" + email + "</td>" | ||
+ " </tr>" | ||
+ " <tr style='background-color: #f2f9ff;'>" | ||
+ " <th style='text-align: left; padding: 8px; border: 1px solid #005bac; color: #005bac;'>문의 내용</th>" | ||
+ " <td style='padding: 8px; border: 1px solid #005bac;'>" + inquiry + "</td>" | ||
+ " </tr>" | ||
+ "</table>" | ||
+ "<p style='text-align: center; margin-top: 16px; color: #555;'>상담 신청해주셔서 감사합니다.</p>" | ||
+ "</div>" | ||
+ "</body></html>"; | ||
|
||
// 이메일 본문을 HTML로 설정 | ||
message.setContent(content, "text/html; charset=UTF-8"); | ||
|
||
// 메일 전송 | ||
Transport.send(message); | ||
rttr.addFlashAttribute("message", "상담 신청이 성공적으로 전송되었습니다."); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
rttr.addFlashAttribute("error", "이메일 전송에 실패했습니다. 다시 시도해주세요."); | ||
} | ||
|
||
return "redirect:/user/consultation"; | ||
} | ||
|
||
|
||
// 비밀번호 찾기 - GET | ||
@RequestMapping(value = "/findpassword", method = RequestMethod.GET) | ||
@RequestMapping(value = "/findPassword", method = RequestMethod.GET) | ||
public String findPasswordGet() { | ||
return "/user/findpassword"; // 비밀번호 찾기 페이지로 이동 | ||
return "/user/findPassword"; // 비밀번호 찾기 페이지로 이동 | ||
} | ||
|
||
// 비밀번호 찾기 - POST | ||
@RequestMapping(value = "/findpassword", method = RequestMethod.POST) | ||
@RequestMapping(value = "/findPassword", method = RequestMethod.POST) | ||
public String findPasswordPost(@RequestParam("email") String email, | ||
@RequestParam("name") String name, | ||
Model model) { | ||
|
@@ -446,13 +364,13 @@ public String findPasswordPost(@RequestParam("email") String email, | |
// 비밀번호가 일치하지 않으면 오류 메시지 추가 | ||
logger.info("비밀번호 찾기 실패: 이메일 또는 이름이 일치하지 않음"); // 실패 로그 | ||
model.addAttribute("errorMessage", "이메일 또는 이름이 일치하지 않습니다."); | ||
return "/user/findpassword"; // 비밀번호 찾기 페이지로 다시 이동 | ||
return "/user/findPassword"; // 비밀번호 찾기 페이지로 다시 이동 | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
logger.error("비밀번호 찾기 처리 중 오류 발생", e); // 예외 로그 추가 | ||
model.addAttribute("errorMessage", "비밀번호 찾기 처리 중 오류가 발생했습니다."); | ||
return "/user/findpassword"; // 오류 발생 시 비밀번호 찾기 페이지로 돌아감 | ||
return "/user/findPassword"; // 오류 발생 시 비밀번호 찾기 페이지로 돌아감 | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.