mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 15:13:55 +08:00
用户业务层为添加新方法,重置密码,直接修改密码
--SysUserService.java 定义2个方法 --SysUserServiceImpl.java 实现重置密码,直接修改密码
This commit is contained in:
@@ -22,8 +22,26 @@ public interface SysUserService extends BaseService<SysUserEntity> {
|
||||
|
||||
void delete(Long[] ids);
|
||||
|
||||
/**
|
||||
* 验证是否允许修改密码更改
|
||||
* @param userId 用户id
|
||||
* @param passwordDTO 验证密码的参数
|
||||
*/
|
||||
void changePassword(Long userId, PasswordDTO passwordDTO);
|
||||
|
||||
/**
|
||||
* 直接修改密码,不需要验证
|
||||
* @param userId 用户id
|
||||
* @param password 密码
|
||||
*/
|
||||
void changePasswordDirectly(Long userId, String password);
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
* @param userId 用户id
|
||||
* @return 随机生成符合规范的密码
|
||||
*/
|
||||
String resetPassword(Long userId);
|
||||
/**
|
||||
* 管理员分页用户信息
|
||||
* @param dto 分页查找参数
|
||||
|
||||
+35
-5
@@ -3,7 +3,6 @@ package xiaozhi.modules.sys.service.impl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import xiaozhi.common.constant.Constant;
|
||||
@@ -22,10 +21,7 @@ import xiaozhi.modules.sys.enums.SuperAdminEnum;
|
||||
import xiaozhi.modules.sys.service.SysUserService;
|
||||
import xiaozhi.modules.sys.vo.AdminPageUserVO;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -91,6 +87,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntit
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void changePassword(Long userId, PasswordDTO passwordDTO) {
|
||||
SysUserEntity sysUserEntity = sysUserDao.selectById(userId);
|
||||
|
||||
@@ -115,6 +112,24 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntit
|
||||
updateById(sysUserEntity);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void changePasswordDirectly(Long userId, String password) {
|
||||
SysUserEntity sysUserEntity = new SysUserEntity();
|
||||
sysUserEntity.setId(userId);
|
||||
sysUserEntity.setPassword(PasswordUtils.encode(password));
|
||||
updateById(sysUserEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String resetPassword(Long userId) {
|
||||
String password = generatePassword();
|
||||
changePasswordDirectly(userId,password);
|
||||
return password;
|
||||
}
|
||||
|
||||
private Long getUserCount() {
|
||||
QueryWrapper<SysUserEntity> queryWrapper = new QueryWrapper<>();
|
||||
return baseDao.selectCount(queryWrapper);
|
||||
@@ -149,4 +164,19 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntit
|
||||
Matcher matcher = pattern.matcher(password);
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()";
|
||||
private static final Random random = new Random();
|
||||
/**
|
||||
* 生成随机密码
|
||||
* @return 随机生成的密码
|
||||
*/
|
||||
private String generatePassword(){
|
||||
StringBuilder password = new StringBuilder();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int randomIndex = random.nextInt(CHARACTERS.length());
|
||||
password.append(CHARACTERS.charAt(randomIndex));
|
||||
}
|
||||
return password.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user