merge
This commit is contained in:
@@ -11,6 +11,8 @@ import com.xwbing.exception.BusinessException;
|
||||
import com.xwbing.util.*;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -95,23 +97,27 @@ public class SysUserService {
|
||||
if (old == null) {
|
||||
throw new BusinessException("该用户不存在");
|
||||
}
|
||||
if (id.equals(CommonDataUtil.getToken(CommonConstant.CURRENT_USER_ID))) {
|
||||
throw new BusinessException("不能删除当前登录用户");
|
||||
SysUser currentInfo = getCurrentInfo();
|
||||
if (currentInfo != null) {
|
||||
if (id.equals(currentInfo.getId())) {
|
||||
throw new BusinessException("不能删除当前登录用户");
|
||||
}
|
||||
if (CommonEnum.YesOrNoEnum.YES.getCode().equals(old.getAdmin())) {
|
||||
throw new BusinessException("不能对管理员进行删除操作");
|
||||
}
|
||||
//删除用户
|
||||
sysUserRepository.delete(id);
|
||||
//删除用户角色
|
||||
List<SysUserRole> sysUserRoles = sysUserRoleService.listByUserId(id);
|
||||
if (CollectionUtils.isNotEmpty(sysUserRoles)) {
|
||||
sysUserRoleService.removeBatch(sysUserRoles);
|
||||
}
|
||||
result.setMessage("删除成功");
|
||||
result.setSuccess(true);
|
||||
return result;
|
||||
} else {
|
||||
throw new BusinessException("未能获取当前登录用户信息");
|
||||
}
|
||||
if (CommonEnum.YesOrNoEnum.YES.getCode().equals(old.getAdmin())) {
|
||||
throw new BusinessException("不能对管理员进行删除操作");
|
||||
}
|
||||
//删除用户
|
||||
sysUserRepository.delete(id);
|
||||
//删除用户角色
|
||||
List<SysUserRole> sysUserRoles = sysUserRoleService.listByUserId(id);
|
||||
if (CollectionUtils.isNotEmpty(sysUserRoles)) {
|
||||
sysUserRoleService.removeBatch(sysUserRoles);
|
||||
}
|
||||
result.setMessage("删除成功");
|
||||
result.setSuccess(true);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,9 +133,6 @@ public class SysUserService {
|
||||
if (old == null) {
|
||||
throw new BusinessException("该用户不存在");
|
||||
}
|
||||
if (old.getId().equals(CommonDataUtil.getToken(CommonConstant.CURRENT_USER_ID))) {
|
||||
throw new BusinessException("不能修改当前登录用户");
|
||||
}
|
||||
if (CommonEnum.YesOrNoEnum.YES.getCode().equals(old.getAdmin())) {
|
||||
throw new BusinessException("不能对管理员进行修改操作");
|
||||
}
|
||||
@@ -160,6 +163,20 @@ public class SysUserService {
|
||||
return sysUserRepository.findOne(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户对象
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public SysUser getCurrentInfo() {
|
||||
Subject subject = SecurityUtils.getSubject();
|
||||
if (subject != null && subject.getPrincipal() != null) {
|
||||
return (SysUser) subject.getPrincipal();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表查询
|
||||
*
|
||||
@@ -193,28 +210,33 @@ public class SysUserService {
|
||||
if (old == null) {
|
||||
throw new BusinessException("未查询到用户信息");
|
||||
}
|
||||
if (CommonDataUtil.getToken(CommonConstant.CURRENT_USER_ID).equals(id)) {
|
||||
throw new BusinessException("不能重置当前登录用户");
|
||||
SysUser currentInfo = getCurrentInfo();
|
||||
if (currentInfo != null) {
|
||||
if (id.equals(currentInfo.getId())) {
|
||||
throw new BusinessException("不能重置当前登录用户");
|
||||
}
|
||||
if (CommonEnum.YesOrNoEnum.YES.getCode().equals(old.getAdmin())) {
|
||||
throw new BusinessException("管理员密码不能重置");
|
||||
}
|
||||
//生成密码
|
||||
String[] str = PassWordUtil.getUserSecret(null, null);
|
||||
old.setSalt(str[1]);
|
||||
old.setPassword(str[2]);
|
||||
old.setModifiedTime(new Date());
|
||||
SysUser save = sysUserRepository.save(old);
|
||||
if (save == null) {
|
||||
throw new BusinessException("重置密码失败");
|
||||
}
|
||||
boolean send = sendEmail(old, str[0]);
|
||||
if (!send) {
|
||||
throw new BusinessException("发送密码邮件错误");
|
||||
}
|
||||
result.setSuccess(true);
|
||||
result.setMessage("重置密码成功");
|
||||
return result;
|
||||
} else {
|
||||
throw new BusinessException("未能获取当前登录用户信息");
|
||||
}
|
||||
if (CommonEnum.YesOrNoEnum.YES.getCode().equals(old.getAdmin())) {
|
||||
throw new BusinessException("管理员密码不能重置");
|
||||
}
|
||||
//生成密码
|
||||
String[] str = PassWordUtil.getUserSecret(null, null);
|
||||
old.setSalt(str[1]);
|
||||
old.setPassword(str[2]);
|
||||
old.setModifiedTime(new Date());
|
||||
SysUser save = sysUserRepository.save(old);
|
||||
if (save == null) {
|
||||
throw new BusinessException("重置密码失败");
|
||||
}
|
||||
boolean send = sendEmail(old, str[0]);
|
||||
if (!send) {
|
||||
throw new BusinessException("发送密码邮件错误");
|
||||
}
|
||||
result.setSuccess(true);
|
||||
result.setMessage("重置密码成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -81,11 +81,6 @@
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
<version>${fileUpLoad.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-spring</artifactId>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>boot-web</finalName>
|
||||
|
||||
@@ -2,14 +2,12 @@ package com.xwbing.controller.sys;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xwbing.annotation.LogInfo;
|
||||
import com.xwbing.constant.CommonConstant;
|
||||
import com.xwbing.constant.CommonEnum;
|
||||
import com.xwbing.domain.entity.sys.*;
|
||||
import com.xwbing.domain.entity.vo.*;
|
||||
import com.xwbing.redis.RedisService;
|
||||
import com.xwbing.service.sys.*;
|
||||
import com.xwbing.shiro.UsernamePasswordCaptchaToken;
|
||||
import com.xwbing.util.CommonDataUtil;
|
||||
import com.xwbing.util.IpUtil;
|
||||
import com.xwbing.util.JsonResult;
|
||||
import com.xwbing.util.RestMessage;
|
||||
@@ -132,7 +130,7 @@ public class SysUserControl {
|
||||
return JsonResult.toJSONObj(new Object(), "登录成功");
|
||||
}
|
||||
}else {
|
||||
return JsonResult.toJSONObj("登录失败");
|
||||
return JsonResult.toJSONObj("你认证未通过,请重新登录");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,17 +159,18 @@ public class SysUserControl {
|
||||
return JsonResult.toJSONObj("没有获取到用户登录信息");
|
||||
}
|
||||
|
||||
@LogInfo("修改密码")
|
||||
@ApiOperation(value = "修改密码", response = RestMessageVo.class)
|
||||
@LogInfo("当前用修改密码")
|
||||
@ApiOperation(value = "当前用户修改密码", response = RestMessageVo.class)
|
||||
@PostMapping("updatePassWord")
|
||||
public JSONObject updatePassWord(@RequestParam String newPassWord, @RequestParam String oldPassWord, @RequestParam String id) {
|
||||
if (StringUtils.isEmpty(id)) {
|
||||
return JsonResult.toJSONObj("主键不能为空");
|
||||
public JSONObject updatePassWord(@RequestParam String newPassWord, @RequestParam String oldPassWord) {
|
||||
SysUser currentInfo = sysUserService.getCurrentInfo();
|
||||
if(currentInfo==null){
|
||||
return JsonResult.toJSONObj("没有获取到当前登录用户信息");
|
||||
}
|
||||
if (StringUtils.isEmpty(newPassWord) || StringUtils.isEmpty(oldPassWord)) {
|
||||
return JsonResult.toJSONObj("原密码或新密码不能为空");
|
||||
}
|
||||
RestMessage restMessage = sysUserService.updatePassWord(newPassWord, oldPassWord, id);
|
||||
RestMessage restMessage = sysUserService.updatePassWord(newPassWord, oldPassWord, currentInfo.getId());
|
||||
return JsonResult.toJSONObj(restMessage);
|
||||
}
|
||||
|
||||
@@ -190,7 +189,7 @@ public class SysUserControl {
|
||||
@ApiOperation(value = "获取当前登录用户信息")
|
||||
@GetMapping("getLoginUserInfo")
|
||||
public JSONObject getLoginUserInfo() {
|
||||
SysUser sysUser = sysUserService.getById((String) CommonDataUtil.getToken(CommonConstant.CURRENT_USER_ID));
|
||||
SysUser sysUser = sysUserService.getCurrentInfo();
|
||||
if (sysUser == null) {
|
||||
return JsonResult.toJSONObj("未获取到当前登录用户信息");
|
||||
}
|
||||
|
||||
@@ -50,6 +50,12 @@
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
</dependency>
|
||||
<!-- shiro -->
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-spring</artifactId>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
<!-- 支持注解@ConfigurationProperties 需要get/set方法-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
Reference in New Issue
Block a user