From fd4cd788d973ae117f7ba9c9683e97cdc7204a3f Mon Sep 17 00:00:00 2001 From: "taylor.dang" Date: Thu, 16 Aug 2018 17:22:31 +0800 Subject: [PATCH] compare --- .../citypartner/beans/CityPartnerBean.java | 9 +++++++ .../web/CityPartnerRegisterController.java | 27 ++++++++++++------- .../manage/mappers/bill/BillMapper.xml | 2 +- src/main/ui/citypartner_register.html | 17 +++++++++--- 4 files changed, 42 insertions(+), 13 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 e78b879b0..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,17 +1,14 @@ 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 au.com.royalpay.payment.tools.exceptions.ForbiddenException; +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 au.com.royalpay.payment.tools.secure.ApplyRequest; import org.springframework.validation.Errors; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; /** @@ -22,10 +19,22 @@ import javax.validation.Valid; public class CityPartnerRegisterController { @Resource private CityPartnerRegisterService cityPartnerRegisterService; + @Resource + private ClientApply clientApply; @RequestMapping(method = RequestMethod.POST) - @ApplyRequest - public void register(@RequestBody @Valid CityPartnerBean partner, Errors errors) { + 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/resources/au/com/royalpay/payment/manage/mappers/bill/BillMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/bill/BillMapper.xml index 6870d79df..a213ff20d 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/bill/BillMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/bill/BillMapper.xml @@ -3,7 +3,7 @@