Commit cb0caa28d3fa90ef2a7aa3ac5fb181851b3bceeb
1 parent
884fed5dc8
Exists in
master
and in
8 other branches
platform permission
用户登录
Showing 2 changed files with 37 additions and 20 deletions
platform-common/src/main/java/com/lyms/platform/common/utils/LoginUtil.java
View file @
cb0caa2
... | ... | @@ -64,26 +64,27 @@ |
64 | 64 | return null; |
65 | 65 | } |
66 | 66 | |
67 | - public static String loginHospitalUser(String phone, String pwd, String typeId, String token) { | |
67 | + public static LoginContext loginHospitalUser(String account, String pwd, String typeId, String token) { | |
68 | 68 | HttpClient client = new HttpClient(); |
69 | 69 | PostMethod post = new MessageUtil.UTF8PostMethod("http://passport.healthbaby.com.cn/v1/userLogin.action"); |
70 | + NameValuePair[] data = { | |
71 | + new NameValuePair("account", account), | |
72 | + new NameValuePair("typeId", typeId), | |
73 | + new NameValuePair("password", org.apache.commons.lang.StringUtils.isBlank(pwd)?"p":md5(pwd).toUpperCase()) | |
74 | + }; | |
75 | + post.setRequestBody(data); | |
76 | + post.setRequestHeader("Authorization", token); | |
70 | 77 | try { |
71 | - NameValuePair[] data = { | |
72 | - new NameValuePair("phone", phone), | |
73 | - new NameValuePair("typeId", typeId), | |
74 | - new NameValuePair("password", org.apache.commons.lang.StringUtils.isBlank(pwd)?"p":md5(pwd)) | |
75 | - }; | |
76 | - post.setRequestBody(data); | |
77 | - post.setRequestHeader("Authorization", token); | |
78 | 78 | client.executeMethod(post); |
79 | 79 | int statusCode = post.getStatusCode(); |
80 | 80 | String result = new String(post.getResponseBodyAsString()); |
81 | 81 | |
82 | 82 | post.releaseConnection(); |
83 | + LoginContext loginState = new LoginContext(); | |
83 | 84 | if (200 == statusCode) { |
84 | - LoginContext loginState = JsonUtil.str2Obj(result, LoginContext.class); | |
85 | + loginState = JsonUtil.str2Obj(result, LoginContext.class); | |
85 | 86 | if (0 == loginState.getErrorcode()) { |
86 | - return loginState.getToken(); | |
87 | + return loginState; | |
87 | 88 | } |
88 | 89 | } |
89 | 90 | } catch (Exception e) { |
... | ... | @@ -92,7 +93,7 @@ |
92 | 93 | return null; |
93 | 94 | } |
94 | 95 | |
95 | - public static String login(String phone, String varCode, String typeId, String token) { | |
96 | + public static LoginContext login(String phone, String varCode, String typeId, String token) { | |
96 | 97 | HttpClient client = new HttpClient(); |
97 | 98 | PostMethod post = new MessageUtil.UTF8PostMethod("http://passport.healthbaby.com.cn/v1/login.action"); |
98 | 99 | NameValuePair[] data = { |
99 | 100 | |
100 | 101 | |
... | ... | @@ -108,10 +109,11 @@ |
108 | 109 | String result = new String(post.getResponseBodyAsString()); |
109 | 110 | |
110 | 111 | post.releaseConnection(); |
112 | + LoginContext loginState = new LoginContext(); | |
111 | 113 | if (200 == statusCode) { |
112 | - LoginContext loginState = JsonUtil.str2Obj(result, LoginContext.class); | |
114 | + loginState = JsonUtil.str2Obj(result, LoginContext.class); | |
113 | 115 | if (0 == loginState.getErrorcode()) { |
114 | - return loginState.getToken(); | |
116 | + return loginState; | |
115 | 117 | } |
116 | 118 | } |
117 | 119 | } catch (Exception e) { |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/UsersController.java
View file @
cb0caa2
... | ... | @@ -171,10 +171,11 @@ |
171 | 171 | */ |
172 | 172 | @RequestMapping(value = "/tokens", method = RequestMethod.POST) |
173 | 173 | public void usersLogin(@RequestParam(value = "account") String account, |
174 | - @RequestParam(value = "vercode") String code, | |
174 | + @RequestParam(value = "vercode", required = false) String code, | |
175 | + @RequestParam(value = "password", required = false) String password, | |
175 | 176 | HttpServletResponse response) { |
176 | 177 | Map<String, Object> resultMsgMap = new HashMap<>(); |
177 | - if (StringUtils.isEmpty(account) || StringUtils.isEmpty(code)) { | |
178 | + if (StringUtils.isEmpty(account) && (StringUtils.isEmpty(code) || StringUtils.isEmpty(password))) { | |
178 | 179 | resultMsgMap.put(ResultUtils.ERROR_CODE, ConstantInterface.PARAMETER_ERROR);//参数错误 |
179 | 180 | resultMsgMap.put(ResultUtils.ERROR_MSG, "登录账户或者验证码为空,请输入"); |
180 | 181 | //把这个map转成一个json字符串输出到前台 |
181 | 182 | |
182 | 183 | |
183 | 184 | |
184 | 185 | |
... | ... | @@ -182,26 +183,40 @@ |
182 | 183 | return; |
183 | 184 | } |
184 | 185 | |
186 | + //code 不为空使用手机登录, password不为空时使用帐号登录 | |
185 | 187 | UsersQuery usersQuery = new UsersQuery(); |
186 | - usersQuery.setPhone(account); | |
188 | + usersQuery.setYn(YnEnums.YES.getId()); | |
189 | + if(null != code) { | |
190 | + usersQuery.setPhone(account); | |
191 | + } | |
192 | + if(null != password) { | |
193 | + usersQuery.setAccount(account); | |
194 | + } | |
187 | 195 | List<Users> users = usersService.queryUsers(usersQuery); |
188 | 196 | if(0 == users.size()) { |
189 | 197 | ResultUtils.buildParameterErrorResultAndWrite(response, "该账户不存在"); |
190 | 198 | return; |
191 | 199 | } |
192 | 200 | |
193 | - String key =LoginUtil.login(account, code, typeId, token); | |
194 | - if(null != key) { | |
201 | + LoginContext loginContext = null; | |
202 | + if(null != code) { | |
203 | + loginContext =LoginUtil.login(account, code, typeId, token); | |
204 | + } | |
205 | + if(null != password) { | |
206 | + loginContext = LoginUtil.loginHospitalUser(account, password, typeId, token); | |
207 | + } | |
208 | + | |
209 | + if(null != loginContext) { | |
195 | 210 | Users users1 = new Users(); |
196 | 211 | users1.setId(users.get(0).getId()); |
197 | 212 | users1.setLastLoginTime(new Date()); |
198 | 213 | usersService.updateUsers(users1); |
199 | 214 | |
200 | 215 | Map<String, Object> result = new HashMap<>(); |
201 | - result.put("token", key); | |
216 | + result.put("token", loginContext.getToken()); | |
202 | 217 | ResultUtils.buildSuccessResultAndWrite(response, result); |
203 | 218 | }else { |
204 | - ResultUtils.buildResultAndWrite(response, ErrorCodeConstants.PARAMETER_ERROR, "登录失败,手机或验证码错误"); | |
219 | + ResultUtils.buildResultAndWrite(response, ErrorCodeConstants.PARAMETER_ERROR, loginContext.getErrormsg()); | |
205 | 220 | } |
206 | 221 | } |
207 | 222 |