refactor: simplecapcha remark 처리

JDK 8 -> 11 up
main
Jonguk. Lim 2 years ago
parent 8cd542cfaa
commit 1a1c6ec36f

@ -19,7 +19,7 @@
<properties> <properties>
<encoding>UTF-8</encoding> <encoding>UTF-8</encoding>
<java-version>1.8</java-version> <java-version>11</java-version>
<spring.maven.artifact.version>4.3.25.RELEASE</spring.maven.artifact.version> <spring.maven.artifact.version>4.3.25.RELEASE</spring.maven.artifact.version>
<egovframework.rte.version>3.10.0</egovframework.rte.version> <egovframework.rte.version>3.10.0</egovframework.rte.version>
<org.apache.tiles.version>3.0.5</org.apache.tiles.version> <org.apache.tiles.version>3.0.5</org.apache.tiles.version>
@ -69,6 +69,71 @@
</repositories> </repositories>
<dependencies> <dependencies>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.15.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
<version>3.0.15.RELEASE</version>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
<version>3.1.0</version>
</dependency>
<!--
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.23</version>
</dependency>
-->
<!--
<dependency>
<groupId>com.github.spullara.mustache.java</groupId>
<artifactId>compiler</artifactId>
<version>0.9.4</version>
</dependency>
<dependency>
<groupId>com.samskivert</groupId>
<artifactId>jmustache</artifactId>
<version>1.15</version>
</dependency>
-->
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mustache</artifactId>
<version>2.1.18.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
-->
<dependency> <dependency>
<groupId>egovframework.rte</groupId> <groupId>egovframework.rte</groupId>
<artifactId>egovframework.rte.fdl.logging</artifactId> <artifactId>egovframework.rte.fdl.logging</artifactId>
@ -484,13 +549,13 @@
</dependency> </dependency>
<!--
<dependency> <dependency>
<groupId>nl.captcha</groupId> <groupId>nl.captcha</groupId>
<artifactId>simplecaptcha</artifactId> <artifactId>simplecaptcha</artifactId>
<version>1.2.1</version> <version>1.2.1</version>
</dependency> </dependency>
-->
<!-- Apache Commons Configurations --> <!-- Apache Commons Configurations -->
<dependency> <dependency>
@ -732,6 +797,7 @@
<include>spring/service/cache/*.xml</include> <include>spring/service/cache/*.xml</include>
<include>sqlmapper/**/*</include> <include>sqlmapper/**/*</include>
<include>validator/**/*</include> <include>validator/**/*</include>
<include>templates/**/*</include>
</includes> </includes>
<filtering>true</filtering> <filtering>true</filtering>
</resource> </resource>
@ -931,6 +997,7 @@
</executions> </executions>
</plugin> </plugin>
<!-- Rest Doc 생성 --> <!-- Rest Doc 생성 -->
</plugins> </plugins>
</build> </build>
<reporting> <reporting>

