提交 f34af437 编写于 作者: F fucan1017

注册功能

上级 72785110
......@@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class StringUtils {
......@@ -479,4 +480,42 @@ public final class StringUtils {
}
return null;
}
/**
* 验证是否为正确的邮箱号
*
* @param email
* @return
*/
public static boolean isValidEmail(String email) {
// 1、\\w+表示@之前至少要输入一个匹配字母或数字或下划线 \\w 单词字符:[a-zA-Z_0-9]
// 2、(\\w+\\.)表示域名. 如新浪邮箱域名是sina.com.cn
// {1,3}表示可以出现一次或两次或者三次.
String reg = "\\w+@(\\w+\\.){1,3}\\w+";
Pattern pattern = Pattern.compile(reg);
boolean flag = false;
if (email != null) {
Matcher matcher = pattern.matcher(email);
flag = matcher.matches();
}
return flag;
}
/**
* 验证是否为手机号
*
* @param mobileNo
* @return
*/
public static boolean isValidMobileNo(String mobileNo) {
// 1、(13[0-9])|(15[02789])|(18[679])|(17[0-9]) 13段 或者15段 18段17段的匹配
// 2、\\d{8} 整数出现8次
boolean flag = false;
Pattern p = Pattern.compile("^((13[0-9])|(14[0-9])|(15[0-9])|(16[0-9])|(17[0-9])|(18[0-9])|(19[0-9]))\\d{8}$");
Matcher match = p.matcher(mobileNo);
if (mobileNo != null) {
flag = match.matches();
}
return flag;
}
}
......@@ -60,7 +60,7 @@ public interface UserInfoMapper extends IJpaBaseMapper<UserInfo>{
public int updateProfile(UserInfo userInfo);
@Select("SELECT * FROM USERINFO WHERE EMAIL = #{value} OR MOBILE= #{value}")
@Select("SELECT * FROM MXK_USERINFO WHERE EMAIL = #{value} OR MOBILE= #{value}")
public UserInfo queryUserInfoByEmailMobile(String emailMobile);
}
......@@ -31,12 +31,15 @@ import org.maxkey.authn.support.rememberme.AbstractRemeberMeService;
import org.maxkey.authn.support.socialsignon.service.SocialSignOnProviderService;
import org.maxkey.authn.support.wsfederation.WsFederationConstants;
import org.maxkey.configuration.ApplicationConfig;
import org.maxkey.constants.ConstantsOperateMessage;
import org.maxkey.constants.ConstantsStatus;
import org.maxkey.crypto.password.opt.AbstractOptAuthn;
import org.maxkey.domain.UserInfo;
import org.maxkey.persistence.service.UserInfoService;
import org.maxkey.util.StringUtils;
import org.maxkey.web.WebConstants;
import org.maxkey.web.WebContext;
import org.maxkey.web.message.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -222,4 +225,51 @@ public class LoginEndpoint {
return "fail";
}
/**
* view register
* @return
*/
@RequestMapping(value={"/register"})
public ModelAndView register(HttpServletRequest request,HttpServletResponse response) {
_logger.debug("LoginController /register.");
ModelAndView modelAndView = new ModelAndView("registration/register");
Object loginErrorMessage=WebContext.getAttribute(WebConstants.LOGIN_ERROR_SESSION_MESSAGE);
modelAndView.addObject("loginErrorMessage", loginErrorMessage==null?"":loginErrorMessage);
WebContext.removeAttribute(WebConstants.LOGIN_ERROR_SESSION_MESSAGE);
return modelAndView;
}
@RequestMapping(value={"/registeron"})
@ResponseBody
public Message registeron(UserInfo userInfo,@RequestParam String emailMobile) throws ServletException, IOException {
if(StringUtils.isNullOrBlank(emailMobile)) {
return new Message(WebContext.getI18nValue("register.emailMobile.error"),"1");
}
if(StringUtils.isValidEmail(emailMobile)) {
userInfo.setEmail(emailMobile);
}
if(StringUtils.isValidMobileNo(emailMobile)) {
userInfo.setMobile(emailMobile);
}
if(!(StringUtils.isValidEmail(emailMobile)||StringUtils.isValidMobileNo(emailMobile))) {
return new Message(WebContext.getI18nValue("register.emailMobile.error"),"1");
}
UserInfo temp=userInfoService.queryUserInfoByEmailMobile(emailMobile);
if(temp!=null) {
return new Message(WebContext.getI18nValue("register.emailMobile.exist"),"1");
}
temp=userInfoService.loadByUsername(userInfo.getUsername());
if(temp!=null) {
return new Message(WebContext.getI18nValue("register.user.error"),"1");
}
userInfo.setStatus(ConstantsStatus.ACTIVE);
if(userInfoService.insert(userInfo)) {
return new Message(WebContext.getI18nValue("login.text.register.success"),"0");
}
return new Message(WebContext.getI18nValue("login.text.register.error"),"1");
}
}
......@@ -53,6 +53,11 @@ login.button.login=\u767b\u5f55
login.text.currenttime=\u65f6&nbsp;&nbsp;&nbsp;&nbsp;\u95f4
login.text.otherlogins=\u5176\u4ed6\u767b\u5f55\u65b9\u5f0f
login.text.register=\u7528\u6237\u6ce8\u518c
login.text.register.success=\u6ce8\u518c\u6210\u529f
login.text.register.error=\u6ce8\u518c\u5931\u8d25\u000d\u000a
register.user.error=\u767B\u9646\u8D26\u53F7\u5DF2\u5B58\u5728
register.emailMobile.error=\u90AE\u7BB1\u6216\u624B\u673A\u683C\u5F0F\u9519\u8BEF
register.emailMobile.exist=\u90AE\u7BB1\u6216\u624B\u673A\u5DF2\u5B58\u5728
login.password.expired=\u5bc6\u7801\u8fc7\u671f
login.password.expired.tip=\u5bc6\u7801\u8fc7\u671f\uff0c\u8bf7\u4fee\u6539\u5bc6\u7801
......
......@@ -53,6 +53,11 @@ login.button.login=Login
login.text.currenttime=CurrentTime
login.text.otherlogins=OtherLogins
login.text.register=Register
login.text.register.success=Register successful
login.text.register.error=Register error
register.user.error=username exist
register.emailMobile.error=email or mobile error
register.emailMobile.exist=email or mobile exist
login.password.expired=Password Expired
login.password.expired.tip=Password expired, please change password
......
......@@ -53,6 +53,11 @@ login.button.login=\u767b\u5f55
login.text.currenttime=\u65f6&nbsp;&nbsp;&nbsp;&nbsp;\u95f4
login.text.otherlogins=\u5176\u4ed6\u767b\u5f55\u65b9\u5f0f
login.text.register=\u7528\u6237\u6ce8\u518c
login.text.register.success=\u6ce8\u518c\u6210\u529f
login.text.register.error=\u6ce8\u518c\u5931\u8d25\u000d\u000a
register.user.error=\u767B\u9646\u8D26\u53F7\u5DF2\u5B58\u5728
register.emailMobile.error=\u90AE\u7BB1\u6216\u624B\u673A\u683C\u5F0F\u9519\u8BEF
register.emailMobile.exist=\u90AE\u7BB1\u6216\u624B\u673A\u5DF2\u5B58\u5728
login.password.expired=\u5bc6\u7801\u8fc7\u671f
login.password.expired.tip=\u5bc6\u7801\u8fc7\u671f\uff0c\u8bf7\u4fee\u6539\u5bc6\u7801
......
......@@ -168,6 +168,9 @@ $(function(){
<#--todo:send captcha-->
captchaCountTimer=setInterval("getCaptchaCount()", 1000);
});
$('#register').on('click',function(){
window.location.href="<@base />/register";
});
});
</script>
......
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<@base/>">
<title>My JSP 'register.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<#include "../layout/header.ftl">
<#include "../layout/common.cssjs.ftl">
<script type="text/javascript">
$(function(){
</head>
<body>
$('#j_captchaimg').click(function () {//
$(this).attr("src", "<@base />/captcha");
});
$('#btn_save').on('click',function(){
if($('#emailMobile').val()==''){
alert('<@locale code="forgotpassword.emailmobile"/>'+': empty');
return false;
}
if($('#username').val()==''){
alert('<@locale code="userinfo.username"/>'+': empty');
return false;
}
if($('#displayName').val()==''){
alert('<@locale code="userinfo.displayName"/>'+': empty');
return false;
}
if($('#password').val()==''){
alert('<@locale code="login.text.password"/>'+': empty');
return false;
}
if($('#confirmpassword').val()==''){
alert('<@locale code="login.password.confirmPassword"/>'+': empty');
return false;
}
if($('#password').val()!=$('#confirmpassword').val()){
alert('<@locale code="login.password.confirmPassword"/>'+''+'<@locale code="login.text.password"/>'+': error');
return false;
}
formSubmit();
})
function formSubmit(){
var uname=$('#username').val();
var pwd=$('#password').val();
var eMobile=$('#emailMobile').val();
var dName=$('#displayName').val();
$.ajax({
type:"POST",
url:"<@base/>/registeron",
data:{
username:uname,
password:pwd,
emailMobile:eMobile,
displayName:dName
},
success:function(data){
if(data.code=='0'){
alert(data.message);
window.location.href="<@base/>/login";
}else{
alert(data.message);
}
},
error:function(jqXHR){
alert("error:"+ jqXHR.status);
}
});
}
});
</script>
</head>
<body >
<div id="top">
<#include "../layout/nologintop.ftl">
</div>
<div class="container">
<table border="0" style="width:100%;">
<tr>
<td width="630px">
</td>
<td>
<form action="<@base />/registration/register" method="post">
<table class="datatable">
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8">
<form action="<@base/>/register.do" method="post" class="needs-validation" novalidate>
<table class="table table-bordered">
<tr>
<td><@locale code="register.lastname"/></td>
<td><input type='text' id="lastName" name="lastName" value="" /></td>
<td><@locale code="forgotpassword.emailmobile"/></td>
<td><input required="" type="text" id="emailMobile" name="emailMobile" class="form-control" title="" value=""/></td>
</tr>
<tr>
<td><@locale code="register.firstname"/></td>
<td><input type='text' id="firstName" name="firstName" value="" /></td>
<td><@locale code="login.text.captcha"/></td>
<td><input required="" class="form-control" type='text' id="j_captcha" name="captcha" tabindex="3" value="" style="float: left;"/><img id="j_captchaimg" src="<@base/>/captcha"/></td>
</tr>
<tr>
<td><@locale code="register.workemail"/></td>
<td><input type='text' id="workEmail" name="workEmail" value="" /></td>
<td><@locale code="userinfo.displayName"/></td>
<td><input required="" class="form-control" type='text' id='displayName' name='displayName' tabindex="1"/></td>
</tr>
<tr>
<td><@locale code="register.company"/></td>
<td><input type='text' id="company" name="company" value="" /></td>
<td><@locale code="userinfo.username"/></td>
<td><input required="" class="form-control" type='text' id='username' name='username' tabindex="1"/></td>
</tr>
<tr>
<td><@locale code="register.workphone"/></td>
<td><input type='text' id="workPhone" name="workPhone" value="" /></td>
</tr>
<tr style="display:none">
<td><@locale code="register.users"/></td>
<td><input type='text' id="users" name="users" value="0" /></td>
<td><@locale code="login.text.password"/></td>
<td><input required="" class="form-control" type='password' id="password" name="password" tabindex="1" value="" /></td>
</tr>
<tr>
<td colspan="2"><input id="registerBtn" class="button" type="submit" value="<@locale code="register.button.register" />"/></td>
<td><@locale code="login.password.confirmPassword"/></td>
<td><input required="" class="form-control" type='password' id="confirmpassword" name="confirmpassword" tabindex="2" value="" /></td>
</tr>
<tr>
<td colspan="2"><input id="btn_save" class="button btn btn-lg btn-primary btn-block" type="button" value="<@locale code="login.text.register" />"/></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</div>
</body>
</html>
<div class="col-md-2"></div>
</div >
</div>
<div id="footer">
<#include "../layout/footer.ftl">
</div>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册