Commit 341f8a999b599c0e988b2d88e707f8cadb543eea
Exists in
master
and in
1 other branch
Merge remote-tracking branch 'origin/master'
Showing 3 changed files
platform-common/src/main/java/com/lyms/platform/common/utils/LoginUtil.java
View file @
341f8a9
... | ... | @@ -64,7 +64,7 @@ |
64 | 64 | return null; |
65 | 65 | } |
66 | 66 | |
67 | - public static boolean sendVerCode(String phone, String typeId, String token) { | |
67 | + public static LoginContext sendVerCode(String phone, String typeId, String token) { | |
68 | 68 | HttpClient client = new HttpClient(); |
69 | 69 | String query = "?phone=" + phone + "&typeId=" + typeId + "&token=" + token + "&userType=2"; |
70 | 70 | GetMethod get = new MessageUtil.UTF8GetMethod("http://passport.healthbaby.com.cn/v1/vercode.action" + query); |
71 | 71 | |
... | ... | @@ -77,14 +77,12 @@ |
77 | 77 | get.releaseConnection(); |
78 | 78 | if(200 == statusCode) { |
79 | 79 | LoginContext loginState = JsonUtil.str2Obj(result, LoginContext.class); |
80 | - if(0 == loginState.getErrorcode()) { | |
81 | - return true; | |
82 | - } | |
80 | + return loginState; | |
83 | 81 | } |
84 | 82 | } catch (Exception e) { |
85 | 83 | e.printStackTrace(); |
86 | 84 | } |
87 | - return false; | |
85 | + return null; | |
88 | 86 | } |
89 | 87 | |
90 | 88 |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/UsersController.java
View file @
341f8a9
... | ... | @@ -115,8 +115,13 @@ |
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 | + Users users1 = new Users(); | |
121 | + users1.setId(users.get(0).getId()); | |
122 | + users1.setLastLoginTime(new Date()); | |
123 | + usersService.updateUsers(users1); | |
124 | + | |
120 | 125 | Map<String, Object> result = new HashMap<>(); |
121 | 126 | result.put("token", key); |
122 | 127 | ResultUtils.buildSuccessResultAndWrite(response, result); |
123 | 128 | |
124 | 129 | |
125 | 130 | |
126 | 131 | |
127 | 132 | |
128 | 133 | |
129 | 134 | |
... | ... | @@ -149,24 +154,61 @@ |
149 | 154 | } |
150 | 155 | |
151 | 156 | |
152 | - if(LoginUtil.sendVerCode(phone, typeId, token) ) { | |
153 | - ResultUtils.buildResultAndWrite(httpServletResponse, ErrorCodeConstants.SUCCESS, "发送成功"); | |
154 | - } else { | |
155 | - ResultUtils.buildResultAndWrite(httpServletResponse, ErrorCodeConstants.SUCCESS, "发送失败"); | |
157 | + LoginContext loginContext = LoginUtil.sendVerCode(phone, typeId, token); | |
158 | + if(null != loginContext) { | |
159 | + ResultUtils.buildResultAndWrite(httpServletResponse, loginContext.getErrorcode(), loginContext.getErrormsg()); | |
160 | + return; | |
156 | 161 | } |
162 | + ResultUtils.buildResultAndWrite(httpServletResponse, ErrorCodeConstants.SYSTEM_ERROR, "服务器内部错误"); | |
163 | + | |
157 | 164 | } |
158 | 165 | |
159 | 166 | |
160 | 167 | /** |
161 | - * 获取 AMS 用户登录信息(用户、最后登录时间) | |
168 | + * 获取 登录用户信息(用户、最后登录时间) | |
162 | 169 | */ |
163 | - @RequestMapping(value = "/status/sign", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8") | |
170 | + @RequestMapping(value = "/users/currentUser", method = RequestMethod.GET) | |
164 | 171 | @TokenRequired |
165 | - public void usersLoginMsg(HttpServletResponse response) { | |
172 | + public void usersLoginMsg(HttpServletResponse response, HttpServletRequest request) { | |
173 | + LoginContext loginContext = (LoginContext) request.getAttribute("loginContext"); | |
174 | + Users users = null; | |
175 | + if(null != loginContext) { | |
176 | + users = usersService.getUsers(loginContext.getId()); | |
177 | + } | |
166 | 178 | |
179 | + UserRoleMapsQuery query = new UserRoleMapsQuery(); | |
180 | + query.setUserId(users.getId()); | |
181 | + query.setYn(YnEnums.YES.getId()); | |
182 | + List<UserRoleMaps> userRoleMapses = userRoleMapsService.queryUserRoleMaps(query); | |
183 | + List<Roles> roles = new ArrayList<>(); | |
184 | + for(UserRoleMaps roleMaps : userRoleMapses) { | |
185 | + roles.add(rolesService.getRoles(roleMaps.getRoleId())); | |
186 | + } | |
187 | + Map<String, Object> map = new HashMap<>(); | |
188 | + map.put("user", users); | |
189 | + map.put("roles", roles); | |
167 | 190 | |
191 | + ResultUtils.buildSuccessResultAndWrite(response, map); | |
168 | 192 | } |
169 | 193 | |
194 | + | |
195 | + /** | |
196 | + * 获取 用户角色信息 | |
197 | + */ | |
198 | + @RequestMapping(value = "/users/userRole/{id}", method = RequestMethod.GET) | |
199 | + @TokenRequired | |
200 | + public void userRole(HttpServletResponse response, HttpServletRequest request, @PathVariable(value = "id") Integer id) { | |
201 | + UserRoleMapsQuery query = new UserRoleMapsQuery(); | |
202 | + query.setUserId(id); | |
203 | + query.setYn(YnEnums.YES.getId()); | |
204 | + List<UserRoleMaps> userRoleMapses = userRoleMapsService.queryUserRoleMaps(query); | |
205 | + List<Roles> roles = new ArrayList<>(); | |
206 | + for(UserRoleMaps roleMaps : userRoleMapses) { | |
207 | + roles.add(rolesService.getRoles(roleMaps.getRoleId())); | |
208 | + } | |
209 | + | |
210 | + ResultUtils.buildSuccessResultAndWrite(response, roles); | |
211 | + } | |
170 | 212 | |
171 | 213 | |
172 | 214 |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/inteceptor/TokenValidateInteceptor.java
View file @
341f8a9
... | ... | @@ -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,10 @@ |
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 | + | |
80 | 84 | LogUtil.tokenInfo(" userId:" + users.getId() + ", ,url:" + httpServletRequest.getRequestURI() + ",method:" + httpServletRequest.getMethod()); |
81 | 85 | |
82 | 86 | return loginContext.isLogin(); |