이메일 발송 Util파일 생성 및 모듈화
name email mask 함수 StringUtil에 추가
This commit is contained in:
parent
448188b0f8
commit
ec5f029209
@ -2,7 +2,6 @@
|
||||
package nlib.user.web;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
@ -10,12 +9,10 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
@ -23,41 +20,17 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
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.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
import org.springframework.web.servlet.support.RequestContextUtils;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
||||
import com.github.scribejava.core.model.OAuth2AccessToken;
|
||||
|
||||
import egovframework.com.ext.oauth.service.OAuthConfig;
|
||||
import egovframework.com.ext.oauth.service.OAuthLogin;
|
||||
import egovframework.com.ext.oauth.service.OAuthUniversalUser;
|
||||
import egovframework.com.ext.oauth.service.OAuthVO;
|
||||
@ -66,20 +39,17 @@ import nlib.cmm.NlibCommonController;
|
||||
import nlib.cmm.crypto.AriaCrypto;
|
||||
import nlib.cmm.service.NlibProperty;
|
||||
import nlib.cmm.session.SessionConfig;
|
||||
import nlib.cmm.snslogin.GoogleOAuthResponse;
|
||||
import nlib.cmm.snslogin.KakaoController;
|
||||
import nlib.info.service.InformService;
|
||||
import nlib.mail.EmailSender;
|
||||
import nlib.mail.service.EmailVO;
|
||||
import nlib.restful.service.DataApiReqVO;
|
||||
import nlib.user.service.LoginService;
|
||||
import nlib.user.service.MemberService;
|
||||
import nlib.user.service.NlibLoginVO;
|
||||
import nlib.user.service.UserInfoService;
|
||||
import nlib.util.StringUtil;
|
||||
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import nlib.util.EmailUtil;
|
||||
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
@ -138,8 +108,8 @@ public class MemberController extends NlibCommonController{
|
||||
@Resource(name = "ariaCrypto")
|
||||
private AriaCrypto ariaCrypto;
|
||||
|
||||
@Autowired
|
||||
private EmailSender emailSender;
|
||||
@Resource(name = "emailUtil")
|
||||
private EmailUtil emailUtil;
|
||||
|
||||
/* 이메일 메시지 및 템플릿 정보 */
|
||||
//템플릿 파일경로
|
||||
@ -161,6 +131,8 @@ public class MemberController extends NlibCommonController{
|
||||
@Value("#{properties['guest.userid']}")
|
||||
private String gUserId;
|
||||
|
||||
@Autowired
|
||||
private EmailSender emailSender;
|
||||
|
||||
public ModelMap certificateMember(HttpServletRequest req) {
|
||||
return null;
|
||||
@ -295,8 +267,8 @@ public class MemberController extends NlibCommonController{
|
||||
//사용자ID 마스킹처리
|
||||
for(int i=0;voList.size()>i;i++)
|
||||
{
|
||||
voList.get(i).setEmail(maskingEmail(ariaCrypto.decode(voList.get(i).getEmail())));
|
||||
voList.get(i).setName(maskingName(voList.get(i).getName()));
|
||||
voList.get(i).setEmail(StringUtil.maskEmail(ariaCrypto.decode(voList.get(i).getEmail())));
|
||||
voList.get(i).setName(StringUtil.maskName(voList.get(i).getName()));
|
||||
}
|
||||
|
||||
model.addAttribute("cnt",voList.size());
|
||||
@ -367,8 +339,8 @@ public class MemberController extends NlibCommonController{
|
||||
loginVO.setJoinCouncilCd(getCurCouncilCd(request));
|
||||
|
||||
loginVO = loginService.selectLoginUserInfo(loginVO);
|
||||
loginVO.setEmail(maskingEmail(loginVO.getEmail()));
|
||||
loginVO.setName(maskingName(loginVO.getName()));
|
||||
loginVO.setEmail(StringUtil.maskEmail(loginVO.getEmail()));
|
||||
loginVO.setName(StringUtil.maskName(loginVO.getName()));
|
||||
|
||||
model.addAttribute("result",loginVO);
|
||||
return "/nlib/member/accountConsolidationForm";
|
||||
@ -427,31 +399,10 @@ public class MemberController extends NlibCommonController{
|
||||
|
||||
// 결과가 정상이면, 안내 메일 발송
|
||||
// > 템플릿파일에서 내용 mailing.sender.membership.template
|
||||
// > 치환 (사용자명, 이메일주소)
|
||||
// > 발송처리 요청
|
||||
String reciver = vo.getLoginUserId(); //받을사람의 이메일입니다.-> naver nate 등등
|
||||
String subject = "온라인자료대출시스템 회원가입을 축하드립니다.";
|
||||
|
||||
Path path = Paths.get(template);
|
||||
Charset cs = StandardCharsets.UTF_8;
|
||||
List<String> list = new ArrayList<String>();
|
||||
String contents = "";
|
||||
try {
|
||||
list = Files.readAllLines(path,cs);
|
||||
}catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for(String readLine : list) {
|
||||
contents+=readLine;
|
||||
}
|
||||
contents=contents.replace("${userName}",vo.getName());
|
||||
|
||||
email.setReciver(reciver);
|
||||
|
||||
email.setSubject(subject);
|
||||
email.setContent(contents);
|
||||
emailSender.SendEmail(email);
|
||||
Map<String, Object> replaceContents = new HashMap<String, Object>();
|
||||
replaceContents.put("${contents}", vo.getName());
|
||||
emailUtil.sendEmail(vo.getLoginUserId(),"온라인자료대출시스템 회원가입을 축하드립니다.",replaceContents,template);
|
||||
|
||||
return "nlib/member/insertMemberInfoResult";
|
||||
}
|
||||
@ -519,31 +470,11 @@ public class MemberController extends NlibCommonController{
|
||||
//이메일 발송
|
||||
// 결과가 정상이면, 안내 메일 발송
|
||||
// > 템플릿파일에서 내용 mailing.sender.membership.template
|
||||
// > 치환 (사용자명, 이메일주소)
|
||||
// > 발송처리 요청
|
||||
String reciver = email; //받을사람의 이메일입니다.-> naver nate 등등
|
||||
String subject = "온라인자료대출시스템 이메일 인증번호";
|
||||
|
||||
Path path = Paths.get(template);
|
||||
Charset cs = StandardCharsets.UTF_8;
|
||||
List<String> list = new ArrayList<String>();
|
||||
String contents = "";
|
||||
try {
|
||||
list = Files.readAllLines(path,cs);
|
||||
}catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Map<String, Object> replaceContents = new HashMap<String, Object>();
|
||||
replaceContents.put("${contents}", "인증번호는"+CertNumber+"입니다.");
|
||||
emailUtil.sendEmail(email,"온라인자료대출시스템 이메일 인증번호",replaceContents,template);
|
||||
|
||||
for(String readLine : list) {
|
||||
contents+=readLine;
|
||||
}
|
||||
contents=contents.replace("${userName}","인증번호는"+CertNumber+"입니다.");
|
||||
|
||||
emailVO.setReciver(reciver);
|
||||
|
||||
emailVO.setSubject(subject);
|
||||
emailVO.setContent(contents);
|
||||
emailSender.SendEmail(emailVO);
|
||||
map.put("msg","이메일 인증번호가 발송됐습니다.");
|
||||
map.put("emailCertYn","Y");
|
||||
return map;
|
||||
@ -704,8 +635,8 @@ public class MemberController extends NlibCommonController{
|
||||
|
||||
loginVO = loginService.selectLoginUserInfo(loginVO);
|
||||
//이메일,이름 마스킹
|
||||
loginVO.setEmail(maskingEmail(loginVO.getEmail()));
|
||||
loginVO.setName(maskingName(loginVO.getName()));
|
||||
loginVO.setEmail(StringUtil.maskEmail(loginVO.getEmail()));
|
||||
loginVO.setName(StringUtil.maskName(loginVO.getName()));
|
||||
model.addAttribute("loginVO",loginVO);
|
||||
return "nlib/member/deleteMembershipForm";
|
||||
}
|
||||
@ -778,45 +709,14 @@ public class MemberController extends NlibCommonController{
|
||||
|
||||
if(loginVO!=null)
|
||||
{
|
||||
String reciver = vo.getEmail(); //받을사람의 이메일입니다.-> naver nate 등등
|
||||
String subject = "온라인자료대출시스템 비밀번호 초기화 메일입니다.";
|
||||
|
||||
|
||||
// 결과가 정상이면, 안내 메일 발송
|
||||
// > 템플릿파일에서 내용 mailing.sender.membership.pwdtemplate
|
||||
// > 치환 (사용자명, 이메일주소)
|
||||
// > 발송처리 요청
|
||||
Path path = Paths.get(pwdTemplate);
|
||||
Charset cs = StandardCharsets.UTF_8;
|
||||
List<String> list = new ArrayList<String>();
|
||||
String contents = "";
|
||||
try {
|
||||
list = Files.readAllLines(path,cs);
|
||||
}catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for(String readLine : list) {
|
||||
contents+=readLine;
|
||||
}
|
||||
|
||||
encodedText = egovPasswordEncoder.encryptPassword(loginVO.getLoginUserId()+InitPwd);
|
||||
vo.setPassword(encodedText);
|
||||
|
||||
vo.setMbInfoId(gUserId);
|
||||
vo.encodePrivateInfo();
|
||||
//암호화된 비밀번호로 수정
|
||||
memberService.changePassword(vo);
|
||||
|
||||
contents=contents.replace("${userPwd}",InitPwd);
|
||||
|
||||
email.setReciver(reciver);
|
||||
|
||||
email.setSubject(subject);
|
||||
email.setContent(contents);
|
||||
emailSender.SendEmail(email);
|
||||
|
||||
|
||||
Map<String, Object> replaceContents = new HashMap<String, Object>();
|
||||
replaceContents.put("${contents}", InitPwd);
|
||||
emailUtil.sendEmail(vo.getEmail(),"온라인자료대출시스템 비밀번호 초기화 메일입니다.",replaceContents,pwdTemplate);
|
||||
|
||||
|
||||
message="초기화된 비밀번호가 이메일로 발송됐습니다.";
|
||||
}else {
|
||||
@ -857,51 +757,6 @@ public class MemberController extends NlibCommonController{
|
||||
return message;
|
||||
}
|
||||
|
||||
/** * 이메일 masking 후 리턴<br> * 변환 실패시 입력값 그대로 리턴<br> * 이메일 아이디 앞 2자리 노출<br> */
|
||||
public String maskingEmail(String email){
|
||||
try{
|
||||
if(StringUtils.isEmpty(email) || !email.contains("@")){
|
||||
return email;
|
||||
}
|
||||
String[] emailSplited = email.split("@");
|
||||
if(emailSplited.length != 2){
|
||||
return email;
|
||||
}
|
||||
if(emailSplited[0].length() > 2){
|
||||
String str="";
|
||||
for(int i=2;emailSplited[0].length()>i;i++)
|
||||
{
|
||||
str+="*";
|
||||
}
|
||||
return email.substring(0, 2) + str+"@" + emailSplited[1];
|
||||
}
|
||||
else{
|
||||
return email;
|
||||
}
|
||||
}
|
||||
catch (Exception e){
|
||||
} return email;
|
||||
}
|
||||
/** * 이름 masking 후 리턴<br> * 변환 실패시 입력값 그대로 리턴<br>*/
|
||||
public String maskingName(String name){
|
||||
try{
|
||||
if(StringUtils.isEmpty(name)){
|
||||
return name;
|
||||
}
|
||||
if(name.length() == 2){
|
||||
|
||||
return name.substring(0, 1)+"*";
|
||||
}
|
||||
else if(name.length() >2){
|
||||
String str="";
|
||||
for(int i = 2; name.length()>i;i++)
|
||||
str+="*";
|
||||
return name.substring(0, 1)+str+name.substring(name.length()-1,name.length());
|
||||
}
|
||||
}
|
||||
catch (Exception e){
|
||||
} return name;
|
||||
}
|
||||
/**
|
||||
* 회원가입 SNS 구글인증
|
||||
* @exception Exception
|
||||
|
||||
90
src/main/java/nlib/util/EmailUtil.java
Normal file
90
src/main/java/nlib/util/EmailUtil.java
Normal file
@ -0,0 +1,90 @@
|
||||
package nlib.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import egovframework.com.cmm.EgovWebUtil;
|
||||
import egovframework.com.utl.fcc.service.EgovStringUtil;
|
||||
import nlib.mail.EmailSender;
|
||||
import nlib.mail.service.EmailVO;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* @Class Name : EmailUtil.java
|
||||
*
|
||||
* @Description : 이메일 관련 유틸리티 기능 모음 클래스
|
||||
*
|
||||
*
|
||||
* @프로젝트명: 지방문화원 통합자료관리시스템 구축사업 (2021)
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @ ------------ -------- ---------------------------
|
||||
* @ 수정일 수정자 수정내용
|
||||
* @ ------------ -------- ---------------------------
|
||||
* @ 2021. 9. 16. JSYOo 최초 생성
|
||||
*
|
||||
*
|
||||
* @author 이씨플라자 * DIGITALSHIP JSYOO
|
||||
* @since 2021. 9. 16.
|
||||
* @version 1.0
|
||||
*
|
||||
*/
|
||||
@Component("emailUtil")
|
||||
public class EmailUtil{
|
||||
|
||||
@Autowired
|
||||
private EmailSender emailSender;
|
||||
|
||||
|
||||
/** 메일발송
|
||||
* @param reciverEmail
|
||||
* @param subject
|
||||
* @param replaceContents
|
||||
* @param templateFilePath
|
||||
* @throws Exception
|
||||
*/
|
||||
public void sendEmail(String reciverEmail, String subject, Map<String, Object> replaceContents, String templateFilePath) throws Exception {
|
||||
EmailVO email = new EmailVO();
|
||||
|
||||
Path path = Paths.get(templateFilePath);
|
||||
Charset cs = StandardCharsets.UTF_8;
|
||||
List<String> list = new ArrayList<String>();
|
||||
String contents = "";
|
||||
try {
|
||||
list = Files.readAllLines(path,cs);
|
||||
}catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for(String readLine : list) {
|
||||
contents+=readLine;
|
||||
}
|
||||
Set set = replaceContents.keySet();
|
||||
|
||||
Iterator iterator = set.iterator();
|
||||
|
||||
while(iterator.hasNext()){
|
||||
String key = (String)iterator.next();
|
||||
contents=contents.replace(key,(CharSequence) replaceContents.get(key));
|
||||
}
|
||||
email.setReciver(reciverEmail);
|
||||
|
||||
email.setSubject(subject);
|
||||
email.setContent(contents);
|
||||
emailSender.SendEmail(email);
|
||||
}
|
||||
}
|
||||
@ -191,4 +191,51 @@ public class StringUtil extends StringUtils {
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/** * 이메일 masking 후 리턴<br> * 변환 실패시 입력값 그대로 리턴<br> * 이메일 아이디 앞 2자리 노출<br> */
|
||||
public static String maskEmail(String email){
|
||||
try{
|
||||
if(StringUtils.isEmpty(email) || !email.contains("@")){
|
||||
return email;
|
||||
}
|
||||
String[] emailSplited = email.split("@");
|
||||
if(emailSplited.length != 2){
|
||||
return email;
|
||||
}
|
||||
if(emailSplited[0].length() > 2){
|
||||
String str="";
|
||||
for(int i=2;emailSplited[0].length()>i;i++)
|
||||
{
|
||||
str+="*";
|
||||
}
|
||||
return email.substring(0, 2) + str+"@" + emailSplited[1];
|
||||
}
|
||||
else{
|
||||
return email;
|
||||
}
|
||||
}
|
||||
catch (Exception e){
|
||||
} return email;
|
||||
}
|
||||
|
||||
/** * 이름 masking 후 리턴<br> * 변환 실패시 입력값 그대로 리턴<br>*/
|
||||
public static String maskName(String name){
|
||||
try{
|
||||
if(StringUtils.isEmpty(name)){
|
||||
return name;
|
||||
}
|
||||
if(name.length() == 2){
|
||||
|
||||
return name.substring(0, 1)+"*";
|
||||
}
|
||||
else if(name.length() >2){
|
||||
String str="";
|
||||
for(int i = 2; name.length()>i;i++)
|
||||
str+="*";
|
||||
return name.substring(0, 1)+str+name.substring(name.length()-1,name.length());
|
||||
}
|
||||
}
|
||||
catch (Exception e){
|
||||
} return name;
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<span style="color:orange">${userName}</span>님 회원가입이 완료되었습니다.
|
||||
<span style="color:orange">${contents}</span>님 회원가입이 완료되었습니다.
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@ -6,7 +6,7 @@
|
||||
</head>
|
||||
<body>
|
||||
|
||||
초기화된 비밀번호는 <span style="color:orange">${userPwd}</span> 입니다.
|
||||
초기화된 비밀번호는 <span style="color:orange">${contents}</span> 입니다.
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue
Block a user