Commit 58f923e5 authored by 廖旭伟's avatar 廖旭伟

新增管理员修改用户密码接口

parent 1e698e4a
......@@ -74,4 +74,14 @@ public interface UserService extends ICRUDService<UserEntity,Long>{
*/
void synchSitesAuth() throws AppException;
/**
* 重置密码
*
* @param loginName
* @param newPwd
* @return
* @throws AppException
*/
boolean resetUserPwd(String loginName, String newPwd , Context context) throws AppException;
}
\ No newline at end of file
......@@ -289,6 +289,27 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
});
}
@Override
public boolean resetUserPwd(String loginName, String newPwd, Context context) throws AppException {
if(context==null){
throw new AppException("登录过期!");
}
if(context.getUser().getId()!=1){
throw new AppException("当前用户非管理员,不能使用此功能");
}
UserEntity sysUser = this.findByLoginName(loginName);
if (sysUser == null || !sysUser.getLoginName().equals(loginName)) {
throw new AppException("帐号错误!");
}
try {
sysUser.setLoginPwd(SecurityUtil.md5DoubleEncoding(newPwd));
} catch (Exception e) {
throw new AppException("密码转换异常!", e);
}
dao.update(sysUser);
return true;
}
private void updateRedisUserSession(UserEntity userEntity) {
Set<String> keys = cacheService.scan(Constant.LOGIN_TOKEN_KEY + userEntity.getId());
keys.forEach(key -> {
......
......@@ -244,4 +244,18 @@ public class UserController extends BaseCRUDJsonBodyMappingController<UserServic
ret.setMsg(model.get("message_info") == null ? "" : model.remove("message_info").toString());
return ret;
}
@RequestMapping(value = "reset/password", method = RequestMethod.POST)
public String resetPassword(@RequestBody UserEntity entity) {
JSONObject ret = new JSONObject();
try {
service.resetUserPwd(entity.getLoginName(), entity.getNewPwd(),this.getContext());
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_MSG, "密码修改成功!");
} catch (Exception e) {
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, super.convertException(e));
}
return ret.toJSONString();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment