fix: 修复修改密码和创建用户时偶现的错误(#50)

This commit is contained in:
xiaozzzi 2024-01-04 03:22:56 +08:00
parent d59bf97b17
commit 389997aee7
3 changed files with 21 additions and 3 deletions

View File

@ -13,6 +13,11 @@ import org.apache.ibatis.annotations.Param;
@Mapper
public interface UserMapper extends BaseMapper<UserEntity> {
/**
* 新增用户
*/
void insertUser(UserEntity user);
/**
* 修改用户信息
*/

View File

@ -67,7 +67,7 @@ public class UserService extends ServiceImpl<UserMapper, UserEntity> {
user.setType(req.getType());
user.setSalt(SaltUtil.randomSalt());
user.setPassword(passwordEncoder.encode(req.getPassword() + user.getSalt()));
baseMapper.insert(user);
baseMapper.insertUser(user);
userParamService.initUserParams(user.getId());
}
@ -89,7 +89,6 @@ public class UserService extends ServiceImpl<UserMapper, UserEntity> {
if (!passwordEncoder.matches(req.getPassword() + user.getSalt(), user.getPassword())) {
throw new XzException400("密码错误");
}
String newPwd = passwordEncoder.encode(req.getNewPassword() + user.getSalt());
baseMapper.updPwd(req.getUserId(), newPwd);
}

View File

@ -2,6 +2,19 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.blossom.backend.base.user.UserMapper">
<insert id="insertUser" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
insert into base_user (`id`, `type`, `username`, `password`, `salt`, `nick_name`, `real_name`)
values (
null,
#{type},
#{username},
'${password}',
'${salt}',
#{username},
#{username}
)
</insert>
<!-- 根据ID修改 -->
<update id="updById">
update base_user
@ -17,6 +30,7 @@
</update>
<update id="updPwd">
update base_user set password = #{password},upd_time = now() where id = #{userId}
update base_user set password = '${password}',upd_time = now() where id = #{userId}
</update>
</mapper>