重置密码

v1.4.1
Parker 4 years ago
parent ed11467bd1
commit 9a915a8941

@ -102,6 +102,13 @@ public interface UserApi {
@PostMapping("/updatePasswordById")
ResultVo<?> updatePasswordById(@RequestBody UserPassword userPassword);
/**
* ID
* @return ResultVo
*/
@PostMapping("/resetPasswordById")
ResultVo<?> resetPasswordById(String userId);
/**
*

@ -80,6 +80,13 @@ public interface IUserService extends CrudServiceInterface<SysUser, UserModel> {
*/
boolean updatePassword(UserPassword userPassword);
/**
*
* @param userPassword
* @return
*/
boolean resetPassword(UserPassword userPassword);
/**
* IP

@ -230,6 +230,37 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
return ret;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean resetPassword(UserPassword userPassword) {
UserModel userModel = super.get(userPassword.getUserId());
// 如果为空则 不修改密码
if(userModel == null){
return false;
}
// 设置随机新盐值
userPassword.setSalt(
RandomUtil.randomString(20)
);
// 处理密码
userPassword.setNewPassword(
UserUtil.handlePassword(userPassword.getNewPassword(),
userPassword.getSalt())
);
// 修改密码
boolean ret = mapper.updatePassword(userPassword);
if(ret){
// 刷新用户缓存
UserUtil.refreshUser(userModel);
}
return ret;
}
/**
* IP
* @param model

@ -58,6 +58,7 @@ import org.opsli.modulars.system.user.entity.SysUserAndOrg;
import org.opsli.modulars.system.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
@ -85,6 +86,8 @@ public class UserRestController extends BaseRestController<SysUser, UserModel, I
@Value("${opsli.web.upload-path}")
private String basedir;
@Value("${opsli.default-pass}")
private String defaultPass;
@Autowired
private ISysOrgService iSysOrgService;
@ -247,7 +250,29 @@ public class UserRestController extends BaseRestController<SysUser, UserModel, I
return ResultVo.success();
}
/**
*
* @return ResultVo
*/
@ApiOperation(value = "重置密码", notes = "重置密码")
@RequiresPermissions("system_user_resetPassword")
@EnableLog
@Override
public ResultVo<?> resetPasswordById(String userId) {
// 演示模式 不允许操作
super.demoError();
UserPassword userPassword = new UserPassword();
userPassword.setNewPassword(defaultPass);
userPassword.setUserId(userId);
boolean resetPasswordFlag = IService.resetPassword(userPassword);
if(!resetPasswordFlag){
return ResultVo.error("重置密码失败");
}
return ResultVo.success("重置密码成功!默认密码为:" + defaultPass);
}
/**
*

@ -186,6 +186,9 @@ opsli:
# token 有效时间 (分钟) 2小时
token-effective-time: 120
# 重置默认密码
default-pass: Aa123456
# 登录设置
login:
# 失败次数

Loading…
Cancel
Save