wangning 7 years ago
parent 543964051b
commit 1842e10bb3

@ -4,17 +4,22 @@ import au.com.royalpay.payment.manage.merchants.beans.NewAccountBean;
import com.alibaba.fastjson.JSONObject;
public interface SimpleClientApplyService {
void verifyRegisterSMSCode(String codeKey, String accountName);
void verifyRegisterSMSCode(String codeKey, String phoneNumber);
JSONObject newAccount(NewAccountBean accountBean);
void deleteSMSVerifyCodeKey(String codeKey);
String partnerSignIn(JSONObject account);
String getSmsCodeAndSend(String phoneNumber,String nationCode,String accountName);
String getAndSendSmsCode(String phoneNumber, String nationCode);
String checkOrGenerateRegisterProcessKey(String accountName, String codeKey);
void deleteRegisterProcessKey(String codeKey);
void sendVerifyEmail(String address, int client_id);
String checkOrGenerateVerifyMailKey(String address, String codeKey);
void sendVerifyEmail(String address,JSONObject client);
void deleteVerifyMailKey(String codeKey);
String generateRegisterProcessKey(String accountName);
}

@ -1,29 +1,34 @@
package au.com.royalpay.payment.manage.application.core.impls;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import au.com.royalpay.payment.manage.application.core.SimpleClientApplyService;
import au.com.royalpay.payment.manage.merchants.beans.NewAccountBean;
import au.com.royalpay.payment.manage.merchants.core.ClientManager;
import au.com.royalpay.payment.manage.system.core.MailGunService;
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
import au.com.royalpay.payment.tools.env.SysConfigManager;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
import au.com.royalpay.payment.tools.mail.SendMail;
import au.com.royalpay.payment.tools.utils.sms.SmsSingleSender;
import javax.annotation.Resource;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.util.Assert;
import org.thymeleaf.context.Context;
import org.thymeleaf.spring4.SpringTemplateEngine;
import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import au.com.royalpay.payment.manage.application.core.SimpleClientApplyService;
import au.com.royalpay.payment.manage.merchants.beans.NewAccountBean;
import au.com.royalpay.payment.manage.system.core.MailGunService;
import au.com.royalpay.payment.tools.env.SysConfigManager;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
import au.com.royalpay.payment.tools.mail.SendMail;
import au.com.royalpay.payment.tools.utils.sms.SmsSingleSender;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
@ -37,23 +42,31 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
private MailGunService mailGunService;
@Resource
private SpringTemplateEngine thymeleaf;
@Resource
private ClientManager clientManager;
@Resource
private StringRedisTemplate stringRedisTemplate;
private final SmsSingleSender smsSingleSender = new SmsSingleSender(appId, appKey);
private final int REGISTER_CLIENT_TEMPLID = 126008;
private final String REGISTER_CLIENT_PREFIX = "REGISTER_CLIENT";
private final String REGISTER_CLIENT_PHONE_EXPIRE_PREFIX = "REGISTER_CLIENT_PHONE_EXPIRE";
private final String REGISTER_CLIENT_PROCESS_PREFIX = "REGISTER_CLIENT_PROCESS";
private final String VERIFY_MAIL_PREFIX = "VERIFY_MAIL";
private final List<String> tags = new ArrayList<>();
@PostConstruct
public void init(){
tags.add("account");
}
@Override
public void verifyRegisterSMSCode(String codeKey,String accountName) {
String rediskey = getRegisterClientRedisKey(accountName);
public void verifyRegisterSMSCode(String codeKey,String phoneNumber) {
String rediskey = getRegisterClientRedisKey(phoneNumber);
String codeValue = stringRedisTemplate.boundValueOps(rediskey).get();
if (codeValue == null || !codeValue.equals(codeKey)) {
throw new BadRequestException("Verification code has expired or is not correct");
}
stringRedisTemplate.delete(rediskey);
// stringRedisTemplate.delete(getRegisterClientPhoneExpireRedisKey(phoneNumber));
}
@Override
@ -61,19 +74,14 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
return null;
}
@Override
public void deleteSMSVerifyCodeKey(String codeKey) {
}
@Override
public String partnerSignIn(JSONObject account) {
return null;
}
@Override
public String getSmsCodeAndSend(String phoneNumber, String nationCode,String accountName) {
String reidsCheckCodeKey = getRegisterClientPhoneExpireRedisKey(phoneNumber);
public String getAndSendSmsCode(String phoneNumber, String nationCode) {
String reidsCheckCodeKey = getRegisterClientRedisKey(phoneNumber);
String value = stringRedisTemplate.boundValueOps(reidsCheckCodeKey).get();
if (StringUtils.isNotEmpty(value)) {
throw new BadRequestException("SMS has been sentPlease check your messages or try again in 3 minutes.");
@ -81,7 +89,6 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
JSONObject sysConfig = sysConfigManager.getSysConfig();
ArrayList<String> param = new ArrayList<>();
String registerClientKey = getRegisterClientRedisKey(accountName);
String registerClientCode = RandomStringUtils.random(6, true, true);
param.add(registerClientCode);
String expireMin = (String) sysConfig.getOrDefault("sms.verification.code.expire", 3);
@ -91,19 +98,20 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
} catch (Exception e) {
throw new ServerErrorException("System Error");
}
stringRedisTemplate.boundValueOps(registerClientKey).set(registerClientCode, Long.parseLong(expireMin), TimeUnit.MINUTES);
stringRedisTemplate.boundValueOps(reidsCheckCodeKey).set(reidsCheckCodeKey, Long.parseLong(expireMin), TimeUnit.MINUTES);
stringRedisTemplate.boundValueOps(getRegisterClientRedisKey(phoneNumber)).set(registerClientCode,Long.parseLong(expireMin), TimeUnit.MINUTES);
return registerClientCode;
}
@Override
public void sendVerifyEmail(String address,JSONObject client) {
public void sendVerifyEmail(String address,int client_id) {
JSONObject client= clientManager.getClientInfo(client_id);
if(client==null){
throw new BadRequestException("Merchant not found");
}
String key = checkOrGenerateVerifyMailKey(address,null);
Context ctx = new Context();
ctx.setVariable("url", url);
ctx.setVariable("url", PlatformEnvironment.getEnv().concatUrl("/register/account/mail/"+address+"/verify/" + key+"/jump"));
final String content = thymeleaf.process("mail/register_application", ctx);
SendMail sendMail = new SendMail();
Set<String> to = new HashSet<>();
to.add(address);
@ -113,18 +121,59 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService {
sendMail.setContent(content);
sendMail.setTags(tags);
mailGunService.sendMail(sendMail);
}
@Override
public String generateRegisterProcessKey(String accountName) {
public String checkOrGenerateRegisterProcessKey(String accountName, String codeKey) {
Assert.notNull(accountName,"accountName can't be null");
if(StringUtils.isNotEmpty(codeKey)){
String redisAccountName = stringRedisTemplate.boundValueOps(getRegisterClientProcessRedisKey(codeKey)).get();
if(!accountName.equals(redisAccountName)){
throw new BadRequestException("Data error,Please re-register for safety.");
}else {
return codeKey;
}
}
String key = RandomStringUtils.random(10, true, false);
stringRedisTemplate.boundValueOps(getRegisterClientProcessRedisKey(key)).set(accountName,1,TimeUnit.HOURS);
return key;
}
return null;
@Override
public void deleteRegisterProcessKey(String codeKey) {
stringRedisTemplate.delete(getRegisterClientProcessRedisKey(codeKey));
}
private String getRegisterClientRedisKey(String accountName){
return REGISTER_CLIENT_PREFIX +accountName;
@Override
public String checkOrGenerateVerifyMailKey(String address, String codeKey){
Assert.notNull(address,"address can't be null");
if(StringUtils.isNotEmpty(codeKey)){
String redisAddress = stringRedisTemplate.boundValueOps(getVerifyMailRedisKey(codeKey)).get();
if(!address.equals(redisAddress)){
throw new BadRequestException("Data error");
}else {
return codeKey;
}
}
String key = RandomStringUtils.random(10, true, false);
stringRedisTemplate.boundValueOps(getRegisterClientProcessRedisKey(key)).set(address,1,TimeUnit.HOURS);
return key;
}
@Override
public void deleteVerifyMailKey(String codeKey) {
stringRedisTemplate.delete(getVerifyMailRedisKey(codeKey));
}
private String getRegisterClientRedisKey(String phoneNumber){
return REGISTER_CLIENT_PREFIX +phoneNumber;
}
private String getRegisterClientProcessRedisKey(String codeKey){
return REGISTER_CLIENT_PROCESS_PREFIX+codeKey;
}
private String getRegisterClientPhoneExpireRedisKey(String phoneNumber){
return REGISTER_CLIENT_PHONE_EXPIRE_PREFIX +phoneNumber;
private String getVerifyMailRedisKey(String codekey){
return VERIFY_MAIL_PREFIX+codekey;
}
}

@ -4,42 +4,58 @@ 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.stereotype.Controller;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
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.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
@RestController
@Controller
@RequestMapping("/register")
public class SimpleClientApplyController {
@Resource
private SimpleClientApplyService simpleClientApplyService;
@Resource
@RequestMapping(value = "/account/{codeKey}", method = RequestMethod.POST)
@ResponseBody
public void registerAccount(@PathVariable String codeKey, @RequestBody @Valid NewAccountBean accountBean, Errors errors, HttpServletResponse response)
throws Exception {
HttpUtils.handleValidErrors(errors);
simpleClientApplyService.verifyRegisterSMSCode(codeKey,accountBean.getUsername());
simpleClientApplyService.verifyRegisterSMSCode(codeKey,accountBean.getContactPhone());
JSONObject account = simpleClientApplyService.newAccount(accountBean);
simpleClientApplyService.deleteSMSVerifyCodeKey(codeKey);
String statusKey = simpleClientApplyService.partnerSignIn(account);
HttpUtils.setCookie(response, CommonConsts.CODE_KEY, statusKey);
}
// @RequestMapping(value = "/account/mail/verify", method = RequestMethod.GET)
// public void registerAccount(@PathVariable String codeKey, @RequestBody @Valid NewAccountBean accountBean, Errors errors, HttpServletResponse response)
// throws Exception {
// HttpUtils.handleValidErrors(errors);
// simpleClientApplyService.verifyRegisterSMSCode(codeKey, accountBean.getContactPhone());
//
// JSONObject account = simpleClientApplyService.newAccount(accountBean);
// simpleClientApplyService.deleteSMSVerifyCodeKey(codeKey);
// String statusKey = simpleClientApplyService.partnerSignIn(account);
// HttpUtils.setCookie(response, CommonConsts.CODE_KEY, statusKey);
// }
@RequestMapping(value = "/account/mail/{address}/verify/{codeKey}/jump", method = RequestMethod.GET)
public ModelAndView jumpVerifyMail(@PathVariable String codeKey, @PathVariable String address){
simpleClientApplyService.checkOrGenerateVerifyMailKey(address,codeKey);
ModelAndView view = new ModelAndView("verify_mail");
view.addObject("codeKey", codeKey);
return view;
}
@RequestMapping(value = "/account/mail/{address}/verify/{codeKey}", method = RequestMethod.POST)
@ResponseBody
public void verifyMail(@PathVariable String codeKey, @PathVariable String address,@RequestBody JSONObject account){
simpleClientApplyService.checkOrGenerateVerifyMailKey(address,codeKey);
ModelAndView view = new ModelAndView("verify_mail");
view.addObject("codeKey", codeKey);
simpleClientApplyService.deleteVerifyMailKey(codeKey);
}
}

@ -0,0 +1,158 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>RoyalPay | Reset Password</title>
<link rel="apple-touch-icon" sizes="57x57" href="ico/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="ico/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="ico/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="ico/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="ico/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="ico/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="ico/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="ico/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="ico/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="ico/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="ico/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="ico/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="ico/favicon-16x16.png">
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Bootstrap 3.3.5 -->
<link href="static/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Font Awesome -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<!-- Ionicons -->
<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<!-- Theme style -->
<link rel="stylesheet" href="./static/lib/dist/css/AdminLTE.min.css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<style type="text/css">
#bg {
display: block;
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
background-color: black;
z-index: 1001;
-moz-opacity: 0.7;
opacity: .70;
filter: alpha(opacity=70);
}
#show {
display: block;
position: absolute;
top: 50%;
left: 40%;
width: 20%;
padding: 8px;
z-index: 1002;
overflow: auto;
}
</style>
</head>
<body class="hold-transition login-page">
<div class="login-box">
<div class="login-logo">
<p><img src="static/images/rp_logo.svg" style="width:45%"></p>
<a href="index.html"><b>RoyalPay</b></a>
</div>
<!-- /.login-logo -->
<div class="login-box-body">
<p class="login-box-msg">Verify Your Mail</p>
<form action="" method="post">
<div class="form-group has-feedback">
<input type="text" id="userName" class="form-control" placeholder="User Names">
<span class="glyphicon glyphicon-user form-control-feedback"></span>
</div>
<div class="row">
<div class="form-group col-xs-12">
<input type="text" name="codeKey" class="form-control" style="width: 70%;display: inline"
id="codeKey" placeholder="Verification Code">
<img style="width:30%;display:inline;height: 34px;float: right" id="email-kaptcha"
src="/global/userstatus/captcha-login"
title="点击更换"/>
</div>
<div class="col-xs-12 margin-bottom">
<button type="button" id="submitEmail-btn" class="btn btn-success btn-block btn-flat">Submit</button>
</div>
</div>
<p style="font-size: smaller">
文案修改 We need your partner code to confirm your identity information, please enter it. (Your partner code is the same as the first four letters of your order ID.)
</p>
</form>
</div>
<!-- /.login-box-body -->
</div>
<!-- /.login-box -->
<script src="static/lib/jquery/jquery-2.1.4.min.js"></script>
<!-- Bootstrap 3.3.5 -->
<script src="static/lib/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" data-th-inline="javascript">
$(document).ready(function () {
$('input').keypress(function (evt) {
if (evt.keyCode == 13) {
$('#login-btn').click();
}
});
$('#submitEmail-btn').click(function () {
var userName = $('#userName').val();
if (userName == null || userName.length == 0) {
alert('请输入用户名');
return;
}
var verifyCode = $('#email—verifyCode').val();
if (verifyCode == null || verifyCode.length == 0) {
alert('请填写验证码');
return;
}
$("#bg").show();
$("#show").show();
$.ajax({
url: '/register/account/mail/'+,
method: 'GET',
contentType: 'application/json',
dataType: 'text',
success: function (resp) {
$("#bg").hide();
$("#show").hide();
alert("Reset password email has send your mailbox:"+resp);
location.href = 'index.html'
},
error: function (jqXHR) {
$("#bg").hide();
$("#show").hide();
alert(JSON.parse(jqXHR.responseText).message);
$('#email-kaptcha').attr("src", "/global/userstatus/captcha-login?" + Math.floor(Math.random() * 100));
}
})
})
})
</script>
<div id="bg" style="display: none"></div>
<div id="show" style="display: none">
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="45" aria-valuemin="0"
aria-valuemax="100" style="width: 100%">
<span class="sr-only">Requesting...</span>
</div>
</div>
</div>
</body>
</html>
Loading…
Cancel
Save