修改用户登录账号重复验证

This commit is contained in:
RuoYi 2022-09-18 11:26:03 +08:00
parent c3faa1a925
commit 854b405d89
6 changed files with 22 additions and 18 deletions

View File

@ -125,7 +125,7 @@ public class SysUserController extends BaseController
@PostMapping
public AjaxResult add(@Validated @RequestBody SysUser user)
{
if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user.getUserName())))
if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user)))
{
return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
}
@ -154,7 +154,11 @@ public class SysUserController extends BaseController
{
userService.checkUserAllowed(user);
userService.checkUserDataScope(user.getUserId());
if (StringUtils.isNotEmpty(user.getPhonenumber())
if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user)))
{
return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,登录账号已存在");
}
else if (StringUtils.isNotEmpty(user.getPhonenumber())
&& UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
{
return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");

View File

@ -41,9 +41,11 @@ public class SysRegisterService
public String register(RegisterBody registerBody)
{
String msg = "", username = registerBody.getUsername(), password = registerBody.getPassword();
SysUser sysUser = new SysUser();
sysUser.setUserName(username);
boolean captchaEnabled = configService.selectCaptchaEnabled();
// 验证码开关
boolean captchaEnabled = configService.selectCaptchaEnabled();
if (captchaEnabled)
{
validateCaptcha(username, registerBody.getCode(), registerBody.getUuid());
@ -67,16 +69,14 @@ public class SysRegisterService
{
msg = "密码长度必须在5到20个字符之间";
}
else if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(username)))
else if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(sysUser)))
{
msg = "保存用户'" + username + "'失败,注册账号已存在";
}
else
{
SysUser sysUser = new SysUser();
sysUser.setUserName(username);
sysUser.setNickName(username);
sysUser.setPassword(SecurityUtils.encryptPassword(registerBody.getPassword()));
sysUser.setPassword(SecurityUtils.encryptPassword(password));
boolean regFlag = userService.registerUser(sysUser);
if (!regFlag)
{
@ -84,8 +84,7 @@ public class SysRegisterService
}
else
{
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.REGISTER,
MessageUtils.message("user.register.success")));
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.REGISTER, MessageUtils.message("user.register.success")));
}
}
return msg;

View File

@ -107,7 +107,7 @@ public interface SysUserMapper
* @param userName 用户名称
* @return 结果
*/
public int checkUserNameUnique(String userName);
public SysUser checkUserNameUnique(String userName);
/**
* 校验手机号码是否唯一

View File

@ -69,10 +69,10 @@ public interface ISysUserService
/**
* 校验用户名称是否唯一
*
* @param userName 用户名称
* @param user 用户信息
* @return 结果
*/
public String checkUserNameUnique(String userName);
public String checkUserNameUnique(SysUser user);
/**
* 校验手机号码是否唯一

View File

@ -161,14 +161,15 @@ public class SysUserServiceImpl implements ISysUserService
/**
* 校验用户名称是否唯一
*
* @param userName 用户名称
* @param user 用户信息
* @return 结果
*/
@Override
public String checkUserNameUnique(String userName)
public String checkUserNameUnique(SysUser user)
{
int count = userMapper.checkUserNameUnique(userName);
if (count > 0)
Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
SysUser info = userMapper.checkUserNameUnique(user.getUserName());
if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue())
{
return UserConstants.NOT_UNIQUE;
}

View File

@ -130,8 +130,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where u.user_id = #{userId}
</select>
<select id="checkUserNameUnique" parameterType="String" resultType="int">
select count(1) from sys_user where user_name = #{userName} and del_flag = '0' limit 1
<select id="checkUserNameUnique" parameterType="String" resultMap="SysUserResult">
select user_id, user_name from sys_user where user_name = #{userName} and del_flag = '0' limit 1
</select>
<select id="checkPhoneUnique" parameterType="String" resultMap="SysUserResult">