From a4fb42ef4b9d9b7f0f13feb64922261db941fb45 Mon Sep 17 00:00:00 2001 From: "eason.qian" Date: Tue, 22 May 2018 17:15:19 +0800 Subject: [PATCH] fix --- .../core/SimpleClientApplyService.java | 14 ++++++++ .../web/SimpleClientApplyController.java | 33 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/main/java/au/com/royalpay/payment/manage/application/core/SimpleClientApplyService.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/application/web/SimpleClientApplyController.java diff --git a/src/main/java/au/com/royalpay/payment/manage/application/core/SimpleClientApplyService.java b/src/main/java/au/com/royalpay/payment/manage/application/core/SimpleClientApplyService.java new file mode 100644 index 000000000..008d754c4 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/application/core/SimpleClientApplyService.java @@ -0,0 +1,14 @@ +package au.com.royalpay.payment.manage.application.core; + +import au.com.royalpay.payment.manage.merchants.beans.NewAccountBean; +import com.alibaba.fastjson.JSONObject; + +public interface SimpleClientApplyService { + String getSMSVerifyCode(String codeKey); + + JSONObject newAccount(NewAccountBean accountBean); + + void deleteSMSVerifyCodeKey(String codeKey); + + String partnerSignIn(JSONObject account); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/application/web/SimpleClientApplyController.java b/src/main/java/au/com/royalpay/payment/manage/application/web/SimpleClientApplyController.java new file mode 100644 index 000000000..1a8a47e00 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/application/web/SimpleClientApplyController.java @@ -0,0 +1,33 @@ +package au.com.royalpay.payment.manage.application.web; + +import au.com.royalpay.payment.manage.application.core.SimpleClientApplyService; +import au.com.royalpay.payment.manage.merchants.beans.NewAccountBean; +import au.com.royalpay.payment.tools.CommonConsts; +import au.com.royalpay.payment.tools.http.HttpUtils; +import com.alibaba.fastjson.JSONObject; +import org.springframework.validation.Errors; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; + +@RestController +@RequestMapping("/register") +public class SimpleClientApplyController { + @Resource + private SimpleClientApplyService simpleClientApplyService; + + @RequestMapping(value = "/account/{codeKey}", method = RequestMethod.POST) + public void registerAccount(@PathVariable String codeKey, @RequestBody @Valid NewAccountBean accountBean, Errors errors, HttpServletResponse response) throws Exception { + HttpUtils.handleValidErrors(errors); + String codeValue = simpleClientApplyService.getSMSVerifyCode(codeKey); + if (codeValue == null || !codeValue.equals(accountBean.getUsername())) { + throw new Exception("Verification code has expired or is not correct"); + } + JSONObject account = simpleClientApplyService.newAccount(accountBean); + simpleClientApplyService.deleteSMSVerifyCodeKey(codeKey); + String statusKey = simpleClientApplyService.partnerSignIn(account); + HttpUtils.setCookie(response, CommonConsts.CODE_KEY, statusKey); + } +}