Commit 54c37947137c4db8dfc168efcb96f51ba674847e
1 parent
7856e32a73
Exists in
master
and in
1 other branch
platform permission
fix bug
Showing 2 changed files with 46 additions and 4 deletions
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/UsersController.java
View file @
54c3794
| ... | ... | @@ -115,7 +115,7 @@ |
| 115 | 115 | return; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - String key =LoginUtil.login(account,code, typeId, token); | |
| 118 | + String key =LoginUtil.login(account, code, typeId, token); | |
| 119 | 119 | if(null != key) { |
| 120 | 120 | Map<String, Object> result = new HashMap<>(); |
| 121 | 121 | result.put("token", key); |
| 122 | 122 | |
| 123 | 123 | |
| 124 | 124 | |
| 125 | 125 | |
| 126 | 126 | |
| ... | ... | @@ -158,15 +158,50 @@ |
| 158 | 158 | |
| 159 | 159 | |
| 160 | 160 | /** |
| 161 | - * 获取 AMS 用户登录信息(用户、最后登录时间) | |
| 161 | + * 获取 登录用户信息(用户、最后登录时间) | |
| 162 | 162 | */ |
| 163 | - @RequestMapping(value = "/status/sign", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8") | |
| 163 | + @RequestMapping(value = "/users/currentUser", method = RequestMethod.GET) | |
| 164 | 164 | @TokenRequired |
| 165 | - public void usersLoginMsg(HttpServletResponse response) { | |
| 165 | + public void usersLoginMsg(HttpServletResponse response, HttpServletRequest request) { | |
| 166 | + LoginContext loginContext = (LoginContext) request.getAttribute("loginContext"); | |
| 167 | + Users users = null; | |
| 168 | + if(null != loginContext) { | |
| 169 | + users = usersService.getUsers(loginContext.getId()); | |
| 170 | + } | |
| 166 | 171 | |
| 172 | + UserRoleMapsQuery query = new UserRoleMapsQuery(); | |
| 173 | + query.setUserId(users.getId()); | |
| 174 | + query.setYn(YnEnums.YES.getId()); | |
| 175 | + List<UserRoleMaps> userRoleMapses = userRoleMapsService.queryUserRoleMaps(query); | |
| 176 | + List<Roles> roles = new ArrayList<>(); | |
| 177 | + for(UserRoleMaps roleMaps : userRoleMapses) { | |
| 178 | + roles.add(rolesService.getRoles(roleMaps.getRoleId())); | |
| 179 | + } | |
| 180 | + Map<String, Object> map = new HashMap<>(); | |
| 181 | + map.put("user", users); | |
| 182 | + map.put("roles", roles); | |
| 167 | 183 | |
| 184 | + ResultUtils.buildSuccessResultAndWrite(response, map); | |
| 168 | 185 | } |
| 169 | 186 | |
| 187 | + | |
| 188 | + /** | |
| 189 | + * 获取 用户角色信息 | |
| 190 | + */ | |
| 191 | + @RequestMapping(value = "/users/userRole/{id}", method = RequestMethod.GET) | |
| 192 | + @TokenRequired | |
| 193 | + public void userRole(HttpServletResponse response, HttpServletRequest request, @PathVariable(value = "id") Integer id) { | |
| 194 | + UserRoleMapsQuery query = new UserRoleMapsQuery(); | |
| 195 | + query.setUserId(id); | |
| 196 | + query.setYn(YnEnums.YES.getId()); | |
| 197 | + List<UserRoleMaps> userRoleMapses = userRoleMapsService.queryUserRoleMaps(query); | |
| 198 | + List<Roles> roles = new ArrayList<>(); | |
| 199 | + for(UserRoleMaps roleMaps : userRoleMapses) { | |
| 200 | + roles.add(rolesService.getRoles(roleMaps.getRoleId())); | |
| 201 | + } | |
| 202 | + | |
| 203 | + ResultUtils.buildSuccessResultAndWrite(response, roles); | |
| 204 | + } | |
| 170 | 205 | |
| 171 | 206 | |
| 172 | 207 |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/inteceptor/TokenValidateInteceptor.java
View file @
54c3794
| ... | ... | @@ -20,6 +20,7 @@ |
| 20 | 20 | import javax.servlet.http.HttpServletRequest; |
| 21 | 21 | import javax.servlet.http.HttpServletResponse; |
| 22 | 22 | import java.lang.annotation.Annotation; |
| 23 | +import java.util.Date; | |
| 23 | 24 | |
| 24 | 25 | /** |
| 25 | 26 | * 验证token拦截器 |
| 26 | 27 | |
| ... | ... | @@ -76,7 +77,13 @@ |
| 76 | 77 | if(null == users) { |
| 77 | 78 | throw new TokenException(); |
| 78 | 79 | } |
| 80 | + loginContext.setId(users.getId()); | |
| 81 | + loginContext.setToken(token); | |
| 79 | 82 | httpServletRequest.setAttribute("loginContext", loginContext); |
| 83 | + Users users1 = new Users(); | |
| 84 | + users1.setId(users.getId()); | |
| 85 | + users1.setLastLoginTime(new Date()); | |
| 86 | + usersService.updateUsers(users1); | |
| 80 | 87 | LogUtil.tokenInfo(" userId:" + users.getId() + ", ,url:" + httpServletRequest.getRequestURI() + ",method:" + httpServletRequest.getMethod()); |
| 81 | 88 | |
| 82 | 89 | return loginContext.isLogin(); |