@ -7,7 +7,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import nl.captcha.Captcha; //import nl.captcha.Captcha;
import kr.xit.framework.biz.cmm.dto.XitLoginPolicyVO; import kr.xit.framework.biz.cmm.dto.XitLoginPolicyVO;
import kr.xit.framework.biz.cmm.dto.XitUserAbsnceVO; import kr.xit.framework.biz.cmm.dto.XitUserAbsnceVO;
import kr.xit.framework.biz.cmm.service.XitFrameCrudService; import kr.xit.framework.biz.cmm.service.XitFrameCrudService;
@ -92,13 +92,15 @@ public class XitLoginServiceImpl implements XitLoginService{
//캡차인증 확인 //캡차인증 확인
HttpServletRequest req = XitHttpRequestHelper.getCurrentRequest(); HttpServletRequest req = XitHttpRequestHelper.getCurrentRequest();
boolean isUseCaptcha = XitCmmnUtil.notEmpty(req.getSession().getAttribute("captcha")); boolean isUseCaptcha = XitCmmnUtil.notEmpty(req.getSession().getAttribute("captcha"));
if(isUseCaptcha) {
Captcha captcha = (Captcha) req.getSession().getAttribute("captcha"); // FIXME :: Simple captcha
String captchStr = captcha.getAnswer(); // if(isUseCaptcha) {
String userInputStr = (String) req.getParameter("captcha"); // Captcha captcha = (Captcha) req.getSession().getAttribute("captcha");
if(!captchStr.equals(userInputStr)) // String captchStr = captcha.getAnswer();
throw new RuntimeException(String.format("자동로그인 방지 문구와 입력하신 값이 일치하지 않습니다.(생성:%s/입력:%s)", captchStr, userInputStr)); // String userInputStr = (String) req.getParameter("captcha");
} // if(!captchStr.equals(userInputStr))
// throw new RuntimeException(String.format("자동로그인 방지 문구와 입력하신 값이 일치하지 않습니다.(생성:%s/입력:%s)", captchStr, userInputStr));
// }

@ -38,7 +38,7 @@ import kr.xit.framework.core.constants.FrameworkConstants.USER_SE;
import kr.xit.framework.core.message.XitMessageSource; import kr.xit.framework.core.message.XitMessageSource;
import kr.xit.framework.core.utils.XitCmmnUtil; import kr.xit.framework.core.utils.XitCmmnUtil;
//import kr.xit.framework.core.utils.XitProperties; //import kr.xit.framework.core.utils.XitProperties;
import kr.xit.framework.core.utils.captcha.XitCaptchaUtil; //import kr.xit.framework.core.utils.captcha.XitCaptchaUtil;
import kr.xit.framework.core.validation.XitBeanValidator; import kr.xit.framework.core.validation.XitBeanValidator;
import kr.xit.framework.support.util.AjaxUtils; import kr.xit.framework.support.util.AjaxUtils;
@ -453,7 +453,7 @@ public class XitFrameAnonymousController {
*/ */
@RequestMapping(value = "captcha", method={RequestMethod.GET, RequestMethod.POST}) @RequestMapping(value = "captcha", method={RequestMethod.GET, RequestMethod.POST})
public void captcha(HttpServletRequest request, HttpServletResponse response) { public void captcha(HttpServletRequest request, HttpServletResponse response) {
XitCaptchaUtil.getImage(request, response); //XitCaptchaUtil.getImage(request, response);
} }

@ -84,7 +84,8 @@ public class XitLoginController {
// 1. Spring Security 사용자권한 처리 // 1. Spring Security 사용자권한 처리
Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated(); Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();
if (!isAuthenticated) { if (!isAuthenticated) {
return LOGIN_PAGE+TILES_TYPE.NONE.getVal(); //return LOGIN_PAGE+TILES_TYPE.NONE.getVal();
return LOGIN_PAGE;
} }
// 2. 메인 페이지 이동 // 2. 메인 페이지 이동
@ -189,7 +190,8 @@ public class XitLoginController {
} else { } else {
model.addAttribute("message", message==null?xitMessageSource.getMessage("fail.common.login"):message); model.addAttribute("message", message==null?xitMessageSource.getMessage("fail.common.login"):message);
//return XitProperties.getProperty("Globals.Xit.LoginPage")+TILES_TYPE.NONE.getVal(); //return XitProperties.getProperty("Globals.Xit.LoginPage")+TILES_TYPE.NONE.getVal();
return LOGIN_PAGE+TILES_TYPE.NONE.getVal(); //return LOGIN_PAGE+TILES_TYPE.NONE.getVal();
return LOGIN_PAGE;
} }
} }

