feat: add user module register
This commit is contained in:
@@ -58,6 +58,15 @@ public class UUser extends BaseEntity
|
|||||||
/** 密码 */
|
/** 密码 */
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
/** 用户姓名 */
|
||||||
|
private String fullName;
|
||||||
|
|
||||||
|
/** 年龄 */
|
||||||
|
private Integer age;
|
||||||
|
|
||||||
|
/** 地址 */
|
||||||
|
private String address;
|
||||||
|
|
||||||
/** 帐号状态(0正常 1停用) */
|
/** 帐号状态(0正常 1停用) */
|
||||||
@Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用")
|
@Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用")
|
||||||
private String status;
|
private String status;
|
||||||
@@ -102,6 +111,30 @@ public class UUser extends BaseEntity
|
|||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFullName() {
|
||||||
|
return fullName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFullName(String fullName) {
|
||||||
|
this.fullName = fullName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getAge() {
|
||||||
|
return age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAge(Integer age) {
|
||||||
|
this.age = age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAddress() {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddress(String address) {
|
||||||
|
this.address = address;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getUserId()
|
public Long getUserId()
|
||||||
{
|
{
|
||||||
return userId;
|
return userId;
|
||||||
|
|||||||
@@ -5,24 +5,22 @@ import org.springframework.web.bind.annotation.DeleteMapping;
|
|||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.wfc.common.core.web.form.LoginBody;
|
|
||||||
import org.wfc.common.core.web.form.RegisterBody;
|
|
||||||
import org.wfc.auth.service.SysLoginService;
|
import org.wfc.auth.service.SysLoginService;
|
||||||
import org.wfc.auth.service.ULoginService;
|
import org.wfc.auth.service.ULoginService;
|
||||||
|
import org.wfc.common.core.domain.LoginUser;
|
||||||
import org.wfc.common.core.domain.R;
|
import org.wfc.common.core.domain.R;
|
||||||
import org.wfc.common.core.utils.JwtUtils;
|
import org.wfc.common.core.utils.JwtUtils;
|
||||||
import org.wfc.common.core.utils.StringUtils;
|
import org.wfc.common.core.utils.StringUtils;
|
||||||
|
import org.wfc.common.core.web.form.LoginBody;
|
||||||
|
import org.wfc.common.core.web.form.RegisterBody;
|
||||||
import org.wfc.common.security.auth.AuthUtil;
|
import org.wfc.common.security.auth.AuthUtil;
|
||||||
import org.wfc.common.security.service.TokenService;
|
import org.wfc.common.security.service.TokenService;
|
||||||
import org.wfc.common.security.utils.SecurityUtils;
|
import org.wfc.common.security.utils.SecurityUtils;
|
||||||
import org.wfc.common.core.domain.LoginUser;
|
|
||||||
import org.wfc.system.api.domain.SysUser;
|
import org.wfc.system.api.domain.SysUser;
|
||||||
import org.wfc.user.api.domain.UUser;
|
import org.wfc.user.api.domain.UUser;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* token 控制
|
* token 控制
|
||||||
*
|
*
|
||||||
@@ -89,8 +87,9 @@ public class TokenController
|
|||||||
@PostMapping("register")
|
@PostMapping("register")
|
||||||
public R<?> register(@RequestBody RegisterBody registerBody)
|
public R<?> register(@RequestBody RegisterBody registerBody)
|
||||||
{
|
{
|
||||||
// 用户注册
|
|
||||||
sysLoginService.register(registerBody);
|
sysLoginService.register(registerBody);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.wfc.auth.service;
|
package org.wfc.auth.service;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.wfc.common.core.constant.CacheConstants;
|
import org.wfc.common.core.constant.CacheConstants;
|
||||||
@@ -21,6 +22,8 @@ import org.wfc.common.redis.service.RedisService;
|
|||||||
import org.wfc.common.security.utils.SecurityUtils;
|
import org.wfc.common.security.utils.SecurityUtils;
|
||||||
import org.wfc.system.api.RemoteUserService;
|
import org.wfc.system.api.RemoteUserService;
|
||||||
import org.wfc.system.api.domain.SysUser;
|
import org.wfc.system.api.domain.SysUser;
|
||||||
|
import org.wfc.user.api.RemoteUUserService;
|
||||||
|
import org.wfc.user.api.domain.UUser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录校验方法
|
* 登录校验方法
|
||||||
@@ -33,6 +36,9 @@ public class SysLoginService
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RemoteUserService remoteUserService;
|
private RemoteUserService remoteUserService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RemoteUUserService remoteUUserService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysPasswordService passwordService;
|
private SysPasswordService passwordService;
|
||||||
|
|
||||||
@@ -161,12 +167,23 @@ public class SysLoginService
|
|||||||
sysUser.setFullName(registerBody.getFullName());
|
sysUser.setFullName(registerBody.getFullName());
|
||||||
sysUser.setSex(registerBody.getSex());
|
sysUser.setSex(registerBody.getSex());
|
||||||
sysUser.setPhonenumber(registerBody.getPhonenumber());
|
sysUser.setPhonenumber(registerBody.getPhonenumber());
|
||||||
R<?> registerResult = remoteUserService.registerUserInfo(sysUser, SecurityConstants.INNER);
|
|
||||||
|
|
||||||
|
if ("u".equals(registerBody.getAuthType())){
|
||||||
|
UUser uUser = new UUser();
|
||||||
|
BeanUtils.copyProperties(sysUser, uUser);
|
||||||
|
R<?> registerResult = remoteUUserService.registerUserInfo(uUser, SecurityConstants.INNER);
|
||||||
if (R.FAIL == registerResult.getCode())
|
if (R.FAIL == registerResult.getCode())
|
||||||
{
|
{
|
||||||
throw new ServiceException(registerResult.getMsg());
|
throw new ServiceException(registerResult.getMsg());
|
||||||
}
|
}
|
||||||
|
} if ("sys".equals(registerBody.getAuthType())){
|
||||||
|
R<?> registerResult = remoteUserService.registerUserInfo(sysUser, SecurityConstants.INNER);
|
||||||
|
if (R.FAIL == registerResult.getCode())
|
||||||
|
{
|
||||||
|
throw new ServiceException(registerResult.getMsg());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 注册成功删除redis
|
// 注册成功删除redis
|
||||||
if (StrUtil.isNotBlank(registerBody.getEmail())) {
|
if (StrUtil.isNotBlank(registerBody.getEmail())) {
|
||||||
redisService.deleteObject(GlobalConstants.CAPTCHA_CODE_KEY + registerBody.getEmail());
|
redisService.deleteObject(GlobalConstants.CAPTCHA_CODE_KEY + registerBody.getEmail());
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
package org.wfc.user.controller;
|
package org.wfc.user.controller;
|
||||||
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import org.wfc.common.core.domain.LoginUser;
|
import org.wfc.common.core.domain.LoginUser;
|
||||||
import org.wfc.common.core.domain.R;
|
import org.wfc.common.core.domain.R;
|
||||||
@@ -23,7 +31,13 @@ import org.wfc.common.security.utils.SecurityUtils;
|
|||||||
import org.wfc.user.api.domain.UDept;
|
import org.wfc.user.api.domain.UDept;
|
||||||
import org.wfc.user.api.domain.URole;
|
import org.wfc.user.api.domain.URole;
|
||||||
import org.wfc.user.api.domain.UUser;
|
import org.wfc.user.api.domain.UUser;
|
||||||
import org.wfc.user.service.*;
|
import org.wfc.user.domain.query.UserRepeatQuery;
|
||||||
|
import org.wfc.user.service.IUConfigService;
|
||||||
|
import org.wfc.user.service.IUDeptService;
|
||||||
|
import org.wfc.user.service.IUPermissionService;
|
||||||
|
import org.wfc.user.service.IUPostService;
|
||||||
|
import org.wfc.user.service.IURoleService;
|
||||||
|
import org.wfc.user.service.IUUserService;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -75,6 +89,18 @@ public class UUserController extends BaseController
|
|||||||
return MessageUtils.message("user.jcaptcha.error");
|
return MessageUtils.message("user.jcaptcha.error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查重复
|
||||||
|
*/
|
||||||
|
@PostMapping("/checkRepeat")
|
||||||
|
public R<Boolean> checkRepeat(@RequestBody UserRepeatQuery query)
|
||||||
|
{
|
||||||
|
UUser user = new UUser();
|
||||||
|
BeanUtils.copyProperties(query, user);
|
||||||
|
return R.ok(!userService.checkUserNameUnique(user) || !userService.checkPhoneUnique(user)
|
||||||
|
|| !userService.checkEmailUnique(user));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户列表
|
* 获取用户列表
|
||||||
*/
|
*/
|
||||||
@@ -144,18 +170,29 @@ public class UUserController extends BaseController
|
|||||||
*/
|
*/
|
||||||
@InnerAuth
|
@InnerAuth
|
||||||
@PostMapping("/register")
|
@PostMapping("/register")
|
||||||
public R<Boolean> register(@RequestBody UUser UUser)
|
public R<Boolean> register(@RequestBody UUser uUser)
|
||||||
{
|
{
|
||||||
String username = UUser.getUserName();
|
String username = uUser.getUserName();
|
||||||
if (!("true".equals(configService.selectConfigByKey("U.account.registerUser"))))
|
if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser"))))
|
||||||
{
|
{
|
||||||
return R.fail("当前系统没有开启注册功能!");
|
return R.fail("当前系统没有开启注册功能!");
|
||||||
}
|
}
|
||||||
if (!userService.checkUserNameUnique(UUser))
|
if (!userService.checkUserNameUnique(uUser))
|
||||||
{
|
{
|
||||||
return R.fail("保存用户'" + username + "'失败,注册账号已存在");
|
return R.fail("user.register.save.error");
|
||||||
}
|
}
|
||||||
return R.ok(userService.registerUser(UUser));
|
|
||||||
|
if (!userService.checkPhoneUnique(uUser))
|
||||||
|
{
|
||||||
|
return R.fail("user.register.phone.save.error");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!userService.checkEmailUnique(uUser))
|
||||||
|
{
|
||||||
|
return R.fail("user.register.email.save.error");
|
||||||
|
}
|
||||||
|
|
||||||
|
return R.ok(userService.registerUser(uUser));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package org.wfc.user.domain.query;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 用户重复query
|
||||||
|
* @author: caiyuchao
|
||||||
|
* @date: 2024-11-27
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class UserRepeatQuery {
|
||||||
|
private String userName;
|
||||||
|
private String email;
|
||||||
|
private String phonenumber;
|
||||||
|
}
|
||||||
@@ -23,6 +23,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<result property="updateBy" column="update_by" />
|
<result property="updateBy" column="update_by" />
|
||||||
<result property="updateTime" column="update_time" />
|
<result property="updateTime" column="update_time" />
|
||||||
<result property="remark" column="remark" />
|
<result property="remark" column="remark" />
|
||||||
|
<result property="fullName" column="full_name" />
|
||||||
|
<result property="age" column="age" />
|
||||||
|
<result property="address" column="address" />
|
||||||
<association property="dept" javaType="UDept" resultMap="deptResult" />
|
<association property="dept" javaType="UDept" resultMap="deptResult" />
|
||||||
<collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
|
<collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
@@ -156,6 +159,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="status != null and status != ''">status,</if>
|
<if test="status != null and status != ''">status,</if>
|
||||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||||
<if test="remark != null and remark != ''">remark,</if>
|
<if test="remark != null and remark != ''">remark,</if>
|
||||||
|
<if test="fullName != null and fullName != ''">full_name,</if>
|
||||||
|
<if test="age != null and age != ''">age,</if>
|
||||||
|
<if test="address != null and address != ''">address,</if>
|
||||||
create_time
|
create_time
|
||||||
)values(
|
)values(
|
||||||
<if test="userId != null and userId != ''">#{userId},</if>
|
<if test="userId != null and userId != ''">#{userId},</if>
|
||||||
@@ -170,6 +176,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="status != null and status != ''">#{status},</if>
|
<if test="status != null and status != ''">#{status},</if>
|
||||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||||
<if test="remark != null and remark != ''">#{remark},</if>
|
<if test="remark != null and remark != ''">#{remark},</if>
|
||||||
|
<if test="fullName != null and fullName != ''">#{fullName},</if>
|
||||||
|
<if test="age != null and age != ''">#{age},</if>
|
||||||
|
<if test="address != null and address != ''">#{address},</if>
|
||||||
sysdate()
|
sysdate()
|
||||||
)
|
)
|
||||||
</insert>
|
</insert>
|
||||||
|
|||||||
Reference in New Issue
Block a user