From f416d0800f2b32570ac1b8408edacbd9de3e2241 Mon Sep 17 00:00:00 2001 From: yangkai Date: Tue, 14 Aug 2018 15:43:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=AA=8C=E8=AF=81=E7=A0=81?= =?UTF-8?q?=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../citypartner/beans/CityPartnerBean.java | 9 +++++ .../web/CityPartnerRegisterController.java | 34 ++++++++++++++----- src/main/ui/citypartner_register.html | 17 ++++++++-- 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/citypartner/beans/CityPartnerBean.java b/src/main/java/au/com/royalpay/payment/manage/citypartner/beans/CityPartnerBean.java index fcffc6fa0..043f5814d 100644 --- a/src/main/java/au/com/royalpay/payment/manage/citypartner/beans/CityPartnerBean.java +++ b/src/main/java/au/com/royalpay/payment/manage/citypartner/beans/CityPartnerBean.java @@ -22,6 +22,7 @@ public class CityPartnerBean { @NotBlank(message = "error.payment.valid.param_missing") @Length(max = 30) private String phone; + private String captcha; public JSONObject toJSON(){ return (JSONObject) JSONObject.toJSON(this); @@ -58,4 +59,12 @@ public class CityPartnerBean { public void setPhone(String phone) { this.phone = phone; } + + public String getCaptcha() { + return captcha; + } + + public void setCaptcha(String captcha) { + this.captcha = captcha; + } } diff --git a/src/main/java/au/com/royalpay/payment/manage/citypartner/web/CityPartnerRegisterController.java b/src/main/java/au/com/royalpay/payment/manage/citypartner/web/CityPartnerRegisterController.java index 6547049bd..d96cd5474 100644 --- a/src/main/java/au/com/royalpay/payment/manage/citypartner/web/CityPartnerRegisterController.java +++ b/src/main/java/au/com/royalpay/payment/manage/citypartner/web/CityPartnerRegisterController.java @@ -1,10 +1,15 @@ package au.com.royalpay.payment.manage.citypartner.web; +import au.com.royalpay.payment.manage.citypartner.beans.CityPartnerBean; import au.com.royalpay.payment.manage.citypartner.core.CityPartnerRegisterService; - -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import au.com.royalpay.payment.manage.merchants.core.ClientApply; +import au.com.royalpay.payment.tools.CommonConsts; +import au.com.royalpay.payment.tools.http.HttpUtils; +import org.springframework.validation.Errors; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; /** * Created by yixian on 2017-01-23. @@ -14,10 +19,23 @@ import javax.annotation.Resource; public class CityPartnerRegisterController { @Resource private CityPartnerRegisterService cityPartnerRegisterService; + @Resource + private ClientApply clientApply; -// @RequestMapping(method = RequestMethod.POST) -// public void register(@RequestBody @Valid CityPartnerBean partner, Errors errors) { -// HttpUtils.handleValidErrors(errors); -// cityPartnerRegisterService.saveRegistry(partner); -// } + @RequestMapping(method = RequestMethod.POST) + public void register(@CookieValue(CommonConsts.CODE_KEY) String codeKey, HttpServletResponse response, + @RequestBody @Valid CityPartnerBean partner, Errors errors) throws Exception{ + String codeValue = clientApply.getVerifyCode(codeKey); + if (codeValue == null) { + throw new Exception("Verification code has expired"); + } + if (!codeValue.equals(partner.getCaptcha())){ + throw new Exception("Verification code is not correct"); + }else { + clientApply.deleteVerifyCodeKey(codeKey); + HttpUtils.dropCookie(response, CommonConsts.CODE_KEY); + } + HttpUtils.handleValidErrors(errors); + cityPartnerRegisterService.saveRegistry(partner); + } } diff --git a/src/main/ui/citypartner_register.html b/src/main/ui/citypartner_register.html index ba9a34360..372b3b8ee 100644 --- a/src/main/ui/citypartner_register.html +++ b/src/main/ui/citypartner_register.html @@ -139,13 +139,17 @@ }, error: function (jqXHR) { alert(JSON.parse(jqXHR.responseText).message); - $submit.removeAttr('disabled') + $("#kaptcha").attr("src", "/partners/application/captcha-image?" + Math.floor(Math.random() * 100)); + $submit.removeAttr('disabled'); } }); $submit.attr('disabled', 'disabled'); return false; - }) - }) + }); + $('#kaptcha').click(function () { + $(this).attr("src", "/partners/application/captcha-image?" + Math.floor(Math.random() * 100)); + }); + });