Commit d6ab3746 authored by Fred's avatar Fred

111

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