Skip to content

Commit

Permalink
임시저장
Browse files Browse the repository at this point in the history
  • Loading branch information
BowWowBow committed Dec 19, 2024
1 parent a535bf4 commit 2ab8cec
Show file tree
Hide file tree
Showing 8 changed files with 698 additions and 185 deletions.
120 changes: 120 additions & 0 deletions stockMate/src/main/java/com/stockm8/controller/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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";
}

}
98 changes: 8 additions & 90 deletions stockMate/src/main/java/com/stockm8/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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()) {
Expand All @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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"; // 오류 발생 시 비밀번호 찾기 페이지로 돌아감
}
}

Expand Down
31 changes: 29 additions & 2 deletions stockMate/src/main/webapp/WEB-INF/views/consultation.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
}
.form-container input, .form-container textarea, .form-container button {
width: 95.3%;
width: 96%;
margin-bottom: 8px;
padding: 8px;
border: none;
Expand All @@ -80,6 +80,30 @@
background-color: #ffaa00;
}
.back-button {
display: flex;
justify-content: center; /* 수평 중앙 정렬 */
margin: 40px auto; /* 위아래 여백 추가 */
}
.back-button a {
text-decoration: none;
padding: 15px 30px;
background-color: #007BFF;
color: #fff;
border-radius: 10px;
font-size: 20px;
font-weight: bold;
font-family: 'Roboto', sans-serif;
transition: background-color 0.3s ease, transform 0.3s ease;
}
.back-button a:hover {
background-color: #0056b3;
transform: scale(1.05);
}
.footer {
text-align: center;
margin-top: 10px;
Expand Down Expand Up @@ -124,7 +148,7 @@
<!-- 상담 신청 폼 -->
<div class="form-container">
<h2>상담문의</h2>
<form action="/user/sendConsultation" method="post">
<form action="/" method="post">
<input type="text" name="company" placeholder="회사명" required>
<input type="text" name="name" placeholder="이름" required>
<input type="text" name="contact" placeholder="연락처" required>
Expand All @@ -145,6 +169,9 @@
<strong>1588-2929</strong>
</div>
</div>
<div class="back-button">
<a href="/">뒤로 돌아가기</a>
</div>
</div>
</body>
</html>
1 change: 1 addition & 0 deletions stockMate/src/main/webapp/WEB-INF/views/dashboard.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>대시보드</title>
<style>
/* Reset and Global Styles */
body, html {
margin: 0;
Expand Down
Loading

0 comments on commit 2ab8cec

Please sign in to comment.