|
@@ -3,12 +3,14 @@ package com.xiaoan.web.backend;
|
|
import com.xiaoan.common.constant.MsgCode;
|
|
import com.xiaoan.common.constant.MsgCode;
|
|
import com.xiaoan.common.util.PasswordUtils;
|
|
import com.xiaoan.common.util.PasswordUtils;
|
|
import com.xiaoan.common.util.ResultJson;
|
|
import com.xiaoan.common.util.ResultJson;
|
|
|
|
+import com.xiaoan.domain.backend.ResourceEntity;
|
|
import com.xiaoan.domain.backend.UserEntity;
|
|
import com.xiaoan.domain.backend.UserEntity;
|
|
import com.xiaoan.domain.dto.request.LoginRequest;
|
|
import com.xiaoan.domain.dto.request.LoginRequest;
|
|
import com.xiaoan.domain.dto.request.UserRequest;
|
|
import com.xiaoan.domain.dto.request.UserRequest;
|
|
import com.xiaoan.service.backend.ResourceService;
|
|
import com.xiaoan.service.backend.ResourceService;
|
|
import com.xiaoan.service.backend.RoleService;
|
|
import com.xiaoan.service.backend.RoleService;
|
|
import com.xiaoan.service.backend.UserService;
|
|
import com.xiaoan.service.backend.UserService;
|
|
|
|
+import com.xiaoan.service.backend.dto.ResourcePermissions;
|
|
import com.xiaoan.service.backend.dto.ResourceTree;
|
|
import com.xiaoan.service.backend.dto.ResourceTree;
|
|
import com.xiaoan.web.shiro.JWTUtil;
|
|
import com.xiaoan.web.shiro.JWTUtil;
|
|
import com.xiaoan.web.shiro.JwtUtil2;
|
|
import com.xiaoan.web.shiro.JwtUtil2;
|
|
@@ -20,6 +22,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
+import springfox.documentation.annotations.ApiIgnore;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
@@ -28,7 +31,7 @@ import java.util.concurrent.TimeUnit;
|
|
/**
|
|
/**
|
|
* Created by owen on 2020/2/19 0019 15:53
|
|
* Created by owen on 2020/2/19 0019 15:53
|
|
*/
|
|
*/
|
|
-@Api(tags = "IndexController", description = "后台登录管理")
|
|
|
|
|
|
+@Api(value = "IndexController",tags = "后台登录管理")
|
|
@RestController
|
|
@RestController
|
|
//@RequestMapping("api/manage/user")
|
|
//@RequestMapping("api/manage/user")
|
|
@Transactional
|
|
@Transactional
|
|
@@ -51,7 +54,72 @@ public class IndexController {
|
|
private RedisTemplate<String, String> redisTemplate;
|
|
private RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
|
|
|
|
- @ApiOperation("查询用户信息")
|
|
|
|
|
|
+ @ApiIgnore
|
|
|
|
+ @ApiOperation("测试权限")
|
|
|
|
+ @PostMapping(value = "loginPre")
|
|
|
|
+ public ResultJson loginPre(@RequestBody LoginRequest param) throws Exception {
|
|
|
|
+ log.warn("run login , userName:{}, password:{}", param.getUserName(), param.getPassword());
|
|
|
|
+ // 1.获取用户
|
|
|
|
+ UserEntity userEntity = userService.findByUserName(param.getUserName());
|
|
|
|
+ if (userEntity == null){
|
|
|
|
+ return new ResultJson(MsgCode.e_ADMIN_4001, MsgCode.msg_ADMIN_4001);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 验证密码
|
|
|
|
+ String decryptName = PasswordUtils.decrypt(userEntity.getPassword(), param.getPassword(), PasswordUtils.getStaticSalt());
|
|
|
|
+ if (!param.getUserName().equals(decryptName)) {
|
|
|
|
+ return new ResultJson(MsgCode.e_ADMIN_4002, MsgCode.msg_ADMIN_4002);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 检查账号是否启用
|
|
|
|
+ if (userEntity.getStatus() != 0) {
|
|
|
|
+ return new ResultJson(MsgCode.e_ADMIN_4003, MsgCode.msg_ADMIN_4003);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// List<ResourcePermissions> ResourceList = resourceService.findList();
|
|
|
|
+ List<ResourceTree> resourcesTreeByUserPermission = resourceService.getResourcesAllByUserPermission(userEntity);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 获取用户角色
|
|
|
|
+ List<String> roles = userService.findRoleByUserId(userEntity.getId());
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 创建新token
|
|
|
|
+ HashMap<String, Object> tokenMap = new HashMap<>();
|
|
|
|
+ tokenMap.put("userName", userEntity.getUserName());
|
|
|
|
+ tokenMap.put("id", userEntity.getId());
|
|
|
|
+ tokenMap.put("role", roles);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ String token = JwtUtil2.createJWT(-1, tokenMap);
|
|
|
|
+//
|
|
|
|
+
|
|
|
|
+ HashMap<String, Object> result = new HashMap<>();
|
|
|
|
+ result.put("user", userEntity);
|
|
|
|
+// result.put("token", token);
|
|
|
|
+ result.put("permission", resourcesTreeByUserPermission);
|
|
|
|
+ result.put("role", roles);
|
|
|
|
+// result.put("ResourceList", resourcesTreeByUserPermission);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 更新到 redis, 有效期24h, 旧token无效
|
|
|
|
+ redisTemplate.opsForValue().set(userEntity.getUserName(), token, Long.parseLong("23"), TimeUnit.HOURS);
|
|
|
|
+
|
|
|
|
+ // 更新登录次数
|
|
|
|
+ Integer loginCount = userEntity.getViewCount();
|
|
|
|
+ loginCount++;
|
|
|
|
+ userEntity.setViewCount(loginCount);
|
|
|
|
+ userEntity.setUpdateTime(new Date());
|
|
|
|
+
|
|
|
|
+ userService.update(userEntity);
|
|
|
|
+
|
|
|
|
+ return new ResultJson(MsgCode.SUCCESS_CODE, result);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation("登录")
|
|
@PostMapping(value = "admin/login")
|
|
@PostMapping(value = "admin/login")
|
|
public ResultJson login(@RequestBody LoginRequest param) throws Exception {
|
|
public ResultJson login(@RequestBody LoginRequest param) throws Exception {
|
|
log.warn("run login , userName:{}, password:{}", param.getUserName(), param.getPassword());
|
|
log.warn("run login , userName:{}, password:{}", param.getUserName(), param.getPassword());
|
|
@@ -73,9 +141,10 @@ public class IndexController {
|
|
}
|
|
}
|
|
|
|
|
|
// 获取用户菜单
|
|
// 获取用户菜单
|
|
- List<ResourceTree> resourcesByUserMenu = resourceService.getResourcesTreeByUserMenu(userEntity);
|
|
|
|
|
|
+// List<ResourceTree> resourcesByUserMenu = resourceService.getResourcesTreeByUserMenu(userEntity);
|
|
|
|
|
|
- List<ResourceTree> resourcesTreeByUserPermission = resourceService.getResourcesTreeByUserPermission(userEntity);
|
|
|
|
|
|
+// List<ResourceTree> resourcesTreeByUserPermission = resourceService.getResourcesTreeByUserPermission(userEntity);
|
|
|
|
+ List<ResourceTree> resourcesTreeByUserPermission = resourceService.getResourcesAllByUserPermission(userEntity);
|
|
|
|
|
|
// 获取用户角色
|
|
// 获取用户角色
|
|
List<String> roles = userService.findRoleByUserId(userEntity.getId());
|
|
List<String> roles = userService.findRoleByUserId(userEntity.getId());
|
|
@@ -115,6 +184,7 @@ public class IndexController {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @ApiOperation("退出")
|
|
@GetMapping("admin/logout")
|
|
@GetMapping("admin/logout")
|
|
public ResultJson logout(HttpServletRequest request) {
|
|
public ResultJson logout(HttpServletRequest request) {
|
|
|
|
|
|
@@ -130,4 +200,7 @@ public class IndexController {
|
|
return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.msg_SUCCESS);
|
|
return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.msg_SUCCESS);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|