Commit d6ab3746 authored by Fred's avatar Fred

111

parent ddd25bb7
...@@ -12,6 +12,9 @@ public class Constant { ...@@ -12,6 +12,9 @@ public class Constant {
/** 超级管理员ID */ /** 超级管理员ID */
public static final int SUPER_ADMIN = 1; public static final int SUPER_ADMIN = 1;
/** 重置默认密码 */
public static final String DEFAULT_PASSWORD = "abc123456";
/** 数据状态 */ /** 数据状态 */
public static final int STATE_DELETE = 0; public static final int STATE_DELETE = 0;
......
package com.govmade.common.validator;
import com.govmade.common.exception.RRException;
import cn.hutool.core.util.StrUtil;
/**
* 数据校验
*
* @author Fred
* @email fangtaosh@qq.com
* @date 2018年8月8日
*/
public abstract class Assert {
public static void isBlank(String str, String message) {
if (StrUtil.isBlank(str)) {
throw new RRException(message);
}
}
public static void isNull(Object object, String message) {
if (object == null) {
throw new RRException(message);
}
}
}
package com.govmade.modules.system.controller; package com.govmade.modules.system.controller;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.shiro.crypto.hash.Sha256Hash;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -15,11 +13,10 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -15,11 +13,10 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.google.common.collect.Sets;
import com.govmade.common.utils.Constant; import com.govmade.common.utils.Constant;
import com.govmade.common.utils.PageUtils; import com.govmade.common.utils.PageUtils;
import com.govmade.common.utils.R; import com.govmade.common.utils.R;
import com.govmade.common.utils.ShiroUtils; import com.govmade.common.validator.Assert;
import com.govmade.modules.basic.controller.AbstractController; import com.govmade.modules.basic.controller.AbstractController;
import com.govmade.modules.system.entity.UserEntity; import com.govmade.modules.system.entity.UserEntity;
import com.govmade.modules.system.service.UserService; import com.govmade.modules.system.service.UserService;
...@@ -50,7 +47,7 @@ public class UserController extends AbstractController { ...@@ -50,7 +47,7 @@ public class UserController extends AbstractController {
if (this.userService.checkUser(ue.getUsername()) > 0) { if (this.userService.checkUser(ue.getUsername()) > 0) {
return R.error(ue.getUsername() + " 已存在!"); return R.error(ue.getUsername() + " 已存在!");
} }
String password = SecureUtil.md5("123456"); String password = SecureUtil.md5(Constant.DEFAULT_PASSWORD);
ue.setPassword(password); ue.setPassword(password);
} }
userService.save(ue); userService.save(ue);
...@@ -88,17 +85,15 @@ public class UserController extends AbstractController { ...@@ -88,17 +85,15 @@ public class UserController extends AbstractController {
} }
/** /**
* 删除、批量删除用户 * 批量删除用户
* *
* @param ids * @param ids
* @return * @return
*/ */
@DeleteMapping("/delete") @DeleteMapping("/delete")
public R deleteUser() { public R deleteUser(@RequestBody Set<Long> ids) {
Assert.isNull(ids, "删除项不能为空");
Set<Long> ids = Sets.newHashSet();
ids.add(1L);
ids.add(2L);
userService.deleteBatch(ids); userService.deleteBatch(ids);
return R.ok(); return R.ok();
} }
...@@ -110,13 +105,13 @@ public class UserController extends AbstractController { ...@@ -110,13 +105,13 @@ public class UserController extends AbstractController {
* @return * @return
*/ */
@PostMapping("/reset") @PostMapping("/reset")
public R reset(UserEntity ue) { public R reset(Long id) {
if (null != ue.getId()) { Assert.isNull(id, "必选选择一个用户");
String password = SecureUtil.md5("123456"); String password = SecureUtil.md5(Constant.DEFAULT_PASSWORD);
UserEntity ue = new UserEntity();
ue.setPassword(password); ue.setPassword(password);
userService.updateById(ue); userService.updateById(ue);
}
return R.ok(); return R.ok();
} }
...@@ -126,18 +121,17 @@ public class UserController extends AbstractController { ...@@ -126,18 +121,17 @@ public class UserController extends AbstractController {
*/ */
@PutMapping("updatePassword") @PutMapping("updatePassword")
public R password(String password, String newPassword) { public R password(String password, String newPassword) {
Assert.isBlank(newPassword, "新密码不为能空");
password = new Sha256Hash(password).toHex(); password = SecureUtil.md5(password);
newPassword = new Sha256Hash(newPassword).toHex(); newPassword = SecureUtil.md5(newPassword);
// int count = userService.updatePassword(ShiroUtils.getUserId(), password,
// newPassword);
// if (count == 0) {
// return R.error("原密码不正确");
// }
ShiroUtils.logout(); // 更新密码
boolean flag = userService.updatePassword(getUserId(), password, newPassword);
if (!flag) {
return R.error("原密码不正确");
}
return R.ok(); return R.ok();
} }
......
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