@ -1,94 +1,94 @@
package kr.xit.framework.core.utils.captcha; // package kr.xit.framework.core.utils.captcha;
//
import java.awt.*; // import java.awt.*;
import java.io.IOException; // import java.io.IOException;
import java.util.ArrayList; // import java.util.ArrayList;
import java.util.List; // import java.util.List;
//
import javax.servlet.http.HttpServletRequest; // import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; // import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; // import javax.servlet.http.HttpSession;
//
import org.slf4j.Logger; // import org.slf4j.Logger;
import org.slf4j.LoggerFactory; // import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller; // import org.springframework.stereotype.Controller;
//
import kr.xit.framework.support.captcha.SimpleCaptchaUtil; // import kr.xit.framework.support.captcha.SimpleCaptchaUtil;
import nl.captcha.Captcha; // import nl.captcha.Captcha;
import nl.captcha.audio.AudioCaptcha; // import nl.captcha.audio.AudioCaptcha;
import nl.captcha.backgrounds.GradiatedBackgroundProducer; // import nl.captcha.backgrounds.GradiatedBackgroundProducer;
import nl.captcha.servlet.CaptchaServletUtil; // import nl.captcha.servlet.CaptchaServletUtil;
import nl.captcha.text.producer.NumbersAnswerProducer; // import nl.captcha.text.producer.NumbersAnswerProducer;
import nl.captcha.text.renderer.DefaultWordRenderer; // import nl.captcha.text.renderer.DefaultWordRenderer;
//
@Controller // @Controller
public class XitCaptchaUtil { // public class XitCaptchaUtil {
private Logger logger = LoggerFactory.getLogger(getClass()); // private Logger logger = LoggerFactory.getLogger(getClass());
//
/** // /**
* <pre> : . // * <pre>메소드 설명: 캡차인증 이미지를 생성 한다.
* - . // * -자동로그인 방지를 위해 특정문구가 입력된 캡차 이미지를 생성 한다.
* - session attribute "captcha" . // * -캡차 이미지에 입력된 문구는 요청 session의 attribute에 "captcha"란 이름으로 저장 된다.
* </pre> // * </pre>
* @param request // * @param request
* @param response void // * @param response void 요청처리 후 응답객체
* @author: // * @author: 박민규
* @date: 2020. 9. 22. // * @date: 2020. 9. 22.
*/ // */
public static void getImage(HttpServletRequest request, HttpServletResponse response) { // public static void getImage(HttpServletRequest request, HttpServletResponse response) {
//
/*폰트 및 컬러 설정*/ // /*폰트 및 컬러 설정*/
List<Font> fontList = new ArrayList<Font>(); // List<Font> fontList = new ArrayList<Font>();
fontList.add(new Font("", Font.HANGING_BASELINE, 40)); // fontList.add(new Font("", Font.HANGING_BASELINE, 40));
fontList.add(new Font("Courier", Font.ITALIC, 40)); // fontList.add(new Font("Courier", Font.ITALIC, 40));
fontList.add(new Font("", Font.PLAIN, 40)); // fontList.add(new Font("", Font.PLAIN, 40));
List<Color> colorList = new ArrayList<Color>(); // List<Color> colorList = new ArrayList<Color>();
colorList.add(Color.BLACK); // colorList.add(Color.BLACK);
//
//Captcha captcha = new Captcha.Builder(250, 50) //캡차 이미지 크기(가로,세로) // //Captcha captcha = new Captcha.Builder(250, 50) //캡차 이미지 크기(가로,세로)
Captcha captcha = new Captcha.Builder(250, 50) //캡차 이미지 크기(가로,세로) // Captcha captcha = new Captcha.Builder(250, 50) //캡차 이미지 크기(가로,세로)
.addText(new NumbersAnswerProducer(6), new DefaultWordRenderer(colorList, fontList)) //이미지문구 생성(default: 5자리의 랜덤한 알파벳과 숫자 생성) // .addText(new NumbersAnswerProducer(6), new DefaultWordRenderer(colorList, fontList)) //이미지문구 생성(default: 5자리의 랜덤한 알파벳과 숫자 생성)
// .addText(new NumbersAnswerProducer()) //이미지문구 생성(5자리의 랜덤한 숫자 생성) // // .addText(new NumbersAnswerProducer()) //이미지문구 생성(5자리의 랜덤한 숫자 생성)
.addBackground(new GradiatedBackgroundProducer()) //바탕색 흰색 - Default // .addBackground(new GradiatedBackgroundProducer()) //바탕색 흰색 - Default
.addNoise() //한번 호출할 떄마다 하나의 라인이 추가된다. // .addNoise() //한번 호출할 떄마다 하나의 라인이 추가된다.
.gimp() //Gradiated 백그라운드 // .gimp() //Gradiated 백그라운드
// .gimp(new DropShadowGimpyRenderer()) //그림자 효과 추가 // // .gimp(new DropShadowGimpyRenderer()) //그림자 효과 추가
.addBorder() //검정 테두리 선 생성 // .addBorder() //검정 테두리 선 생성
.build(); //필수 호출 함수 // .build(); //필수 호출 함수
/* // /*
//
response.setHeader("Cache-Control", "no-store"); // response.setHeader("Cache-Control", "no-store");
response.setHeader("Pragma", "no-cache"); //브라우저 캐시 설정 // response.setHeader("Pragma", "no-cache"); //브라우저 캐시 설정
response.setDateHeader("Expires", 0); // response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg"); //리턴 컨텐츠타입 설정 // response.setContentType("image/jpeg"); //리턴 컨텐츠타입 설정
//
Capchas.net // Capchas.net
JCAPCHA // JCAPCHA
*/ // */
//
//image 생성 // //image 생성
CaptchaServletUtil.writeImage(response, captcha.getImage()); // CaptchaServletUtil.writeImage(response, captcha.getImage());
//image 문자 // //image 문자
// String captchaImgStr = captcha.getAnswer(); // // String captchaImgStr = captcha.getAnswer();
//
//요청세션에 저장 // //요청세션에 저장
request.getSession().setAttribute("captcha", captcha); // request.getSession().setAttribute("captcha", captcha);
} // }
//
public void getAudioCaptCha(HttpServletRequest req, HttpServletResponse res, String answer) throws IOException { // public void getAudioCaptCha(HttpServletRequest req, HttpServletResponse res, String answer) throws IOException {
HttpSession session = req.getSession(); // HttpSession session = req.getSession();
//
Captcha captcha = (Captcha) session.getAttribute(Captcha.NAME); // Captcha captcha = (Captcha) session.getAttribute(Captcha.NAME);
String getAnswer = answer; // String getAnswer = answer;
//
if(getAnswer == null || getAnswer.equals("")) getAnswer = captcha.getAnswer(); // if(getAnswer == null || getAnswer.equals("")) getAnswer = captcha.getAnswer();
//
AudioCaptcha audiocaptcha = new AudioCaptcha.Builder() // AudioCaptcha audiocaptcha = new AudioCaptcha.Builder()
.addAnswer(new SimpleCaptchaUtil.SetTextProducer(getAnswer)) // .addAnswer(new SimpleCaptchaUtil.SetTextProducer(getAnswer))
.addNoise() /*잡음 추가*/ // .addNoise() /*잡음 추가*/
.build(); // .build();
//
CaptchaServletUtil.writeAudio(res, audiocaptcha.getChallenge()); // CaptchaServletUtil.writeAudio(res, audiocaptcha.getChallenge());
} // }
//
} // }

