fix: 修复查询用户邮箱、手机号时未自动加密导致的错误
This commit is contained in:
parent
53eaef9fbd
commit
faa56d16b9
@ -65,4 +65,20 @@ public interface UserMapper extends DataPermissionMapper<UserDO> {
|
|||||||
*/
|
*/
|
||||||
@Select("SELECT nickname FROM sys_user WHERE id = #{id}")
|
@Select("SELECT nickname FROM sys_user WHERE id = #{id}")
|
||||||
String selectNicknameById(@Param("id") Long id);
|
String selectNicknameById(@Param("id") Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据邮箱查询数量
|
||||||
|
*
|
||||||
|
* @param email 邮箱
|
||||||
|
* @return 用户数量
|
||||||
|
*/
|
||||||
|
Long selectCountByEmail(@FieldEncrypt @Param("email") String email, @Param("id") Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据手机号查询数量
|
||||||
|
*
|
||||||
|
* @param phone 手机号
|
||||||
|
* @return 用户数量
|
||||||
|
*/
|
||||||
|
Long selectCountByPhone(@FieldEncrypt @Param("phone") String phone, @Param("id") Long id);
|
||||||
}
|
}
|
||||||
|
@ -217,8 +217,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
|
|||||||
public void updatePhone(String newPhone, String currentPassword, Long id) {
|
public void updatePhone(String newPhone, String currentPassword, Long id) {
|
||||||
UserDO user = super.getById(id);
|
UserDO user = super.getById(id);
|
||||||
CheckUtils.throwIf(!passwordEncoder.matches(currentPassword, user.getPassword()), "当前密码错误");
|
CheckUtils.throwIf(!passwordEncoder.matches(currentPassword, user.getPassword()), "当前密码错误");
|
||||||
Long count = baseMapper.lambdaQuery().eq(UserDO::getPhone, newPhone).count();
|
CheckUtils.throwIf(this.isPhoneExists(newPhone, id), "手机号已绑定其他账号,请更换其他手机号");
|
||||||
CheckUtils.throwIf(count > 0, "手机号已绑定其他账号,请更换其他手机号");
|
|
||||||
CheckUtils.throwIfEqual(newPhone, user.getPhone(), "新手机号不能与当前手机号相同");
|
CheckUtils.throwIfEqual(newPhone, user.getPhone(), "新手机号不能与当前手机号相同");
|
||||||
// 更新手机号
|
// 更新手机号
|
||||||
baseMapper.lambdaUpdate().set(UserDO::getPhone, newPhone).eq(UserDO::getId, id).update();
|
baseMapper.lambdaUpdate().set(UserDO::getPhone, newPhone).eq(UserDO::getId, id).update();
|
||||||
@ -228,8 +227,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
|
|||||||
public void updateEmail(String newEmail, String currentPassword, Long id) {
|
public void updateEmail(String newEmail, String currentPassword, Long id) {
|
||||||
UserDO user = super.getById(id);
|
UserDO user = super.getById(id);
|
||||||
CheckUtils.throwIf(!passwordEncoder.matches(currentPassword, user.getPassword()), "当前密码错误");
|
CheckUtils.throwIf(!passwordEncoder.matches(currentPassword, user.getPassword()), "当前密码错误");
|
||||||
Long count = baseMapper.lambdaQuery().eq(UserDO::getEmail, newEmail).count();
|
CheckUtils.throwIf(this.isEmailExists(newEmail, id), "邮箱已绑定其他账号,请更换其他邮箱");
|
||||||
CheckUtils.throwIf(count > 0, "邮箱已绑定其他账号,请更换其他邮箱");
|
|
||||||
CheckUtils.throwIfEqual(newEmail, user.getEmail(), "新邮箱不能与当前邮箱相同");
|
CheckUtils.throwIfEqual(newEmail, user.getEmail(), "新邮箱不能与当前邮箱相同");
|
||||||
// 更新邮箱
|
// 更新邮箱
|
||||||
baseMapper.lambdaUpdate().set(UserDO::getEmail, newEmail).eq(UserDO::getId, id).update();
|
baseMapper.lambdaUpdate().set(UserDO::getEmail, newEmail).eq(UserDO::getId, id).update();
|
||||||
@ -296,7 +294,8 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
|
|||||||
* @return 是否存在
|
* @return 是否存在
|
||||||
*/
|
*/
|
||||||
private boolean isEmailExists(String email, Long id) {
|
private boolean isEmailExists(String email, Long id) {
|
||||||
return baseMapper.lambdaQuery().eq(UserDO::getEmail, email).ne(null != id, UserDO::getId, id).exists();
|
Long count = baseMapper.selectCountByEmail(email, id);
|
||||||
|
return null != count && count > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -307,6 +306,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
|
|||||||
* @return 是否存在
|
* @return 是否存在
|
||||||
*/
|
*/
|
||||||
private boolean isPhoneExists(String phone, Long id) {
|
private boolean isPhoneExists(String phone, Long id) {
|
||||||
return baseMapper.lambdaQuery().eq(UserDO::getPhone, phone).ne(null != id, UserDO::getId, id).exists();
|
Long count = baseMapper.selectCountByPhone(phone, id);
|
||||||
|
return null != count && count > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,22 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
<mapper namespace="top.continew.admin.system.mapper.UserMapper">
|
<mapper namespace="top.continew.admin.system.mapper.UserMapper">
|
||||||
|
|
||||||
|
<select id="selectCountByEmail" resultType="java.lang.Long">
|
||||||
|
SELECT count(*)
|
||||||
|
FROM sys_user
|
||||||
|
WHERE email = #{email}
|
||||||
|
<if test="id != null">
|
||||||
|
AND id != #{id}
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectCountByPhone" resultType="java.lang.Long">
|
||||||
|
SELECT count(*)
|
||||||
|
FROM sys_user
|
||||||
|
WHERE phone = #{phone}
|
||||||
|
<if test="id != null">
|
||||||
|
AND id != #{id}
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
Loading…
Reference in New Issue
Block a user