forked from github/cool-admin-java
feat: 管理端重置用户密码,生成8位随机字符串并返回
This commit is contained in:
@@ -60,6 +60,14 @@ public class AdminUserInfoController extends BaseController<UserInfoService, Use
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@Operation(summary = "重置用户密码")
|
||||
@PostMapping("/resetPassword")
|
||||
public R resetPassword(@RequestBody JSONObject requestParams) {
|
||||
Long id = requestParams.getLong("id");
|
||||
String newPassword = userInfoService.resetPassword(id);
|
||||
return R.ok(newPassword);
|
||||
}
|
||||
|
||||
@Override
|
||||
@PostMapping("/delete")
|
||||
protected R delete(HttpServletRequest request, @RequestBody Map<String, Object> params,
|
||||
|
||||
@@ -45,4 +45,6 @@ public interface UserInfoService extends BaseService<UserInfoEntity> {
|
||||
* 删除前校验:必须已注销
|
||||
*/
|
||||
void checkLogoffBeforeDelete(Long userId);
|
||||
|
||||
String resetPassword(Long userId);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.cool.modules.user.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.crypto.digest.MD5;
|
||||
import com.cool.core.base.BaseServiceImpl;
|
||||
import com.cool.core.exception.CoolPreconditions;
|
||||
@@ -101,4 +102,14 @@ public class UserInfoServiceImpl extends BaseServiceImpl<UserInfoMapper, UserInf
|
||||
info.setUsername(username);
|
||||
info.updateById();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resetPassword(Long userId) {
|
||||
UserInfoEntity info = getById(userId);
|
||||
CoolPreconditions.checkEmpty(info, "用户不存在");
|
||||
String newPassword = RandomUtil.randomString(8);
|
||||
info.setPassword(MD5.create().digestHex(newPassword));
|
||||
info.updateById();
|
||||
return newPassword;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user