@ -1,229 +1,229 @@
package kr.xit.framework.support.captcha; // package kr.xit.framework.support.captcha;
//
import kr.xit.framework.support.util.Checks; // import kr.xit.framework.support.util.Checks;
import nl.captcha.Captcha; // import nl.captcha.Captcha;
import nl.captcha.audio.AudioCaptcha; // import nl.captcha.audio.AudioCaptcha;
import nl.captcha.backgrounds.GradiatedBackgroundProducer; // import nl.captcha.backgrounds.GradiatedBackgroundProducer;
import nl.captcha.servlet.CaptchaServletUtil; // import nl.captcha.servlet.CaptchaServletUtil;
import nl.captcha.text.producer.TextProducer; // import nl.captcha.text.producer.TextProducer;
//
import javax.servlet.http.HttpServletRequest; // import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; // import javax.servlet.http.HttpServletResponse;
import java.awt.*; // import java.awt.*;
import java.util.Arrays; // import java.util.Arrays;
import java.util.Collections; // import java.util.Collections;
import java.util.List; // import java.util.List;
import java.util.Objects; // import java.util.Objects;
//
/** // /**
* @author Lim, Jong Uk (minuk926) // * @author Lim, Jong Uk (minuk926)
* @since 2021-11-30 // * @since 2021-11-30
*/ // */
public class SimpleCaptchaUtil { // public class SimpleCaptchaUtil {
//
private static final int WIDTH = 100; // private static final int WIDTH = 100;
private static final int HEIGHT = 30; // private static final int HEIGHT = 30;
private static final int FONT_SIZE = 20; // private static final int FONT_SIZE = 20;
//
//
/** // /**
* // *
* @param req // * @param req
* @param res // * @param res
*/ // */
public static void getImgCaptcha(final HttpServletRequest req, final HttpServletResponse res) { // public static void getImgCaptcha(final HttpServletRequest req, final HttpServletResponse res) {
int width = Objects.isNull(req.getParameter("width"))? WIDTH : Integer.parseInt(req.getParameter("width")); // int width = Objects.isNull(req.getParameter("width"))? WIDTH : Integer.parseInt(req.getParameter("width"));
int height = Objects.isNull(req.getParameter("height"))? HEIGHT : Integer.parseInt(req.getParameter("height")); // int height = Objects.isNull(req.getParameter("height"))? HEIGHT : Integer.parseInt(req.getParameter("height"));
//
List<Font> fonts = Arrays.asList( // List<Font> fonts = Arrays.asList(
new Font("", Font.HANGING_BASELINE, FONT_SIZE), // new Font("", Font.HANGING_BASELINE, FONT_SIZE),
new Font("Courier", Font.ITALIC, FONT_SIZE), // new Font("Courier", Font.ITALIC, FONT_SIZE),
new Font("", Font.PLAIN, FONT_SIZE) // new Font("", Font.PLAIN, FONT_SIZE)
); // );
List<Color> colors = Collections.singletonList(Color.BLACK); // List<Color> colors = Collections.singletonList(Color.BLACK);
//
Captcha captcha = // Captcha captcha =
new Captcha.Builder(150, 50) // new Captcha.Builder(150, 50)
.addText() // .addText()
//new Captcha.Builder(width, height) // //new Captcha.Builder(width, height)
//.addText(new NumbersAnswerProducer(5), new DefaultWordRenderer(colors, fonts)) // //.addText(new NumbersAnswerProducer(5), new DefaultWordRenderer(colors, fonts))
// 호출될때마다 라인 추가 // // 호출될때마다 라인 추가
.addNoise() // .addNoise()
.gimp() // .gimp()
// black border 생성 // // black border 생성
.addBorder() // .addBorder()
.addBackground(new GradiatedBackgroundProducer()) // .addBackground(new GradiatedBackgroundProducer())
.build(); // .build();
/* // /*
res.setHeader("Cache-Control", "no-cache"); // res.setHeader("Cache-Control", "no-cache");
res.setDateHeader("Expires", 0); // res.setDateHeader("Expires", 0);
res.setHeader("Pragma", "no-cache"); // res.setHeader("Pragma", "no-cache");
res.setDateHeader("Max-Age", 0); // res.setDateHeader("Max-Age", 0);
res.setContentType("image/png"); // res.setContentType("image/png");
*/ // */
CaptchaServletUtil.writeImage(res, captcha.getImage()); // CaptchaServletUtil.writeImage(res, captcha.getImage());
req.getSession().setAttribute(Captcha.NAME, captcha); // req.getSession().setAttribute(Captcha.NAME, captcha);
//req.getSession().setAttribute("captcha", captcha.getAnswer());// 값 저장 // //req.getSession().setAttribute("captcha", captcha.getAnswer());// 값 저장
} // }
//
/** // /**
* // *
* @param req // * @param req
* @param res // * @param res
* @param answer // * @param answer
*/ // */
public static void getAudioCaptcha(final HttpServletRequest req, final HttpServletResponse res, String answer) { // public static void getAudioCaptcha(final HttpServletRequest req, final HttpServletResponse res, String answer) {
//
if(Checks.isEmpty(answer)){ // if(Checks.isEmpty(answer)){
Captcha captcha = (Captcha) req.getSession().getAttribute(Captcha.NAME); // Captcha captcha = (Captcha) req.getSession().getAttribute(Captcha.NAME);
answer = captcha.getAnswer(); // answer = captcha.getAnswer();
} // }
//
AudioCaptcha audioCaptcha = new AudioCaptcha.Builder() // AudioCaptcha audioCaptcha = new AudioCaptcha.Builder()
.addAnswer(new SetTextProducer(answer)) // .addAnswer(new SetTextProducer(answer))
.addNoise() // .addNoise()
.build(); // .build();
//
CaptchaServletUtil.writeAudio(res, audioCaptcha.getChallenge()); // CaptchaServletUtil.writeAudio(res, audioCaptcha.getChallenge());
} // }
//
/** // /**
* // *
* @param req // * @param req
* @param res // * @param res
* @param ans // * @param ans
* @return // * @return
*/ // */
public static boolean isCorrect(final HttpServletRequest req, final HttpServletResponse res, String ans) { // public static boolean isCorrect(final HttpServletRequest req, final HttpServletResponse res, String ans) {
//
if(Checks.isEmpty(ans)) return false; // if(Checks.isEmpty(ans)) return false;
//
Captcha captcha = (Captcha) req.getSession().getAttribute(Captcha.NAME); // Captcha captcha = (Captcha) req.getSession().getAttribute(Captcha.NAME);
if(captcha != null && captcha.isCorrect(ans)){ // if(captcha != null && captcha.isCorrect(ans)){
req.getSession().removeAttribute(Captcha.NAME); // req.getSession().removeAttribute(Captcha.NAME);
return true; // return true;
} // }
return false; // return false;
/* // /*
String answer = (String)req.getSession().getAttribute("captcha"); // String answer = (String)req.getSession().getAttribute("captcha");
if(Objects.equals(ans, answer)) { // if(Objects.equals(ans, answer)) {
req.getSession().removeAttribute("captcha"); // req.getSession().removeAttribute("captcha");
return true; // return true;
} // }
return false; // return false;
*/ // */
//
} // }
//
public static class SetTextProducer implements TextProducer { // public static class SetTextProducer implements TextProducer {
private final String str; // private final String str;
//
public SetTextProducer(String answer){ // public SetTextProducer(String answer){
this.str = answer; // this.str = answer;
} // }
//
@Override // @Override
public String getText(){ // public String getText(){
return this.str; // return this.str;
} // }
} // }
} // }
//
//
/* // /*
//
//
@RequestMapping(method = RequestMethod.GET, value = "/captcha/image") // @RequestMapping(method = RequestMethod.GET, value = "/captcha/image")
public void getCaptchaImage(final HttpServletRequest req, final HttpServletResponse res) { // public void getCaptchaImage(final HttpServletRequest req, final HttpServletResponse res) {
SimpleCaptchaUtil // SimpleCaptchaUtil
.getImgCaptcha(req, res); // .getImgCaptcha(req, res);
//
//
} // }
//
@RequestMapping(method = RequestMethod.GET, value = "/captcha/audio") // @RequestMapping(method = RequestMethod.GET, value = "/captcha/audio")
public void getCaptchaAudio(final HttpServletRequest req, final HttpServletResponse res) { // public void getCaptchaAudio(final HttpServletRequest req, final HttpServletResponse res) {
SimpleCaptchaUtil.getAudioCaptcha(req, res, null); // SimpleCaptchaUtil.getAudioCaptcha(req, res, null);
//
//
} // }
//
@RequestMapping(method = RequestMethod.POST, value = "/captcha/check") // @RequestMapping(method = RequestMethod.POST, value = "/captcha/check")
@ResponseBody // @ResponseBody
public String isCorrect(final HttpServletRequest req, final HttpServletResponse res, String answer) { // public String isCorrect(final HttpServletRequest req, final HttpServletResponse res, String answer) {
//modelMap.addAttribute("OK", new SimpleCaptchaUtil().isCorrect(req, res, req.getParameter("answer"))); // //modelMap.addAttribute("OK", new SimpleCaptchaUtil().isCorrect(req, res, req.getParameter("answer")));
//
Gson gson = new GsonBuilder().create(); // Gson gson = new GsonBuilder().create();
return gson.toJson(SimpleCaptchaUtil.isCorrect(req, res, req.getParameter("answer"))); // return gson.toJson(SimpleCaptchaUtil.isCorrect(req, res, req.getParameter("answer")));
} // }
//
//
//
<tr> // <tr>
<th scope="row"><span class="ico_point"><span class="hide"></span>*</span><label for="captcha"></label></th> // <th scope="row"><span class="ico_point"><span class="hide">필수입력</span>*</span><label for="captcha">자동입력방지</label></th>
<td> // <td>
<img id="captchaImg" src="${wwwHost}/support/captcha/image" alt="보안문자를 입력해 주세요."> // <img id="captchaImg" src="${wwwHost}/support/captcha/image" alt="보안문자를 입력해 주세요.">
<div id="ccaudio" style="display:none"></div> // <div id="ccaudio" style="display:none"></div>
<input type="button" ng-click="mainCtrl.captchaReload()" id="reLoad" value="새로고침"> // <input type="button" ng-click="mainCtrl.captchaReload()" id="reLoad" value="새로고침">
<input type="button" ng-click="mainCtrl.audio()" id="soundOn" value="음성듣기"> // <input type="button" ng-click="mainCtrl.audio()" id="soundOn" value="음성듣기">
<input type="text" name="" id="captchaAns" class="" placeholder="보안문자 입력"> // <input type="text" name="" id="captchaAns" class="" placeholder="보안문자 입력">
<input type="button" ng-click="mainCtrl.captchaConfirm()" id="captchaConfirm" value="확인"> // <input type="button" ng-click="mainCtrl.captchaConfirm()" id="captchaConfirm" value="확인">
</td> // </td>
</tr> // </tr>
//
//
//
this.captchaReload = function(){ // this.captchaReload = function(){
const rand = Math.random(); // const rand = Math.random();
const url = '${wwwHost}/support/captcha/image?rand='+rand; // const url = '${wwwHost}/support/captcha/image?rand='+rand;
document.querySelector('#captchaImg').setAttribute('src', url); // document.querySelector('#captchaImg').setAttribute('src', url);
//
} // }
//
this.audio = function(){ // this.audio = function(){
const rand = Math.random(); // const rand = Math.random();
const uAgent = navigator.userAgent; // const uAgent = navigator.userAgent;
//
const url = '${wwwHost}/support/captcha/audio?rand='+rand; // const url = '${wwwHost}/support/captcha/audio?rand='+rand;
//
// IE // // IE
if(uAgent.indexOf('Trident') > -1 || uAgent.indexOf('MISE') > -1){ // if(uAgent.indexOf('Trident') > -1 || uAgent.indexOf('MISE') > -1){
document.querySelector('#ccaudio').innerHTML = '<bgsoun src="' + url + '">'; // document.querySelector('#ccaudio').innerHTML = '<bgsoun src="' + url + '">';
//
// Chrome // // Chrome
}else if(!!document.createElement('audio').canPlayType){ // }else if(!!document.createElement('audio').canPlayType){
try{ // try{
new Audio(url).play() // new Audio(url).play()
}catch (e){ // }catch (e){
document.querySelector('#ccaudio').innerHTML = '<bgsoun src="' + url + '">'; // document.querySelector('#ccaudio').innerHTML = '<bgsoun src="' + url + '">';
} // }
}else{ // }else{
window.open(url, '', 'width=1,height=1'); // window.open(url, '', 'width=1,height=1');
} // }
} // }
this.captchaConfirm = function(){ // this.captchaConfirm = function(){
const ans = document.querySelector('#captchaAns').value; // const ans = document.querySelector('#captchaAns').value;
if(!ans){ // if(!ans){
alert("보안문자를 입력해 주세요."); // alert("보안문자를 입력해 주세요.");
return true; // return true;
} // }
//
$http({ // $http({
method: 'POST', // method: 'POST',
url: '${wwwHost}/support/captcha/check', // url: '${wwwHost}/support/captcha/check',
data: {answer: ans} // data: {answer: ans}
}).success(function (data, status, headers, config) { // }).success(function (data, status, headers, config) {
if(data){ // if(data){
//
}else{ // }else{
alert(' .\n '); // alert('보안문자가 일치하지 않습니다.\n다시 입력해 주세요');
captchaReload(); // captchaReload();
} // }
//
}).error(function (data, status, headers, config) { // }).error(function (data, status, headers, config) {
alert(data.message); // alert(data.message);
}); // });
//
} // }
//
*/ // */

@ -160,7 +160,7 @@
$('#id').focus(); $('#id').focus();
CaptchaUtil.init(); //CaptchaUtil.init();
} }
@ -193,13 +193,13 @@
var CaptchaUtil = { var CaptchaUtil = {
init: function(){ init: function(){
//캡차인증 이미지 출력 //캡차인증 이미지 출력
CaptchaUtil.refresh(); //CaptchaUtil.refresh();
//새로고침 버튼 EventListener 설정 //새로고침 버튼 EventListener 설정
$('#btn_captchaRefresh').on({ $('#btn_captchaRefresh').on({
click: function(){ click: function(){
CaptchaUtil.refresh(); //CaptchaUtil.refresh();
return false; return false;
} }

Loading…
Cancel
Save