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); + } +}