注册功能及页面
This commit is contained in:
parent
bb5f136025
commit
9cd69109f9
|
|
@ -45,7 +45,7 @@ public class SysDeptController extends BaseController
|
|||
return prefix + "/dept";
|
||||
}
|
||||
|
||||
@RequiresPermissions("system:dept:list")
|
||||
// @RequiresPermissions("system:dept:list")
|
||||
@PostMapping("/list")
|
||||
@ResponseBody
|
||||
public List<SysDept> list(SysDept dept)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.ghy.web.controller.system;
|
||||
|
||||
import com.ghy.common.core.domain.dto.SysUserAddDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
|
@ -12,6 +13,8 @@ import com.ghy.common.utils.StringUtils;
|
|||
import com.ghy.framework.shiro.service.SysRegisterService;
|
||||
import com.ghy.system.service.ISysConfigService;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* 注册验证
|
||||
*
|
||||
|
|
@ -34,13 +37,13 @@ public class SysRegisterController extends BaseController
|
|||
|
||||
@PostMapping("/register")
|
||||
@ResponseBody
|
||||
public AjaxResult ajaxRegister(SysUser user)
|
||||
public AjaxResult ajaxRegister(@Valid SysUserAddDTO userAddDTO)
|
||||
{
|
||||
if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser"))))
|
||||
{
|
||||
return error("当前系统没有开启注册功能!");
|
||||
}
|
||||
String msg = registerService.register(user);
|
||||
// if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser"))))
|
||||
// {
|
||||
// return error("当前系统没有开启注册功能!");
|
||||
// }
|
||||
String msg = registerService.register(userAddDTO);
|
||||
return StringUtils.isEmpty(msg) ? success() : error(msg);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,41 @@ $(function() {
|
|||
var url = ctx + "captcha/captchaImage?type=" + captchaType + "&s=" + Math.random();
|
||||
$(".imgcode").attr("src", url);
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
dataType:"json",
|
||||
url: ctx + "system/dept/list",
|
||||
data: { parentId: 100 },
|
||||
success: function (data) {
|
||||
$.each(data, function (index, value) {
|
||||
$('#deptId').append("<option value=" + value.deptId + ">" + value.deptName + "</option>");
|
||||
});
|
||||
}
|
||||
})
|
||||
// $('#deptId').select2({
|
||||
// placeholder: '请选择公司编码',
|
||||
// minimumResultsForSearch: -1,
|
||||
// ajax: {
|
||||
// type: "POST",
|
||||
// dataType:"json",
|
||||
// url: ctx + "system/dept/list",
|
||||
// data: { parentId: 100 },
|
||||
// processResults: function (data) {
|
||||
// var processedData = [];
|
||||
// $.each(data, function (index, value) {
|
||||
// processedData.push({
|
||||
// id: value.deptId,
|
||||
// text: value.deptName
|
||||
// })
|
||||
// });
|
||||
// return {
|
||||
// results: processedData
|
||||
// };
|
||||
// },
|
||||
// cache: true
|
||||
// }
|
||||
// });
|
||||
});
|
||||
|
||||
$.validator.setDefaults({
|
||||
|
|
@ -16,6 +51,8 @@ $.validator.setDefaults({
|
|||
function register() {
|
||||
$.modal.loading($("#btnSubmit").data("loading"));
|
||||
var username = $.common.trim($("input[name='username']").val());
|
||||
var phonenumber = $.common.trim($("input[name='phonenumber']").val());
|
||||
var deptId = $.common.trim($('#deptId').val());
|
||||
var password = $.common.trim($("input[name='password']").val());
|
||||
var validateCode = $("input[name='validateCode']").val();
|
||||
$.ajax({
|
||||
|
|
@ -23,6 +60,8 @@ function register() {
|
|||
url: ctx + "register",
|
||||
data: {
|
||||
"loginName": username,
|
||||
"phonenumber": phonenumber,
|
||||
"deptId": deptId,
|
||||
"password": password,
|
||||
"validateCode": validateCode
|
||||
},
|
||||
|
|
@ -49,15 +88,23 @@ function register() {
|
|||
|
||||
function validateRule() {
|
||||
var icon = "<i class='fa fa-times-circle'></i> ";
|
||||
$.validator.addMethod("checkPhone",function(value,element,params){
|
||||
var regex = /^1[345678]\d{9}$/;
|
||||
return regex.test(value);
|
||||
}, "请输入正确的手机号码");
|
||||
$("#registerForm").validate({
|
||||
rules: {
|
||||
username: {
|
||||
required: true,
|
||||
minlength: 2
|
||||
rangelength: [2,20]
|
||||
},
|
||||
phonenumber: {
|
||||
required: true,
|
||||
checkPhone: true
|
||||
},
|
||||
password: {
|
||||
required: true,
|
||||
minlength: 5
|
||||
rangelength: [5,20]
|
||||
},
|
||||
confirmPassword: {
|
||||
required: true,
|
||||
|
|
@ -66,15 +113,18 @@ function validateRule() {
|
|||
},
|
||||
messages: {
|
||||
username: {
|
||||
required: icon + "请输入您的用户名",
|
||||
minlength: icon + "用户名不能小于2个字符"
|
||||
required: icon + "请输入用户名",
|
||||
rangelength: icon + "账户长度必须在2到20个字符之间"
|
||||
},
|
||||
phonenumber: {
|
||||
required: icon + "请输入手机号码"
|
||||
},
|
||||
password: {
|
||||
required: icon + "请输入您的密码",
|
||||
minlength: icon + "密码不能小于5个字符",
|
||||
required: icon + "请输入密码",
|
||||
rangelength: icon + "密码长度必须在5到20个字符之间"
|
||||
},
|
||||
confirmPassword: {
|
||||
required: icon + "请再次输入您的密码",
|
||||
required: icon + "请再次输入密码",
|
||||
equalTo: icon + "两次密码输入不一致"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,8 @@
|
|||
<li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 在你需要的时候</li>
|
||||
<li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 总在您身边</li>
|
||||
</ul>
|
||||
<strong th:if="${isAllowRegister}">还没有账号? <a th:href="@{/register}">立即注册»</a></strong>
|
||||
<!-- <strong th:if="${isAllowRegister}">还没有账号? <a th:href="@{/register}">立即注册»</a></strong>-->
|
||||
<strong>还没有账号? <a th:href="@{/register}">立即注册»</a></strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-5">
|
||||
|
|
|
|||
|
|
@ -15,25 +15,22 @@
|
|||
<!-- 避免IE使用兼容模式 -->
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<link rel="shortcut icon" href="../static/favicon.ico" th:href="@{favicon.ico}"/>
|
||||
<style type="text/css">label.error { position:inherit; }</style>
|
||||
<style type="text/css">
|
||||
label.error { position:inherit; }
|
||||
#registerForm input,
|
||||
#registerForm select {
|
||||
color: black
|
||||
}
|
||||
</style>
|
||||
<th:block th:include="include :: select2-css" />
|
||||
</head>
|
||||
<body class="signin">
|
||||
<div class="signinpanel">
|
||||
<div class="row">
|
||||
<div class="col-sm-7">
|
||||
<div class="signin-info">
|
||||
<div class="logopanel m-b">
|
||||
<h1><img alt="[ 工圈子 ]" src="../static/ruoyi.png" th:src="@{/ruoyi.png}"></h1>
|
||||
</div>
|
||||
<div class="m-b"></div>
|
||||
<h4>欢迎使用 <strong>工圈子 后台管理系统</strong></h4>
|
||||
<ul class="m-b">
|
||||
<li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> SpringBoot</li>
|
||||
<li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> Mybatis</li>
|
||||
<li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> Shiro</li>
|
||||
<li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> Thymeleaf</li>
|
||||
<li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> Bootstrap</li>
|
||||
</ul>
|
||||
<strong>已经注册过? <a th:href="@{/login}">直接登录»</a></strong>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -41,9 +38,13 @@
|
|||
<form id="registerForm" autocomplete="off">
|
||||
<h4 class="no-margins">注册:</h4>
|
||||
<p class="m-t-md">你若不离不弃,我必生死相依</p>
|
||||
<input type="text" name="username" class="form-control uname" placeholder="用户名" maxlength="20" />
|
||||
<input type="password" name="password" class="form-control pword" placeholder="密码" maxlength="20" />
|
||||
<input type="password" name="confirmPassword" class="form-control pword" placeholder="确认密码" maxlength="20" />
|
||||
<input type="text" name="username" class="form-control username" placeholder="用户名"/>
|
||||
<input type="text" name="phonenumber" class="form-control phonenumber" placeholder="手机号"/>
|
||||
<select id="deptId" class="form-control" name="deptId">
|
||||
<option value="" selected>请选择公司编码</option>
|
||||
</select>
|
||||
<input type="password" name="password" class="form-control pword" placeholder="密码"/>
|
||||
<input type="password" name="confirmPassword" class="form-control pword" placeholder="确认密码"/>
|
||||
<div class="row m-t" th:if="${captchaEnabled==true}">
|
||||
<div class="col-xs-6">
|
||||
<input type="text" name="validateCode" class="form-control code" placeholder="验证码" maxlength="5" >
|
||||
|
|
@ -54,17 +55,18 @@
|
|||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="checkbox-custom" th:classappend="${captchaEnabled==false} ? 'm-t'">
|
||||
<input type="checkbox" id="acceptTerm" name="acceptTerm"> <label for="acceptTerm">我已阅读并同意</label>
|
||||
<a href="https://gitee.com/y_project/RuoYi/blob/master/README.md" target="_blank">使用条款</a>
|
||||
</div>
|
||||
<!-- <div class="checkbox-custom" th:classappend="${captchaEnabled==false} ? 'm-t'">-->
|
||||
<!-- <input type="checkbox" id="acceptTerm" name="acceptTerm"> <label for="acceptTerm">我已阅读并同意</label>-->
|
||||
<!-- <a href="https://gitee.com/y_project/RuoYi/blob/master/README.md" target="_blank">使用条款</a>-->
|
||||
<!-- </div>-->
|
||||
<button class="btn btn-success btn-block" id="btnSubmit" data-loading="正在验证注册,请稍候...">注册</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="signup-footer">
|
||||
<div class="pull-left">
|
||||
© 2018-2021 All Rights Reserved. RuoYi <br>
|
||||
Copyright © 2018-2021 opsoul.com All Rights Reserved. <br>
|
||||
备案号 粤ICP备2021044349号-1
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -76,5 +78,6 @@
|
|||
<script src="../static/ajax/libs/blockUI/jquery.blockUI.js" th:src="@{/ajax/libs/blockUI/jquery.blockUI.js}"></script>
|
||||
<script src="../static/ruoyi/js/ry-ui.js" th:src="@{/ruoyi/js/ry-ui.js?v=4.7.2}"></script>
|
||||
<script src="../static/ruoyi/register.js" th:src="@{/ruoyi/register.js}"></script>
|
||||
<th:block th:include="include :: select2-js" />
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
package com.ghy.common.core.domain.dto;
|
||||
|
||||
import com.ghy.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* @author: yangdanqi
|
||||
* @date: 2023/7/1
|
||||
*/
|
||||
@Data
|
||||
public class SysUserAddDTO extends BaseEntity {
|
||||
@NotNull(message = "公司编码不能为空")
|
||||
private Long deptId;
|
||||
|
||||
@NotBlank(message = "账号不能为空")
|
||||
@Length(min = 2, max = 20, message = "账户长度必须在2到20个字符之间")
|
||||
private String loginName;
|
||||
|
||||
@NotBlank(message = "手机号码不能为空")
|
||||
@Pattern(regexp = "^1[345678]\\d{9}$", message = "手机号码格式不正确")
|
||||
private String phonenumber;
|
||||
|
||||
@NotBlank(message = "密码不能为空")
|
||||
@Length(min = 5, max = 20, message = "密码长度必须在5到20个字符之间")
|
||||
private String password;
|
||||
}
|
||||
|
|
@ -287,6 +287,7 @@ public class ShiroConfig
|
|||
filterChainDefinitionMap.put("/tool/**", "anon");
|
||||
filterChainDefinitionMap.put("/adapay/**", "anon");
|
||||
filterChainDefinitionMap.put("/system/area/**", "anon");
|
||||
filterChainDefinitionMap.put("/system/dept/list", "anon");
|
||||
filterChainDefinitionMap.put("/customer/address/**", "anon");
|
||||
filterChainDefinitionMap.put("/customer/place/app/**", "anon");
|
||||
filterChainDefinitionMap.put("/customer/selection/app/**", "anon");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package com.ghy.framework.shiro.service;
|
||||
|
||||
import com.ghy.common.core.domain.dto.SysUserAddDTO;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.ghy.common.constant.Constants;
|
||||
|
|
@ -10,10 +12,10 @@ import com.ghy.common.utils.DateUtils;
|
|||
import com.ghy.common.utils.MessageUtils;
|
||||
import com.ghy.common.utils.ServletUtils;
|
||||
import com.ghy.common.utils.ShiroUtils;
|
||||
import com.ghy.common.utils.StringUtils;
|
||||
import com.ghy.framework.manager.AsyncManager;
|
||||
import com.ghy.framework.manager.factory.AsyncFactory;
|
||||
import com.ghy.system.service.ISysUserService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 注册校验方法
|
||||
|
|
@ -32,50 +34,30 @@ public class SysRegisterService
|
|||
/**
|
||||
* 注册
|
||||
*/
|
||||
public String register(SysUser user)
|
||||
{
|
||||
String msg = "", loginName = user.getLoginName(), password = user.getPassword();
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String register(SysUserAddDTO userAddDTO) {
|
||||
String msg = "";
|
||||
SysUser sysUser = new SysUser();
|
||||
BeanUtils.copyProperties(userAddDTO, sysUser);
|
||||
|
||||
if (ShiroConstants.CAPTCHA_ERROR.equals(ServletUtils.getRequest().getAttribute(ShiroConstants.CURRENT_CAPTCHA)))
|
||||
{
|
||||
if (ShiroConstants.CAPTCHA_ERROR.equals(ServletUtils.getRequest().getAttribute(ShiroConstants.CURRENT_CAPTCHA))) {
|
||||
msg = "验证码错误";
|
||||
}
|
||||
else if (StringUtils.isEmpty(loginName))
|
||||
{
|
||||
msg = "用户名不能为空";
|
||||
}
|
||||
else if (StringUtils.isEmpty(password))
|
||||
{
|
||||
msg = "用户密码不能为空";
|
||||
}
|
||||
else if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
||||
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH)
|
||||
{
|
||||
msg = "密码长度必须在5到20个字符之间";
|
||||
}
|
||||
else if (loginName.length() < UserConstants.USERNAME_MIN_LENGTH
|
||||
|| loginName.length() > UserConstants.USERNAME_MAX_LENGTH)
|
||||
{
|
||||
msg = "账户长度必须在2到20个字符之间";
|
||||
}
|
||||
else if (UserConstants.USER_NAME_NOT_UNIQUE.equals(userService.checkLoginNameUnique(loginName)))
|
||||
{
|
||||
msg = "保存用户'" + loginName + "'失败,注册账号已存在";
|
||||
}
|
||||
else
|
||||
{
|
||||
user.setPwdUpdateDate(DateUtils.getNowDate());
|
||||
user.setUserName(loginName);
|
||||
user.setSalt(ShiroUtils.randomSalt());
|
||||
user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt()));
|
||||
boolean regFlag = userService.registerUser(user);
|
||||
if (!regFlag)
|
||||
{
|
||||
} else if (UserConstants.USER_NAME_NOT_UNIQUE.equals(userService.checkLoginNameUnique(sysUser.getLoginName()))) {
|
||||
msg = "保存用户'" + userAddDTO.getLoginName() + "'失败,注册账号已存在";
|
||||
} else if (UserConstants.USER_NAME_NOT_UNIQUE.equals(userService.checkPhoneUnique(sysUser))) {
|
||||
msg = "保存手机号码'" + userAddDTO.getPhonenumber() + "'失败,该手机号码已被注册";
|
||||
} else {
|
||||
sysUser.setPwdUpdateDate(DateUtils.getNowDate());
|
||||
sysUser.setUserName(userAddDTO.getLoginName());
|
||||
sysUser.setSalt(ShiroUtils.randomSalt());
|
||||
sysUser.setPassword(passwordService.encryptPassword(sysUser.getLoginName(), sysUser.getPassword(), sysUser.getSalt()));
|
||||
boolean regFlag = userService.registerUser(sysUser);
|
||||
SysUser registeredUserInfo = userService.selectUserByLoginName(sysUser.getLoginName());
|
||||
userService.insertUserAuth(registeredUserInfo.getUserId(), new Long[]{101l});
|
||||
if (!regFlag) {
|
||||
msg = "注册失败,请联系系统管理人员";
|
||||
}
|
||||
else
|
||||
{
|
||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginName, Constants.REGISTER, MessageUtils.message("user.register.success")));
|
||||
} else {
|
||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(userAddDTO.getLoginName(), Constants.REGISTER, MessageUtils.message("user.register.success")));
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
|
|
|
|||
|
|
@ -138,11 +138,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</select>
|
||||
|
||||
<select id="checkLoginNameUnique" parameterType="String" resultType="int">
|
||||
select count(1) from sys_user where login_name=#{loginName} limit 1
|
||||
select count(1) from sys_user where login_name=#{loginName} and del_flag = 0 limit 1
|
||||
</select>
|
||||
|
||||
<select id="checkPhoneUnique" parameterType="String" resultMap="SysUserResult">
|
||||
select user_id, phonenumber from sys_user where phonenumber=#{phonenumber} limit 1
|
||||
select user_id, phonenumber from sys_user where phonenumber=#{phonenumber} and del_flag = 0 limit 1
|
||||
</select>
|
||||
|
||||
<select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult">
|
||||
|
|
|
|||
Loading…
Reference in New Issue