提交 | 用户 | age
|
a6a76f
|
1 |
package com.yc.action.login; |
F |
2 |
|
10a409
|
3 |
import com.alibaba.fastjson.JSON; |
a6a76f
|
4 |
import com.google.gson.Gson; |
F |
5 |
import com.yc.action.BaseAction; |
|
6 |
import com.yc.action.grid.GridUtils; |
a9a8e7
|
7 |
import com.yc.api.bean.Gfrom; |
a6a76f
|
8 |
import com.yc.api.bean.QrScanType; |
a9a8e7
|
9 |
import com.yc.api.bean.attendance.AppSalesSetting; |
F |
10 |
import com.yc.api.controller.QrCodeController; |
a6a76f
|
11 |
import com.yc.api.service.QrServiceIfc; |
F |
12 |
import com.yc.api.utils.VersionUtils; |
2f46cc
|
13 |
import com.yc.app.v2.entity.SysUserConfigEntity; |
a6a76f
|
14 |
import com.yc.entity.*; |
F |
15 |
import com.yc.entity.attachment.AttachmentEntity; |
a9a8e7
|
16 |
import com.yc.exception.ApplicationException; |
a6a76f
|
17 |
import com.yc.exception.CallBackMessage; |
F |
18 |
import com.yc.factory.FactoryBean; |
|
19 |
import com.yc.factory.InitSystem; |
2e5389
|
20 |
import com.yc.im.util.RedisSocket; |
10a409
|
21 |
import com.yc.jpush.JpushAction; |
a6a76f
|
22 |
import com.yc.listener.SessionListener; |
F |
23 |
import com.yc.multiData.MultiDataSource; |
|
24 |
import com.yc.multiData.SpObserver; |
10a409
|
25 |
import com.yc.open.utils.HttpClientUtil; |
3c1697
|
26 |
import com.yc.sdk.WebSocketMessage.action.WebSocketMessageServer; |
F |
27 |
import com.yc.sdk.WebSocketMessage.entity.MessageInfo; |
|
28 |
import com.yc.sdk.WebSocketMessage.entity.MessageType; |
2e5389
|
29 |
import com.yc.sdk.WebSocketMessage.entity.WsMessageUserEntity; |
ba6749
|
30 |
import com.yc.sdk.gaodemap.action.GdMapServiceInit; |
F |
31 |
import com.yc.sdk.gaodemap.api.GdMapService; |
7433a6
|
32 |
import com.yc.sdk.gaodemap.entity.GdErrorException; |
ba6749
|
33 |
import com.yc.sdk.gaodemap.entity.RegeoCodeEntity; |
a6a76f
|
34 |
import com.yc.sdk.password.action.ChangePassword; |
3c1697
|
35 |
import com.yc.sdk.shopping.action.VerificationCodes; |
a6a76f
|
36 |
import com.yc.sdk.shopping.action.api.InvitationCode; |
3c1697
|
37 |
import com.yc.sdk.shopping.service.sms.SendSMSMessagesIfc; |
c321e2
|
38 |
import com.yc.sdk.shopping.util.SettingKey; |
ba6749
|
39 |
import com.yc.sdk.weixinmp.util.UserAgentUtil; |
a6a76f
|
40 |
import com.yc.sdk.weixinopen.entity.OpenComponentAppSetting; |
a9a8e7
|
41 |
import com.yc.service.BaseService; |
a6a76f
|
42 |
import com.yc.service.demo.DemoIfc; |
F |
43 |
import com.yc.service.role.RoleIfc; |
|
44 |
import com.yc.service.upload.AttachmentIfc; |
29126a
|
45 |
import com.yc.service.user.EquipmentEntry; |
3c1697
|
46 |
import com.yc.service.user.LoginEquipmentIfc; |
a6a76f
|
47 |
import com.yc.service.user.LoginRecordIfc; |
F |
48 |
import com.yc.service.user.UserAccountServiceIfc; |
|
49 |
import com.yc.utils.*; |
ba6749
|
50 |
import eu.bitwalker.useragentutils.UserAgent; |
a6a76f
|
51 |
import me.chanjar.weixin.common.util.http.URIUtil; |
555202
|
52 |
import okio.Source; |
a6a76f
|
53 |
import org.apache.commons.lang.StringUtils; |
10a409
|
54 |
import org.apache.http.client.methods.CloseableHttpResponse; |
F |
55 |
import org.apache.http.client.methods.HttpGet; |
|
56 |
import org.apache.http.client.methods.HttpPost; |
|
57 |
import org.apache.http.util.EntityUtils; |
a6a76f
|
58 |
import org.slf4j.Logger; |
F |
59 |
import org.slf4j.LoggerFactory; |
|
60 |
import org.springframework.beans.factory.annotation.Autowired; |
|
61 |
import org.springframework.dao.DataAccessException; |
|
62 |
import org.springframework.data.redis.core.RedisTemplate; |
a9a8e7
|
63 |
import org.springframework.jdbc.core.BeanPropertyRowMapper; |
ba6749
|
64 |
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
a6a76f
|
65 |
import org.springframework.stereotype.Controller; |
F |
66 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
67 |
|
|
68 |
import javax.servlet.http.HttpServletRequest; |
|
69 |
import javax.servlet.http.HttpServletResponse; |
|
70 |
import javax.servlet.http.HttpSession; |
|
71 |
import java.io.File; |
|
72 |
import java.io.IOException; |
|
73 |
import java.io.PrintWriter; |
|
74 |
import java.text.SimpleDateFormat; |
|
75 |
import java.util.*; |
|
76 |
import java.util.concurrent.TimeUnit; |
10a409
|
77 |
import java.util.stream.Collectors; |
a6a76f
|
78 |
|
F |
79 |
//@Scope("request") |
|
80 |
@Controller |
|
81 |
public class LoginAction extends BaseAction { |
|
82 |
@Autowired |
|
83 |
private UserAccountServiceIfc userAccountService; |
|
84 |
@Autowired |
|
85 |
private LoginRecordIfc record; |
|
86 |
@Autowired |
|
87 |
private RoleIfc rIfc; |
|
88 |
@Autowired |
|
89 |
private DemoIfc demoIfc; |
ba6749
|
90 |
@Autowired |
F |
91 |
ThreadPoolTaskExecutor threadPoolExecutor; |
3c1697
|
92 |
@Autowired |
F |
93 |
LoginEquipmentIfc loginEquipmentIfc; |
|
94 |
@Autowired |
|
95 |
SendSMSMessagesIfc sms ; |
|
96 |
@Autowired |
|
97 |
RedisTemplate redisTemplate; |
a6a76f
|
98 |
final Logger log = LoggerFactory.getLogger(this.getClass()); |
F |
99 |
private static String attachment_server = AttachmentConfig.get("attachment.server"); |
3c1697
|
100 |
|
a6a76f
|
101 |
|
F |
102 |
private int prossSN(String cltsn) { |
|
103 |
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); |
|
104 |
try { |
|
105 |
SpObserver.setDBtoDemo(); |
|
106 |
list = demoIfc.getInfoByCltSn(cltsn); |
|
107 |
} finally { |
|
108 |
SpObserver.setDBtoInstance(); |
|
109 |
} |
|
110 |
int r = 0; |
|
111 |
if (list != null && list.size() > 0) { |
|
112 |
r = 1; |
|
113 |
} |
|
114 |
return r; |
|
115 |
} |
|
116 |
|
ba6749
|
117 |
@RequestMapping("/login.do") |
a6a76f
|
118 |
public String login(HttpServletRequest request, HttpServletResponse response) { |
F |
119 |
String userCode = request.getParameter("account"); |
|
120 |
if (userCode == null || "".equals(userCode)) { |
|
121 |
userCode = (request.getAttribute("account") == null ? "" : (String) request.getAttribute("account")); |
|
122 |
} |
|
123 |
String password = request.getParameter("pwd"); |
|
124 |
if (password == null || "".equals(password)) { |
|
125 |
password = (request.getAttribute("pwd") == null ? "" : (String) request.getAttribute("pwd")); |
|
126 |
} |
|
127 |
if (password != null && !"".equals(password)) { |
|
128 |
password = EncodeUtil.replaceUrlChar(password); |
|
129 |
} |
|
130 |
|
|
131 |
String code = request.getParameter("code"); |
|
132 |
if (code == null || "".equals(code)) { |
|
133 |
code = (request.getAttribute("code") == null ? "" : (String) request.getAttribute("code")); |
|
134 |
} |
|
135 |
boolean ch_userid = (request.getAttribute("isch_userid") == null ? false |
|
136 |
: (Boolean) request.getAttribute("isch_userid")); |
|
137 |
if (ch_userid) |
|
138 |
password = "***";// 避开与密码相关 |
|
139 |
String dbId = ""; |
|
140 |
String dataBaseDis = ""; |
|
141 |
String isone = ""; |
|
142 |
Boolean isApp = false; |
|
143 |
CallBackMessage callBackMessage = new CallBackMessage(); |
|
144 |
if (request.getParameter("isApp") != null || request.getAttribute("isApp") != null) { |
|
145 |
isApp = true;// 手机app传过来 ; |
|
146 |
} |
|
147 |
String redirect = request.getParameter("redirect"); // 登录后重定向页面,Added by Johns Wang, 2016-02-17 |
|
148 |
// 处理通行证的情况 |
|
149 |
StringBuilder sb = new StringBuilder(); |
|
150 |
String cltsn = request.getParameter("cltsn"); |
|
151 |
if (cltsn == null) |
|
152 |
cltsn = (String) request.getAttribute("cltsn"); // Added by Johns Wang, 2015-12-06。。……。。……..…… |
|
153 |
if (cltsn != null && !"".equalsIgnoreCase(cltsn)) { |
|
154 |
int k = this.prossSN(cltsn); |
|
155 |
if (k == 0) { |
|
156 |
callBackMessage.setError("通行证已失效,请联络服务提供商!"); |
|
157 |
this.printJson(response, callBackMessage.toString()); |
|
158 |
return null;// 验证出错返回' |
|
159 |
} |
|
160 |
} else { |
|
161 |
|
|
162 |
dbId = request.getParameter("dataName");// 数据源id |
|
163 |
dataBaseDis = request.getParameter(SessionKey.DATABASE_DIS); |
|
164 |
isone = request.getParameter("isone");// 只有一个数据源的情况 |
|
165 |
if (dbId == null) |
|
166 |
dbId = (String) request.getAttribute("dataName"); // Added by Johns Wang, 2015-12-06 |
|
167 |
if (dataBaseDis == null) |
|
168 |
dataBaseDis = (String) request.getAttribute(SessionKey.DATABASE_DIS); // Added by Johns Wang, 2015-12-06 |
|
169 |
|
|
170 |
// 从数据源取 系统名称 dataBaseDis ,added by Johns Wang, 2017-07-02 |
|
171 |
if (dataBaseDis == null) { |
|
172 |
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(dbId); |
|
173 |
if (dataSourceEntity != null) { |
|
174 |
dataBaseDis = dataSourceEntity.getSystemID(); |
|
175 |
} |
|
176 |
} |
|
177 |
|
|
178 |
if (isone == null) |
|
179 |
isone = (String) request.getAttribute("isone"); // Added by Johns Wang, 2015-12-06 |
|
180 |
} |
|
181 |
if (userCode != null && userCode.length() > 30) {//解密为明文 |
|
182 |
try { |
|
183 |
userCode = ChangePassword.getDecryptPassword(EncodeUtil.replaceUrlChar(userCode)); |
|
184 |
} catch (Exception e) { |
|
185 |
e.printStackTrace(); |
|
186 |
print2(response, this.getErrorMsg(e), redirect, isApp); |
|
187 |
return null;// 验证出错返回' |
|
188 |
|
|
189 |
} |
|
190 |
} |
|
191 |
HttpSession session = request.getSession(); |
|
192 |
String domain = request.getParameter("domain") != null ? request.getParameter("domain") |
|
193 |
: (String) request.getAttribute("domain"); |
|
194 |
UserAccountEntity userAccount = null; |
|
195 |
// -------处理原生APP登录,通过手机号,注册时的密码 by danaus 2018-8-24 |
|
196 |
// 1---有dbid的情况表明是通过选择一个数据源进行登录操作 |
3c1697
|
197 |
if (VersionUtils.getAPPTypeName(request) != null) {// ios,android调用 |
a6a76f
|
198 |
try { |
F |
199 |
InvitationCode invitationCode = (InvitationCode) FactoryBean.getBean("invitationCode"); |
|
200 |
// userCode代表手机号 (在方法 invitationCode.getDbList() 切换数据源 ) |
a53114
|
201 |
|
a6a76f
|
202 |
invitationCode.checkPasswordByTelephone(userCode, password, dbId); |
F |
203 |
// 通过数据源id和手机号取得用户usercode进行登录,这时候不需要密码验证 |
|
204 |
SpObserver.setDBtoInstance("_" + dbId); |
|
205 |
userAccount = userAccountService.getUserInfoByTelephone(userCode);//userCode 手机号 |
|
206 |
if (userAccount != null) { |
fbcd37
|
207 |
if(userAccount.isInActive()){ |
F |
208 |
print2(response, "【" + userCode + "】手机号码已被停用,禁止登录本系统", redirect, isApp); |
|
209 |
return null;// 验证出错返回 |
|
210 |
} |
3c1697
|
211 |
userAccount.setApp_userCode(userCode);//手机号 |
a6a76f
|
212 |
userAccount.setApp_Password(password); |
F |
213 |
userCode = userAccount.getUserCode();//转成ERP的usercode进行登陆 |
|
214 |
password = userAccount.getPassword();//转成ERP的密码进行登陆 |
|
215 |
ch_userid = true; |
10a409
|
216 |
//---处理极光别名绑定过多(>10个)的情况,需要查询绑定数量,超过8个则需要删除最后一个,以保证客户端别名设置没问题 |
fe2b91
|
217 |
this.processJiguangAliases(userCode,dbId); |
a6a76f
|
218 |
} else { |
fbcd37
|
219 |
print2(response, "【" + userCode + "】手机号码未开通ERP系统服务,登录失败", redirect, isApp); |
a6a76f
|
220 |
return null;// 验证出错返回' |
F |
221 |
} |
|
222 |
} catch (DataAccessException e) { |
|
223 |
e.printStackTrace(); |
|
224 |
print2(response, e.getCause() != null ? e.getCause().getMessage() : e.getMessage(), redirect, isApp); |
|
225 |
return null; |
|
226 |
} catch (Exception e) { |
|
227 |
e.printStackTrace(); |
|
228 |
print2(response, e.getCause() != null ? e.getCause().getMessage() : e.getMessage(), redirect, isApp); |
|
229 |
return null; |
|
230 |
} finally { |
|
231 |
SpObserver.setDBtoInstance(); |
|
232 |
} |
|
233 |
} |
|
234 |
//这里是短信登录 xin 2020-8-20 11:25:59 |
3c1697
|
235 |
String phone = request.getParameter("telephone"); |
ba6749
|
236 |
phone = (phone == null ? "" : phone); |
F |
237 |
String phoneCode = request.getParameter("phoneCode"); |
|
238 |
phoneCode = (phoneCode == null ? "" : phoneCode); |
|
239 |
if (StringUtils.isBlank(userCode) && !StringUtils.isBlank(phone) && !StringUtils.isBlank(phoneCode)) { |
|
240 |
try { |
|
241 |
if (!redisTemplate.hasKey("CODE:" + phone + ":" + dbId)) { |
|
242 |
print2(response, "验证码已失效,请重新获取验证码。", redirect, isApp); |
|
243 |
return null; |
|
244 |
} |
|
245 |
if (!phoneCode.equals(redisTemplate.opsForValue().get("CODE:" + phone + ":" + dbId) + "")) { |
|
246 |
print2(response, "验证码错误,请输入正确的验证码", redirect, isApp); |
|
247 |
return null; |
|
248 |
} |
|
249 |
redisTemplate.delete("CODE:" + phone + ":" + dbId);//删除 |
|
250 |
SpObserver.setDBtoInstance("_" + dbId); |
a6a76f
|
251 |
userAccount = userAccountService.getUserInfoByTelephone(phone);//phone 手机号 |
F |
252 |
if (userAccount != null) { |
fbcd37
|
253 |
if(userAccount.isInActive()){ |
F |
254 |
print2(response, "【" + phone + "】手机号码已被停用,禁止登录本系统", redirect, isApp); |
|
255 |
return null;// 验证出错返回' |
|
256 |
} |
a6a76f
|
257 |
userCode = userAccount.getUserCode();//转成ERP的usercode进行登陆 |
F |
258 |
password = userAccount.getPassword();//转成ERP的密码进行登陆 |
ba6749
|
259 |
} else { |
fbcd37
|
260 |
print2(response, "【" + phone + "】手机号码未开通ERP系统服务,登录失败", redirect, isApp); |
ba6749
|
261 |
return null;// 验证出错返回' |
a6a76f
|
262 |
} |
ba6749
|
263 |
} catch (Exception e) { |
fbcd37
|
264 |
print2(response, this.getErrorMsg(e), redirect, isApp); |
ba6749
|
265 |
return null;// 验证出错返回' |
F |
266 |
} finally { |
|
267 |
SpObserver.setDBtoInstance(); |
|
268 |
} |
a6a76f
|
269 |
} |
F |
270 |
//---------------- |
|
271 |
// -------- |
|
272 |
if (StringUtils.isBlank(dbId) && StringUtils.isBlank(isone)) { |
|
273 |
sb.append("请选择一个系统!\\n"); |
|
274 |
} else { |
|
275 |
if (!StringUtils.isBlank(isone)) |
|
276 |
dbId = isone; |
|
277 |
session.setAttribute(SessionKey.DATA_BASE_ID, dbId); |
|
278 |
session.setAttribute(SessionKey.DATABASE_DIS, dataBaseDis); |
c321e2
|
279 |
// 如果domain为空,则取默认的域名 by danaus 2021/4/12 11:18 |
ba6749
|
280 |
if (org.apache.commons.lang3.StringUtils.isBlank(domain)) { |
F |
281 |
domain = SettingKey.getHostUrl(request); |
c321e2
|
282 |
} |
a6a76f
|
283 |
session.setAttribute(SessionKey.DOMAIN, domain); |
F |
284 |
} |
|
285 |
if (StringUtils.isBlank(userCode)) { |
|
286 |
sb.append("账号不能为空\\n"); |
|
287 |
} |
|
288 |
if (StringUtils.isBlank(password)) { |
|
289 |
sb.append("密码不能为空\\n"); |
|
290 |
} |
|
291 |
|
|
292 |
// 判断进行验证码校验********************* |
|
293 |
boolean isValidateLogin = "true".equals(SystemConfig.getInstanse().get("isEnableValidateCode")); |
|
294 |
; |
|
295 |
if (isValidateLogin) {// 是否进行验证码验证 |
|
296 |
if (StringUtils.isBlank(code)) { |
|
297 |
sb.append("验证码不能为空\\n"); |
|
298 |
} else { |
|
299 |
String rand = (String) session.getAttribute("rand");// 对照验证码 |
|
300 |
if (!code.equalsIgnoreCase(rand)) { |
|
301 |
sb.append("验证码不相符\\n"); |
|
302 |
} |
|
303 |
} |
|
304 |
} |
|
305 |
// 判断进行验证码校验********************* |
|
306 |
|
|
307 |
if (sb.length() > 0) { |
|
308 |
print2(response, sb.toString(), redirect, isApp); |
|
309 |
return null;// 验证出错返回' |
|
310 |
} |
|
311 |
try { |
|
312 |
// -------------------- |
|
313 |
|
|
314 |
// 判断是否超出人数限制 |
|
315 |
if (SessionListener.checkUserLimit(request, dbId)) { |
|
316 |
String s = "当前登录人数已超过系统最大登录人数,如有需要增加登录人数,请联系软件公司"; |
|
317 |
print2(response, s, redirect, isApp); |
|
318 |
session.invalidate(); |
|
319 |
return null;// 验证出错返回' |
|
320 |
} |
|
321 |
// *** start ******* 读取加密锁的授权店铺数 |
|
322 |
|
|
323 |
// int scount=0; |
|
324 |
// if(session.getAttribute(SessionKey.HAsP_sHOPCOUNT)!=null) |
|
325 |
// scount=(Integer)session.getAttribute(SessionKey.HAsP_sHOPCOUNT); |
|
326 |
// if(scount>0){ |
|
327 |
// // by danaus 13-5-4 |
|
328 |
// int shop=record.getShopCount(); |
|
329 |
// if(shop>scount){ |
|
330 |
// this.print(response, "<script>alert('检测到系统店铺数量超出所授权的店铺数量!');window.history.back();</script>"); |
|
331 |
// return null;//验证出错返回' |
|
332 |
// } |
|
333 |
// } |
|
334 |
|
|
335 |
// *** end *********** |
|
336 |
int recordeCount = 0; |
|
337 |
try { |
|
338 |
SpObserver.setDBtoInstance("_" + dbId); |
|
339 |
recordeCount = record.getRecordCountIn10min(userCode); // 10分钟内不能登录 |
|
340 |
} finally { |
|
341 |
SpObserver.setDBtoInstance(); |
|
342 |
} |
|
343 |
String ip = IPUtil.getIpAddr(request); |
|
344 |
if (recordeCount >= 5) { |
|
345 |
try { |
|
346 |
SpObserver.setDBtoInstance("_" + dbId); |
|
347 |
record.loginRecord(userCode, password, ip);// 登录次数过多再行登陆作为登录失败处理 |
|
348 |
} finally { |
|
349 |
SpObserver.setDBtoInstance(); |
|
350 |
} |
|
351 |
print2(response, userCode + "在短时间内登录错误次数过多!请耐心的等10分钟后再登录!", redirect, isApp); |
|
352 |
return null;// 验证出错返回 |
|
353 |
} |
|
354 |
// 检查限制用户登录时间和登录IP |
|
355 |
int s = 0; |
|
356 |
try { |
|
357 |
SpObserver.setDBtoInstance("_" + dbId); |
|
358 |
s = userAccountService.checkUserLoginTimeAndIp(userCode, ip); |
|
359 |
} finally { |
|
360 |
SpObserver.setDBtoInstance(); |
|
361 |
} |
|
362 |
if (s == 0) { |
|
363 |
print2(response, "该用户只能在工作时间或固定场所使用本系统[" + ip + "]", redirect, isApp); |
|
364 |
return null; |
|
365 |
} |
|
366 |
// |
|
367 |
// 设置session |
|
368 |
try { |
|
369 |
if (userAccount == null) { |
|
370 |
SpObserver.setDBtoInstance("_" + dbId); |
|
371 |
userAccount = userAccountService.getUserInfoByUserCode(userCode); |
|
372 |
|
|
373 |
if (userAccount == null) { |
|
374 |
userAccount = userAccountService.getUserInfoByTelephone(userCode); //允许电话登录 |
|
375 |
} |
|
376 |
|
|
377 |
if (userAccount == null) { |
|
378 |
userAccount = userAccountService.getUserInfoByEmail(userCode); //允许邮箱号登录 |
|
379 |
} |
|
380 |
} |
a53114
|
381 |
}catch (Exception e){ |
F |
382 |
this.print2(response, this.getErrorMsg(e), request.getParameter("redirect"), isApp); |
|
383 |
return null; |
|
384 |
}finally { |
a6a76f
|
385 |
SpObserver.setDBtoInstance(); |
F |
386 |
} |
|
387 |
if (userAccount == null) { |
|
388 |
try { |
|
389 |
SpObserver.setDBtoInstance("_" + dbId); |
|
390 |
record.loginRecord(userCode, password, IPUtil.getIpAddr(request));// 记录登录登录失败的信息 |
a53114
|
391 |
}catch (Exception e){ |
F |
392 |
this.print2(response, this.getErrorMsg(e), request.getParameter("redirect"), isApp); |
|
393 |
return null; |
a6a76f
|
394 |
} finally { |
F |
395 |
SpObserver.setDBtoInstance(); |
|
396 |
} |
|
397 |
if (ch_userid) { |
fbcd37
|
398 |
return "{\"ch_error\":\"ch_user_error\",\"info\":\"未开通ERP系统服务,登录失败!\"}"; |
a6a76f
|
399 |
} else { |
fbcd37
|
400 |
this.print2(response, "未开通ERP系统服务,登录失败!", request.getParameter("redirect"), isApp); |
a6a76f
|
401 |
return null; |
F |
402 |
} |
|
403 |
} |
|
404 |
try { |
|
405 |
if (!ch_userid && !userAccount.checkPassword(password)) { |
|
406 |
try { |
|
407 |
SpObserver.setDBtoInstance("_" + dbId); |
|
408 |
record.loginRecord(userCode, password, IPUtil.getIpAddr(request));// 记录登录登录失败的信息 |
a53114
|
409 |
}catch (Exception e){ |
F |
410 |
this.print2(response, this.getErrorMsg(e), request.getParameter("redirect"), isApp); |
|
411 |
return null; |
a6a76f
|
412 |
} finally { |
F |
413 |
SpObserver.setDBtoInstance(); |
|
414 |
} |
|
415 |
this.print2(response, "用户密码不正确!", request.getParameter("redirect"), isApp); |
|
416 |
return null; |
|
417 |
} |
|
418 |
} catch (Exception ex) { |
|
419 |
this.print2(response, ex.getMessage(), request.getParameter("redirect"), isApp); |
|
420 |
return null; |
|
421 |
} |
0a03f9
|
422 |
// 判断用户登录时是否禁用 |
F |
423 |
if (userAccount.isInActive()) { |
|
424 |
this.print2(response, "用户账号已禁止登录!如有问题,请联系管理员", request.getParameter("redirect"), isApp); |
a6a76f
|
425 |
return null; |
F |
426 |
} |
ba6749
|
427 |
if (isApp) { |
F |
428 |
session.setAttribute(SessionKey.USER_LOGIN_TYPE, SessionKey.USER_LOGIN_TYPE_APP);//app 类型 |
3c1697
|
429 |
//判断当前登录设备是否与最新一次登录设备是一样,不一样需要返回给前端,输出短信进行验证登录 |
F |
430 |
|
ba6749
|
431 |
} else if (redirect != null && !"".equals(redirect)) { // 增加登录后重定向页面功能,added by Johns Wang, 2016-02-17 |
F |
432 |
session.setAttribute(SessionKey.USER_LOGIN_TYPE, SessionKey.USER_LOGIN_TYPE_MINIAPP);//miniapp 类型 |
|
433 |
} else { |
|
434 |
session.setAttribute(SessionKey.USER_LOGIN_TYPE, SessionKey.USER_LOGIN_TYPE_WEB);//web 类型 |
|
435 |
} |
3c1697
|
436 |
final DataSourceEntity dataSourceMap = MultiDataSource.getDataSourceMap(dbId); |
F |
437 |
//--------------------------------- |
|
438 |
|
|
439 |
if(dataSourceMap.isLoginOnceForOneUserCode()) { |
|
440 |
//开启了账号只能在相同类型设备上登录一个,禁止多方登录 |
|
441 |
if (isApp) { |
|
442 |
//---验证当前设备是否为上一次登录设备 |
cdc83b
|
443 |
//---1,检查是否有发送SMS验证的标记,有则不需要查,表明之前已查过,跳过下面checkSameEquipmentByLastLogin方法 |
F |
444 |
final Object object = request.getAttribute("loginByCode"); |
3c1697
|
445 |
if(object==null){ |
29126a
|
446 |
EquipmentEntry equipmentEntry=null; |
3c1697
|
447 |
try { |
F |
448 |
SpObserver.setDBtoDemo(); |
29126a
|
449 |
equipmentEntry = loginEquipmentIfc.checkSameEquipmentByLastLogin(userAccount.getApp_userCode(), request.getHeader("x-app-uniqueIdentifier")); |
F |
450 |
}catch (Exception e){ |
cdc83b
|
451 |
printJson(response, callBackMessage.sendErrorMessage(this.getErrorMsg(e))); |
F |
452 |
return null; |
29126a
|
453 |
}finally { |
3c1697
|
454 |
SpObserver.setDBtoInstance(); |
F |
455 |
} |
29126a
|
456 |
if(equipmentEntry!=null&& org.apache.commons.lang3.StringUtils.isNotBlank(equipmentEntry.getEquipmentName())) { |
cdc83b
|
457 |
//log.info(JSON.toJSONString("equipmentEntry:"+equipmentEntry)); |
F |
458 |
//2----不相同,则需要SMS进行验证登录 |
3c1697
|
459 |
session.invalidate();//删除当前会话 |
29126a
|
460 |
String error=String.format("已在另一台设备%s登录,登录时间%s,如果需要在本机登录,则需要验证您的身份。",equipmentEntry.getEquipmentName(),equipmentEntry.getLastLogonDate()); |
F |
461 |
printJson(response, callBackMessage.sendErrorMessage(error,-1005)); |
3c1697
|
462 |
return null; |
F |
463 |
} |
555202
|
464 |
}else{ |
F |
465 |
this.singleAccount(isApp ? "2" : "1", dbId, userAccount, request); |
3c1697
|
466 |
} |
555202
|
467 |
}else { |
F |
468 |
//限制多设备登录 |
3c1697
|
469 |
this.singleAccount(isApp ? "2" : "1", dbId, userAccount, request); |
555202
|
470 |
} |
3c1697
|
471 |
} |
ba6749
|
472 |
processLoginUserToSessionV2(ip, dbId, request, userAccount); |
3c1697
|
473 |
//------------------------------- |
2f46cc
|
474 |
//--APP用户配置组装成对象输出 |
F |
475 |
SysUserConfigEntity sysUserConfigEntity=new SysUserConfigEntity(); |
|
476 |
sysUserConfigEntity.setSwitchToPageWhenLogonApp(session.getAttribute(SessionKey.SWITCHTOPAGEWHENLOGONAPP)+""); |
|
477 |
sysUserConfigEntity.setSelectNextDocumentWhenApproved(session.getAttribute(SessionKey.SELECTNEXTDOCUMENTWHENAPPROVED)==null?0:Integer.parseInt(session.getAttribute(SessionKey.SELECTNEXTDOCUMENTWHENAPPROVED)+"")); |
|
478 |
sysUserConfigEntity.setIsStartupPopupMessages(session.getAttribute(SessionKey.ISSTARTUPPOPUPMESSAGES)==null?0:Integer.parseInt(session.getAttribute(SessionKey.ISSTARTUPPOPUPMESSAGES)+"")); |
|
479 |
session.setAttribute("userConfig",sysUserConfigEntity); |
a6a76f
|
480 |
if (isApp) { |
ba6749
|
481 |
QrServiceIfc qrServiceIfc = (QrServiceIfc) FactoryBean.getBean("qrService"); |
87daf8
|
482 |
try { |
F |
483 |
SpObserver.setDBtoInstance("_" + dbId); |
ba6749
|
484 |
AppSalesSetting appSalesSetting = qrServiceIfc.getAppSalesOrderStyle(); |
87daf8
|
485 |
//加到会话 |
ba6749
|
486 |
session.setAttribute(SessionKey.APP_SALESORDER_MATCODE_LIST, appSalesSetting.getAppSalesOrderMatCodeList()); |
F |
487 |
session.setAttribute(SessionKey.APP_SALESORDER_STYLE, appSalesSetting.getAppSalesOrderStyle()); |
|
488 |
} catch (Exception e) { |
87daf8
|
489 |
e.printStackTrace(); |
F |
490 |
throw new ApplicationException(e.getMessage()); |
ba6749
|
491 |
} finally { |
87daf8
|
492 |
SpObserver.setDBtoInstance(); |
F |
493 |
} |
a6a76f
|
494 |
Map<String, Object> map = new HashMap<String, Object>(); |
F |
495 |
map.put("success", "ok"); |
|
496 |
map.put("sessionid", session.getId()); |
|
497 |
map.put("userName", userAccount.getUserName()); |
|
498 |
String avatarUnid = ""; |
|
499 |
if (userAccount.getAvatarUnid() != null && !"".equals(userAccount.getAvatarUnid())) { |
|
500 |
try { |
|
501 |
SpObserver.setDBtoInstance("_" + dbId); |
|
502 |
AttachmentIfc attachmentIfc = (AttachmentIfc) FactoryBean.getBean("AttachmentImpl"); |
|
503 |
String[] unids = userAccount.getAvatarUnid().split(";"); |
|
504 |
final AttachmentEntity attachmentEntity = attachmentIfc.getAttachmentEntity(unids[0], unids[1]); |
|
505 |
avatarUnid = userAccount.getAvatarUnid() + ";" + attachmentEntity.getFileType(); |
|
506 |
} catch (Exception ex) { |
|
507 |
callBackMessage.sendErrorMessage(ex.getMessage()); |
|
508 |
this.printJson(response, callBackMessage.toString()); |
|
509 |
return null; |
|
510 |
} finally { |
|
511 |
SpObserver.setDBtoInstance(); |
|
512 |
} |
|
513 |
} |
|
514 |
map.put("avatarUnid", avatarUnid); |
|
515 |
map.put("attachment_server", attachment_server); |
|
516 |
map.put("url", domain == null ? "" : domain); |
|
517 |
if (request.getAttribute("postTokenV2") == null) { |
|
518 |
map.put("token", genToken(userAccount.getApp_Password(), userAccount.getApp_userCode(), Integer.parseInt(dbId))); |
|
519 |
} |
|
520 |
|
|
521 |
//---增加扫码显示方式 |
a9a8e7
|
522 |
|
ba6749
|
523 |
QrScanType qrScanType = null; |
a9a8e7
|
524 |
//显示下单图标 |
ba6749
|
525 |
int appSalesMenuIcon = 0; |
a6a76f
|
526 |
try { |
F |
527 |
SpObserver.setDBtoInstance("_" + dbId); |
ba6749
|
528 |
qrScanType = qrServiceIfc.getQrScanType(userAccount.getUserCode(), userAccount.getUserName()); |
a9a8e7
|
529 |
|
ba6749
|
530 |
} catch (Exception e) { |
a6a76f
|
531 |
e.printStackTrace(); |
a9a8e7
|
532 |
throw new ApplicationException(e.getMessage()); |
ba6749
|
533 |
} finally { |
a6a76f
|
534 |
SpObserver.setDBtoInstance(); |
F |
535 |
} |
37ae33
|
536 |
//---增加是否可以显示下单图标 |
ba6749
|
537 |
try { |
37ae33
|
538 |
SpObserver.setDBtoInstance("_" + dbId); |
ba6749
|
539 |
BaseService baseService = (BaseService) FactoryBean.getBean("BaseService"); |
F |
540 |
List<Gfrom> list = baseService.getJdbcTemplate().query("select a.formid,a.formname from gform a where exists(select 1 from gfield b where a.formid = b.formid and b.fieldid in ( 'matcode','barcode','qrcode') and b.ScanCodeField = 1 )", new BeanPropertyRowMapper<>(Gfrom.class)); |
a9a8e7
|
541 |
|
ba6749
|
542 |
if (list != null && list.size() > 0) { |
F |
543 |
QrCodeController qrCodeController = (QrCodeController) FactoryBean.getBean("qrCodeController"); |
|
544 |
List tempList = qrCodeController.procFormLimit(request, list); |
|
545 |
if (tempList != null && tempList.size() > 0) { |
|
546 |
appSalesMenuIcon = 1; |
37ae33
|
547 |
} |
F |
548 |
} |
ba6749
|
549 |
} catch (Exception e) { |
37ae33
|
550 |
e.printStackTrace(); |
F |
551 |
throw new ApplicationException(e.getMessage()); |
ba6749
|
552 |
} finally { |
37ae33
|
553 |
SpObserver.setDBtoInstance(); |
F |
554 |
} |
a6a76f
|
555 |
map.put("sessionInfo", getSessionInfo(session)); |
6fe1e6
|
556 |
map.put("userType", session.getAttribute(SessionKey.USERTYPE)); |
F |
557 |
map.put("isStopSystem", session.getAttribute(SessionKey.isStopSystem)); |
ba6749
|
558 |
map.put("isAdmin", ("SuperUser".equalsIgnoreCase(session.getAttribute(SessionKey.USERTYPE) + "") || "DeveloperUser".equalsIgnoreCase(session.getAttribute(SessionKey.USERTYPE) + "")) ? 1 : 0);//非普通用户都有所有权限 |
F |
559 |
map.put("isShowAttendance", dataSourceMap.isShowAttendanceButton() ? 1 : 0);//打卡 |
a6a76f
|
560 |
map.put("qrDisplayType", qrScanType.getScanMeterialAction());//扫码显示方式 |
a9a8e7
|
561 |
map.put("appSalesMenuIcon", appSalesMenuIcon);//是否显示下单图标,0不显示,1显示 |
a6a76f
|
562 |
map.put("isRelatingMaterialWhenNewCustomer", qrScanType.getIsRelatingMaterialWhenNewCustomer());//是否关联客户 |
ba6749
|
563 |
OpenComponentAppSetting openComponentAppSetting = OpenComponentAppSetting.defaultSettings(); |
F |
564 |
map.put("mobileAppId", openComponentAppSetting == null ? null : openComponentAppSetting.getMobileAppId());//小程序id |
|
565 |
map.put("mobileAppSecret", openComponentAppSetting == null ? null : openComponentAppSetting.getMobileAppSecret());//小程序MobileAppSecret |
a6a76f
|
566 |
map.put("miniAppOrgId", dataSourceMap.getMiniAppOrgId());//小程序miniAppOrgId |
F |
567 |
map.put("isModifyPriceWhenScanQrCode", session.getAttribute(SessionKey.ISMODIFYPRICEWHENSCANQRCODE)); |
625716
|
568 |
map.put("isModifyPriceWhenSalesOrder", session.getAttribute(SessionKey.ISMODIFYPRICEWHENSALESORDER)); |
F |
569 |
map.put("isModifyPriceWhenPurchaseOrder", session.getAttribute(SessionKey.ISMODIFYPRICEWHENPURCHASEORDER)); |
21e5fd
|
570 |
map.put("switchToPageWhenLogonApp", session.getAttribute(SessionKey.SWITCHTOPAGEWHENLOGONAPP)); |
fe0a59
|
571 |
map.put("selectNextDocumentWhenApproved", session.getAttribute(SessionKey.SELECTNEXTDOCUMENTWHENAPPROVED)); |
2f46cc
|
572 |
map.put("userConfig", sysUserConfigEntity); |
a6a76f
|
573 |
map.put("perssion", session.getAttribute(SessionKey.PERSSION)); |
F |
574 |
this.printJson(response, GridUtils.toJson(map)); |
|
575 |
return null; |
|
576 |
} else if (redirect != null && !"".equals(redirect)) { // 增加登录后重定向页面功能,added by Johns Wang, 2016-02-17 |
|
577 |
//return "redirect:" + redirect; |
|
578 |
callBackMessage.sendSuccessMessage("登录成功"); |
|
579 |
callBackMessage.setData("{\"redirect\":\"" + redirect + "\"}"); |
|
580 |
this.printJson(response, callBackMessage.toString()); |
|
581 |
return null; |
|
582 |
} else { |
|
583 |
if (ch_userid) |
|
584 |
return "{\"ok\":\"ch_user_ok\",\"info\":\"" + userCode + "\"}"; |
|
585 |
else { |
|
586 |
callBackMessage.sendSuccessMessage("登录成功"); |
|
587 |
this.printJson(response, callBackMessage.toString()); |
|
588 |
return null; |
|
589 |
} |
|
590 |
} |
7433a6
|
591 |
}catch (IllegalStateException e) { |
a6a76f
|
592 |
e.printStackTrace(); |
a53114
|
593 |
if (e.getMessage()!=null&&e.getMessage().contains("Session already invalidated")) { |
a6a76f
|
594 |
sb.append("会话已过期,请关闭浏览器再重新登录系统\\n"); |
F |
595 |
print2(response, sb.toString(), redirect, isApp); |
|
596 |
System.out.println(this.getClass() + " sessionid:" + session.getId()); |
|
597 |
return null;// 会话已过期返回 |
|
598 |
} else { |
|
599 |
e.printStackTrace(); |
|
600 |
print2(response, this.getErrorMsg(e), redirect, isApp); |
|
601 |
return null; |
|
602 |
} |
|
603 |
} catch (DataAccessException e) { |
|
604 |
e.printStackTrace(); |
|
605 |
//SQLException sql = (SQLException) e.getCause(); |
|
606 |
//return "/403.jsp?info=" + sql.getMessage(); |
|
607 |
this.print2(response, e.getCause() != null ? e.getCause().getMessage() : e.getMessage(), request.getParameter("redirect"), isApp); |
|
608 |
return null; |
|
609 |
} catch (NullPointerException e) {// 不存在此账号 |
|
610 |
e.printStackTrace(); |
|
611 |
proccError(userCode, password, request, response); |
|
612 |
return null; |
|
613 |
} catch (RuntimeException e) { |
|
614 |
e.printStackTrace(); |
a53114
|
615 |
if (e.getLocalizedMessage()!=null&&e.getMessage().equals(SessionKey.DEMO_REF)) { |
a6a76f
|
616 |
session.setAttribute(SessionKey.DEMO_REF, SessionKey.DEMO_REF); |
F |
617 |
this.print(response, "<script>alert('请生成正确的配置信息');window.location.href='/demo/demoList.jsp';</script>"); |
d75ad0
|
618 |
}else{ |
F |
619 |
this.print2(response, this.getErrorMsg(e), request.getParameter("redirect"), isApp); |
a6a76f
|
620 |
} |
F |
621 |
return null; |
7433a6
|
622 |
}catch (GdErrorException e) {// 不存在高德地图apiKey |
F |
623 |
e.printStackTrace(); |
|
624 |
this.print2(response, "高德地图KEY不存在,请在数据源里维护好", request.getParameter("redirect"), isApp); |
|
625 |
return null; |
|
626 |
} |
|
627 |
catch (Exception e) {// 不存在此账号 |
a6a76f
|
628 |
e.printStackTrace(); |
F |
629 |
proccError(userCode, password, request, response); |
|
630 |
return null; |
|
631 |
} |
|
632 |
} |
3c1697
|
633 |
private void singleAccount(String userFromType,String dbId, UserAccountEntity userAccount, HttpServletRequest request){ |
F |
634 |
HttpSession session = request.getSession(); |
|
635 |
List<OnlineUserEntity> onLineUser = SessionListener.getOnLineUser(request, dbId);//tomcat集群是采用会话复制,所以每个tomcat里的会话信息是一样,取到同一数据源所有会话,从中取到当前用户的会话 |
|
636 |
if(onLineUser!=null&&onLineUser.size()>0) { |
|
637 |
for(OnlineUserEntity entity:onLineUser){ |
|
638 |
if(entity.getUserCode().equalsIgnoreCase(userAccount.getUserCode()) |
|
639 |
&&userFromType.equalsIgnoreCase(entity.getLoginType()+"")//指明是PC,还是APP端 |
|
640 |
&&!session.getId().equalsIgnoreCase(entity.getSessionId())//排除当前的会话,取同账号的之前会话 |
|
641 |
){ |
555202
|
642 |
//只要会话存在,发webSocket回到登录界面 |
F |
643 |
//---通知webscoket |
|
644 |
MessageInfo messageInfo = new MessageInfo(); |
|
645 |
messageInfo.setDbId(Integer.parseInt(dbId)); |
|
646 |
messageInfo.setMsgType(MessageType.RETURN_LOGIN_PAGE); |
|
647 |
messageInfo.setUserFromType(userFromType); |
|
648 |
messageInfo.setUserCode(entity.getUserCode()); |
|
649 |
messageInfo.setSessionId(entity.getSessionId()); |
|
650 |
if(userFromType.equalsIgnoreCase("1")) {//PC端 |
|
651 |
messageInfo.setMsg("您的账号已在其他地方登录"); |
|
652 |
}else{ |
|
653 |
messageInfo.setMsg("您的账号已在其他设备登录"); |
3c1697
|
654 |
} |
555202
|
655 |
WebSocketMessageServer.publishMessageToRedis(messageInfo); |
F |
656 |
} |
3c1697
|
657 |
} |
F |
658 |
} |
555202
|
659 |
|
3c1697
|
660 |
} |
a6a76f
|
661 |
|
F |
662 |
private String genToken(String pwd, String usercode, int dbid) { |
|
663 |
TokenInfo tokenInfo = new TokenInfo(); |
|
664 |
tokenInfo.setUsercode(usercode); |
|
665 |
tokenInfo.setDbid(dbid); |
|
666 |
try { |
|
667 |
String key = "Lg_Token:" + tokenInfo.getDbid() + ":" + tokenInfo.getUsercode(); |
|
668 |
|
3c1697
|
669 |
|
a6a76f
|
670 |
Object object = redisTemplate.opsForValue().get(key); |
F |
671 |
//if (object == null) { |
|
672 |
//不存在则加到redis里,过期时间设置为12小时 |
|
673 |
final int OVERTIME = 12; |
|
674 |
redisTemplate.opsForValue().set(key, pwd, OVERTIME, TimeUnit.HOURS); |
|
675 |
//} |
|
676 |
|
|
677 |
String token = AESUtils.encrypt(GridUtils.toJson(tokenInfo));//dbid+usercode加密返回给APP客户端保存 |
|
678 |
return token; |
|
679 |
} catch (Exception ex) { |
|
680 |
ex.printStackTrace(); |
|
681 |
return ""; |
|
682 |
} |
|
683 |
} |
|
684 |
|
|
685 |
public boolean processLoginUserToSession(String ip, String dbId, HttpSession session, UserAccountEntity userAccount) throws Exception { |
|
686 |
// 设置权限 |
|
687 |
PerssionEntity perssionEntity = new PerssionEntity(); |
|
688 |
try { |
|
689 |
SpObserver.setDBtoInstance("_" + dbId); |
|
690 |
perssionEntity.setRole(rIfc.getRole(userAccount.getUserCode())); |
|
691 |
} finally { |
|
692 |
SpObserver.setDBtoInstance(); |
|
693 |
} |
|
694 |
try { |
|
695 |
SpObserver.setDBtoInstance("_" + dbId); |
|
696 |
perssionEntity.setPerssion(userAccountService.getUserProfiles(userAccount.getUserCode())); |
|
697 |
// 保存会话 session信息 |
|
698 |
setSessionValues(dbId, userAccount, session, perssionEntity); |
|
699 |
// 登录成功清除登录错误信息 |
|
700 |
record.clearLoginRecord(userAccount.getUserCode()); |
|
701 |
|
|
702 |
// 记录登录信息 |
|
703 |
userAccountService.loginLog(userAccount.getUserCode(), userAccount.getUserName(), ip, session.getId()); |
|
704 |
} finally { |
|
705 |
SpObserver.setDBtoInstance(); |
|
706 |
} |
|
707 |
if (userAccount.getDefaultSet() != null && !"".equals(userAccount.getDefaultSet())) { |
|
708 |
try { |
|
709 |
SpObserver.setDBtoInstance("_" + dbId); |
|
710 |
perssionEntity.setDefaultSet(userAccountService.getDefaultSet(userAccount.getDefaultSet())); |
|
711 |
} finally { |
|
712 |
SpObserver.setDBtoInstance(); |
|
713 |
} |
|
714 |
} |
|
715 |
return true; |
|
716 |
|
|
717 |
} |
|
718 |
|
ba6749
|
719 |
public boolean processLoginUserToSessionV2( String ip, String dbId, HttpServletRequest request, UserAccountEntity userAccount) throws Exception { |
F |
720 |
HttpSession session = request.getSession(); |
|
721 |
// 设置权限 |
3c1697
|
722 |
LoginUserEntity userEntity = new LoginUserEntity(); |
29126a
|
723 |
final DataSourceEntity dataSourceMap = MultiDataSource.getDataSourceMap(dbId); |
3c1697
|
724 |
try { |
29126a
|
725 |
userEntity.setDbid(dbId); |
F |
726 |
userEntity.setSystemDescribe(dataSourceMap.getSystemDescribe()); |
|
727 |
userEntity.setLogonDomain(request.getHeader("host")); |
ba6749
|
728 |
if (request.getParameter("isApp") != null || request.getAttribute("isApp") != null) { |
F |
729 |
// 手机app传过来 |
|
730 |
userEntity.setOSType(request.getHeader("x-app-type"));//ios,android |
|
731 |
String equipmentCode = request.getHeader("x-app-equipmentCode"); |
d9236e
|
732 |
String appVersion = request.getHeader("x-app-version");//app版本号 |
29126a
|
733 |
String uniqueIdentifier = request.getHeader("x-app-uniqueIdentifier");//设备唯一码 |
3c1697
|
734 |
userEntity.setUniqueIdentifier(uniqueIdentifier); |
d9236e
|
735 |
userEntity.setAppVersion(appVersion); |
ba6749
|
736 |
userEntity.setEquipmentModel(equipmentCode);//设备型号 |
F |
737 |
userEntity.setUserLoginType("app"); |
|
738 |
//--从设备型号提取生产商名称, |
|
739 |
if (org.apache.commons.lang3.StringUtils.isNotBlank(equipmentCode)) { |
|
740 |
String[] equipment = equipmentCode.split("\\s+?");//空格分隔,取第一个作为生产商 |
|
741 |
userEntity.setManufacturer(equipment[0]); |
|
742 |
} |
|
743 |
|
|
744 |
} else { |
|
745 |
//pc ,小程序 |
b0744c
|
746 |
int userLoginType = session.getAttribute(SessionKey.USER_LOGIN_TYPE)==null?1:Integer.parseInt(session.getAttribute(SessionKey.USER_LOGIN_TYPE)+""); |
F |
747 |
if (userLoginType==3) { |
ba6749
|
748 |
userEntity.setUserLoginType("minapp"); |
F |
749 |
} else { |
|
750 |
userEntity.setUserLoginType("web"); |
|
751 |
} |
|
752 |
String userAgentString = UserAgentUtil.getUaInfo(request); // request.getHeader("User-Agent"); |
|
753 |
UserAgent userAgent = UserAgent.parseUserAgentString(userAgentString); |
|
754 |
String os = userAgent.getOperatingSystem().getGroup().getName(); |
|
755 |
//String osName = userAgent.getOperatingSystem().getName() ; |
|
756 |
String manufacturer = userAgent.getOperatingSystem().getManufacturer().getName(); |
|
757 |
String model = UserAgentUtil.getPhoneModel(userAgentString); |
|
758 |
//String mobileOS = UserAgentUtil.getMobileOS(userAgentString); |
|
759 |
userEntity.setOSType(os); |
|
760 |
userEntity.setManufacturer(manufacturer); |
|
761 |
userEntity.setEquipmentModel(model); |
|
762 |
userEntity.setUserAgent(userAgentString); |
|
763 |
} |
|
764 |
String longitude = request.getHeader("x-app-longitude"); |
|
765 |
String latitude = request.getHeader("x-app-latitude"); |
a53114
|
766 |
|
ba6749
|
767 |
//---通过经纬度,IP 获取地理信息(国,省,市,区) |
e3dd14
|
768 |
if(org.apache.commons.lang3.StringUtils.isNotBlank(dataSourceMap.getGeoWebApiKey())) { |
J |
769 |
GdMapService gdMapService = GdMapServiceInit.getGdMapService(dataSourceMap.getGeoWebApiKey()); |
|
770 |
final RegeoCodeEntity regeo = gdMapService.getRegeoV2(longitude, latitude, ip); |
|
771 |
if (regeo != null) { |
|
772 |
userEntity.setCountryName(regeo.getCountry()); |
|
773 |
userEntity.setProvinceName(regeo.getProvince()); |
|
774 |
userEntity.setCityName(regeo.getCity()); |
|
775 |
userEntity.setCountyName(regeo.getDistrict()); |
|
776 |
} |
ba6749
|
777 |
} |
F |
778 |
userEntity.setLongitude(longitude); |
|
779 |
userEntity.setLatitude(latitude); |
|
780 |
userEntity.setIp(ip); |
|
781 |
|
|
782 |
PerssionEntity perssionEntity = new PerssionEntity(); |
|
783 |
SpObserver.setDBtoInstance("_" + dbId); |
|
784 |
perssionEntity.setRole(rIfc.getRole(userAccount.getUserCode())); |
|
785 |
perssionEntity.setPerssion(userAccountService.getUserProfiles(userAccount.getUserCode())); |
|
786 |
if (userAccount.getDefaultSet() != null && !"".equals(userAccount.getDefaultSet())) { |
|
787 |
perssionEntity.setDefaultSet(userAccountService.getDefaultSet(userAccount.getDefaultSet())); |
|
788 |
} |
a53114
|
789 |
|
ba6749
|
790 |
// 保存会话 session信息 |
F |
791 |
setSessionValues(dbId, userAccount, session, perssionEntity); |
|
792 |
// 登录成功清除登录错误信息 |
|
793 |
record.clearLoginRecord(userAccount.getUserCode()); |
|
794 |
// 记录登录信息 |
|
795 |
userAccountService.loginLogV2(userAccount, userEntity, session.getId()); |
a53114
|
796 |
|
ba6749
|
797 |
} finally{ |
F |
798 |
SpObserver.setDBtoInstance(); |
|
799 |
} |
185287
|
800 |
// if (dataSourceMap.isLoginOnceForOneUserCode() &&request.getAttribute("loginByCode") != null) { |
555202
|
801 |
//启用限制多设备登录,且通过短信二次验证登录 |
3c1697
|
802 |
try { |
F |
803 |
SpObserver.setDBtoDemo(); |
|
804 |
userEntity.setTelePhone(userAccount.getApp_userCode());//手机号 |
|
805 |
loginEquipmentIfc.updateUserLoginEquipmentInfo(userEntity); |
|
806 |
} finally { |
|
807 |
SpObserver.setDBtoInstance(); |
|
808 |
} |
185287
|
809 |
// } |
3c1697
|
810 |
return true; |
ba6749
|
811 |
} |
3c1697
|
812 |
|
ba6749
|
813 |
|
a6a76f
|
814 |
/** |
F |
815 |
* APP 自动登录接口 |
|
816 |
* |
|
817 |
* @param request |
|
818 |
* @param response |
|
819 |
*/ |
|
820 |
@RequestMapping("/autoLogin.do") |
|
821 |
public String autoLogin(String token, HttpServletRequest request, HttpServletResponse response) { |
|
822 |
if (token == null || "".equalsIgnoreCase(token)) { |
|
823 |
this.printJson(response, "{\"error\":\"token不能为空\"}"); |
|
824 |
return ""; |
|
825 |
} |
|
826 |
try { |
|
827 |
String value = AESUtils.decrypt(EncodeUtil.replaceUrlChar(token));//解密 |
|
828 |
Gson gson = new Gson(); |
|
829 |
TokenInfo tokenInfo = gson.fromJson(value, new com.google.gson.reflect.TypeToken<TokenInfo>() { |
|
830 |
}.getType()); |
|
831 |
|
3c1697
|
832 |
|
a6a76f
|
833 |
Object object = redisTemplate.opsForValue().get("Lg_Token:" + tokenInfo.getDbid() + ":" + tokenInfo.getUsercode()); |
F |
834 |
if (object == null) { |
|
835 |
this.printJson(response, "{\"error\":\"token已失效,请重新登录\"}"); |
|
836 |
return ""; |
|
837 |
} |
|
838 |
|
|
839 |
String[] tokenStr = ((String) object).split("#");//0是密码,1是随机数 |
|
840 |
//进行登录操作 |
|
841 |
tokenInfo.setPwd(tokenStr[0]); |
|
842 |
request.setAttribute("account", tokenInfo.getUsercode()); |
|
843 |
request.setAttribute("pwd", tokenInfo.getPwd()); |
|
844 |
request.setAttribute("isApp", "1"); |
|
845 |
request.setAttribute("dataName", tokenInfo.getDbid() + ""); |
|
846 |
request.setAttribute("isone", tokenInfo.getDbid() + ""); |
|
847 |
} catch (Exception ex) { |
|
848 |
this.printJson(response, "{\"error\":\"" + this.getErrorMsg(ex) + "\"}"); |
|
849 |
return ""; |
|
850 |
} |
|
851 |
return login(request, response); |
|
852 |
} |
|
853 |
|
|
854 |
@RequestMapping("/autoLoginV2.do") |
|
855 |
/** |
|
856 |
* by danaus 2020/1/13 9:59 |
|
857 |
*/ |
|
858 |
public String autoLoginV2(String token, HttpServletRequest request, HttpServletResponse response) { |
|
859 |
CallBackMessage callBackMessage = new CallBackMessage(); |
|
860 |
if (token == null || "".equalsIgnoreCase(token)) { |
|
861 |
this.printJson(response, callBackMessage.sendErrorMessage("token不能为空", -1)); |
|
862 |
return ""; |
|
863 |
} |
|
864 |
try { |
|
865 |
String value = AESUtils.decrypt(EncodeUtil.replaceUrlChar(token));//解密 |
|
866 |
Gson gson = new Gson(); |
|
867 |
TokenInfo tokenInfo = gson.fromJson(value, new com.google.gson.reflect.TypeToken<TokenInfo>() { |
|
868 |
}.getType()); |
3c1697
|
869 |
|
a6a76f
|
870 |
//System.out.println("aaaaaa>>>>"+value); |
F |
871 |
//System.out.println("bbbbb>>>>"+InvitationCode.TOKEN_STR + tokenInfo.getDbid() + ":" + tokenInfo.getUsercode()); |
|
872 |
Object object = redisTemplate.opsForValue().get(InvitationCode.TOKEN_STR + tokenInfo.getDbid() + ":" + tokenInfo.getUsercode()); |
|
873 |
//System.out.println("cccc>>>>"+object); |
|
874 |
if (object == null) { |
|
875 |
//设置会话失效 |
|
876 |
request.getSession().invalidate(); |
|
877 |
this.printJson(response, callBackMessage.sendErrorMessage("token已失效,请重新登录", -1002)); |
|
878 |
return ""; |
|
879 |
} |
|
880 |
//405调用需要刷新过期时间 |
ba6749
|
881 |
if (request.getParameter("refresh") != null && "1".equalsIgnoreCase(request.getParameter("refresh"))) { |
a6a76f
|
882 |
//刷新key过期时间 |
F |
883 |
redisTemplate.opsForValue().getOperations().expire(InvitationCode.TOKEN_STR + tokenInfo.getDbid() + ":" + tokenInfo.getUsercode(), 12, TimeUnit.HOURS); |
|
884 |
} |
|
885 |
//验证token合法性,对比随机数 |
|
886 |
String[] tokenStr = ((String) object).split("#");//0是密码,1是随机数 by danaus 2020/9/24 10:18 |
|
887 |
// if (tokenStr[1] == null || "".equals(tokenStr[1]) || tokenInfo.getRand() != Double.parseDouble(tokenStr[1])) { |
|
888 |
// this.printJson(response, callBackMessage.sendErrorMessage("不是合法的token", -1001)); |
|
889 |
// return null; |
|
890 |
// } |
5012fc
|
891 |
//检查数据源是否已禁用 |
F |
892 |
final DataSourceEntity dataSourceMap = MultiDataSource.getDataSourceMap("" + tokenInfo.getDbid()); |
|
893 |
if(dataSourceMap!=null){ |
|
894 |
Integer expiredMinute = (dataSourceMap.getExpiredMinute() == null ? null : (Integer) dataSourceMap.getExpiredMinute());//过期时间:null或负数表示未过期,正数表示已过期 |
|
895 |
boolean actived = dataSourceMap.getActived(); |
|
896 |
if ((expiredMinute != null && expiredMinute.intValue() > 0) || !actived) { |
|
897 |
throw new ApplicationException("系统已过期,请联络服务提供商"); |
|
898 |
} |
|
899 |
} |
a6a76f
|
900 |
//进行登录操作 |
F |
901 |
tokenInfo.setPwd(tokenStr[0]); |
|
902 |
request.setAttribute("account", tokenInfo.getUsercode()); |
|
903 |
request.setAttribute("pwd", tokenInfo.getPwd()); |
|
904 |
request.setAttribute("isApp", "1"); |
|
905 |
request.setAttribute("dataName", tokenInfo.getDbid() + ""); |
|
906 |
request.setAttribute("isone", tokenInfo.getDbid() + ""); |
|
907 |
request.setAttribute("postTokenV2", "1");//说明是通过V2版提交,之后在登录成功后就不返回token。 |
cdc83b
|
908 |
if(org.apache.commons.lang3.StringUtils.isNotBlank(request.getParameter("loginByCode"))) { |
F |
909 |
request.setAttribute("loginByCode", 1);//限制设备功能新增 |
|
910 |
} |
5012fc
|
911 |
|
a6a76f
|
912 |
} catch (Exception ex) { |
5012fc
|
913 |
this.printJson(response, callBackMessage.sendErrorMessage(this.getErrorMsg(ex))); |
a6a76f
|
914 |
return ""; |
F |
915 |
} |
|
916 |
return login(request, response); |
|
917 |
} |
|
918 |
|
3c1697
|
919 |
/** |
F |
920 |
* SMS验证码进行登录 |
|
921 |
* @param code |
|
922 |
* @param request |
|
923 |
* @param response |
|
924 |
* @return |
|
925 |
*/ |
|
926 |
@RequestMapping("/api/loginByCode.do") |
cdc83b
|
927 |
public String loginByCode(String tel, String code, HttpServletRequest request, HttpServletResponse response) { |
3c1697
|
928 |
CallBackMessage callBackMessage = new CallBackMessage(); |
F |
929 |
if (org.apache.commons.lang3.StringUtils.isBlank(code)) { |
|
930 |
this.printJson(response, callBackMessage.sendErrorMessage("验证码不能为空", -1)); |
|
931 |
return ""; |
|
932 |
} |
|
933 |
String verifyCode = (String) redisTemplate.opsForValue().get(VerificationCodes.getCodeKey(tel)); |
|
934 |
if (verifyCode==null) { |
|
935 |
printJson(response, callBackMessage.sendErrorMessage("验证码已失效,请重新获取验证码。",-1)); |
|
936 |
return ""; |
|
937 |
} |
|
938 |
if (!code.equals(verifyCode)) { |
|
939 |
printJson(response, callBackMessage.sendErrorMessage("验证码错误,请输入正确的验证码",-1)); |
|
940 |
return ""; |
cdc83b
|
941 |
}else { |
F |
942 |
redisTemplate.delete(VerificationCodes.getCodeKey(tel));//删除 |
|
943 |
printJson(response, callBackMessage.sendSuccessMessageByDefault()); |
3c1697
|
944 |
return ""; |
F |
945 |
} |
|
946 |
} |
10a409
|
947 |
/** |
F |
948 |
* 处理极光别名 |
|
949 |
* 先查询当前别名已绑定的设备数,如果超过8个则删除最后一个别人 |
|
950 |
* @param usercode |
|
951 |
* @param dbid |
|
952 |
*/ |
|
953 |
public void processJiguangAliases(String usercode,String dbid){ |
|
954 |
try { |
|
955 |
//查询别名绑定的设备列表 |
|
956 |
String aliase=dbid+"_"+usercode; |
|
957 |
String url = JpushAction.URL + "/v3/aliases/"+aliase+"?new_format=true"; |
|
958 |
final HttpGet httpGet = HttpClientUtil.CreateHttpGetByAuthorization(url, null, JpushAction.appKey, JpushAction.masterSecret); |
|
959 |
CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpGet); |
|
960 |
if (response.getStatusLine().getStatusCode() == 200) { |
|
961 |
final Map map = JSON.parseObject(EntityUtils.toString(response.getEntity(), "UTF-8"), Map.class); |
|
962 |
|
|
963 |
List<JiGuangAliaseEntity> list= JSON.parseArray(map.get("data") + "",JiGuangAliaseEntity.class); |
|
964 |
if(list!=null&&list.size()>8){ |
|
965 |
//--处理为只保留最新活跃天数的8个设备 |
|
966 |
StringJoiner joiner=new StringJoiner(","); |
|
967 |
int index=0; |
|
968 |
list= list.stream().sorted(Comparator.comparing(JiGuangAliaseEntity::getLast_online_date).reversed()).collect(Collectors.toList()); |
|
969 |
for (JiGuangAliaseEntity entity:list){ |
|
970 |
if(index>8){ |
|
971 |
joiner.add("\""+entity.getRegistration_id()+"\""); |
|
972 |
} |
|
973 |
index++; |
|
974 |
}; |
|
975 |
//---解绑多出来的设备 |
|
976 |
url=JpushAction.URL+"/v3/aliases/"+aliase; |
|
977 |
String data="{\n" + |
|
978 |
" \"registration_ids\":{\"remove\": ["+joiner.toString()+"]}\n" + |
|
979 |
"}"; |
3c1697
|
980 |
|
10a409
|
981 |
final HttpPost httpPost = HttpClientUtil.CreateHttpPostByAuthorization(url, data, false, JpushAction.appKey, JpushAction.masterSecret); |
F |
982 |
response = HttpClientUtil.getClient().execute(httpPost); |
|
983 |
if (response.getStatusLine().getStatusCode() !=200) { |
3c1697
|
984 |
log.info(usercode+"需要删除的极光别名关联设备ID:"+data); |
F |
985 |
String msg= EntityUtils.toString(response.getEntity(), "UTF-8"); |
|
986 |
throw new ApplicationException("删除极光别名关联设备出错:"+msg); |
10a409
|
987 |
} |
F |
988 |
} |
|
989 |
} else { |
|
990 |
throw new ApplicationException("获取极光别名出错:" + response.getStatusLine().getStatusCode() + "[" + response.getStatusLine().getReasonPhrase() + "]"); |
|
991 |
} |
|
992 |
|
|
993 |
}catch (Exception e){ |
|
994 |
System.out.println(e.getCause()==null?e.getMessage():e.getCause().getMessage()); |
|
995 |
} |
|
996 |
} |
a6a76f
|
997 |
private void print2(HttpServletResponse response, String sb, String redirect, Boolean isApp) { |
F |
998 |
CallBackMessage callBackMessage = new CallBackMessage(); |
|
999 |
// redirect Added by Johns Wang, 2016-03-06 |
|
1000 |
if (redirect != null && !"".equals(redirect)) { |
|
1001 |
redirect = URIUtil.encodeURIComponent(redirect); |
|
1002 |
callBackMessage.setData("{\"redirect\":\"" + redirect + "\"}"); |
|
1003 |
} |
|
1004 |
callBackMessage.sendErrorMessage(sb); |
|
1005 |
if (isApp != null && isApp) { |
ba6749
|
1006 |
if ("密码错误".equalsIgnoreCase(sb)) { |
a6a76f
|
1007 |
//密码不正确 以状态码为-1004返回给app,弹出登录界面 |
ba6749
|
1008 |
callBackMessage.sendErrorMessage(sb, -1004); |
a6a76f
|
1009 |
} |
F |
1010 |
this.print(response, callBackMessage.toString()); |
|
1011 |
} else { |
|
1012 |
this.print(response, callBackMessage.toString()); |
|
1013 |
} |
|
1014 |
// // this.print(response, "<script> |
|
1015 |
// // alert('"+sb+"');window.history.back();</script>"); |
|
1016 |
// if (redirect == null || redirect.equals("")) |
|
1017 |
// this.print(response, "<script> alert('" + sb + "');window.history.back();</script>"); |
|
1018 |
// else |
|
1019 |
// this.print(response, "<script> alert('" + sb + "');window.location='/login.jsp?redirect=" + redirect |
|
1020 |
// + "';</script>"); |
|
1021 |
// } |
|
1022 |
} |
|
1023 |
|
|
1024 |
private Map<String, Object> getSessionInfo(HttpSession session) { |
|
1025 |
Map<String, Object> map = new HashMap<String, Object>(); |
|
1026 |
map.put(SessionKey.HRCODE.replace("@", ""), session.getAttribute(SessionKey.HRCODE)); |
|
1027 |
map.put(SessionKey.HRNAME.replace("@", ""), session.getAttribute(SessionKey.HRNAME)); |
|
1028 |
map.put(SessionKey.USERNAME.replace("@", ""), session.getAttribute(SessionKey.USERNAME)); |
|
1029 |
map.put(SessionKey.USER_NAME.replace("@", ""), session.getAttribute(SessionKey.USER_NAME)); |
|
1030 |
map.put(SessionKey.ORIGINAL_USERNAME.replace("@", ""), session.getAttribute(SessionKey.ORIGINAL_USERNAME)); |
|
1031 |
map.put(SessionKey.USER.replace("@", ""), session.getAttribute(SessionKey.USER)); |
|
1032 |
map.put(SessionKey.ORIGINAL_USERCODE.replace("@", ""), session.getAttribute(SessionKey.ORIGINAL_USERCODE)); |
|
1033 |
map.put(SessionKey.USERCODE.replace("@", ""), session.getAttribute(SessionKey.USERCODE)); |
|
1034 |
map.put(SessionKey.COMPANY_ID.replace("@", ""), session.getAttribute(SessionKey.COMPANY_ID)); |
|
1035 |
map.put(SessionKey.COMPANY_NAME.replace("@", ""), session.getAttribute(SessionKey.COMPANY_NAME)); |
|
1036 |
map.put(SessionKey.COMPANYMEMO.replace("@", ""), session.getAttribute(SessionKey.COMPANYMEMO)); |
|
1037 |
map.put(SessionKey.VERSION_ID.replace("@", ""), session.getAttribute(SessionKey.VERSION_ID)); |
|
1038 |
map.put(SessionKey.DEPARTMENT.replace("@", ""), session.getAttribute(SessionKey.DEPARTMENT)); |
|
1039 |
map.put(SessionKey.CCCODE.replace("@", ""), session.getAttribute(SessionKey.CCCODE)); |
|
1040 |
map.put(SessionKey.CCNAME.replace("@", ""), session.getAttribute(SessionKey.CCNAME)); |
|
1041 |
map.put(SessionKey.SUPPER_USER.replace("@", ""), session.getAttribute(SessionKey.SUPPER_USER)); |
|
1042 |
map.put(SessionKey.ROLE_NAME.replace("@", ""), session.getAttribute(SessionKey.ROLE_NAME)); |
|
1043 |
map.put(SessionKey.DEFAULT_SET.replace("@", ""), session.getAttribute(SessionKey.DEFAULT_SET)); |
|
1044 |
map.put(SessionKey.LOGIN_TYPE.replace("@", ""), session.getAttribute(SessionKey.LOGIN_TYPE)); |
|
1045 |
map.put(SessionKey.isStopSystem.replace("@", ""), session.getAttribute(SessionKey.isStopSystem)); |
|
1046 |
map.put(SessionKey.OPEN_ID.replace("@", ""), session.getAttribute(SessionKey.OPEN_ID)); |
|
1047 |
map.put(SessionKey.CURRENCY.replace("@", ""), session.getAttribute(SessionKey.CURRENCY)); |
|
1048 |
map.put(SessionKey.SHOP_CCCDOE.replace("@", ""), session.getAttribute(SessionKey.SHOP_CCCDOE)); |
|
1049 |
; |
|
1050 |
map.put(SessionKey.SYSTEM_LANGUAGE.replace("@", ""), session.getAttribute(SessionKey.SYSTEM_LANGUAGE)); |
|
1051 |
map.put(SessionKey.DEFAULT_STCODE.replace("@", ""), session.getAttribute(SessionKey.DEFAULT_STCODE)); |
|
1052 |
map.put(SessionKey.DEFAULT_ACCTCODE.replace("@", ""), session.getAttribute(SessionKey.DEFAULT_ACCTCODE)); |
|
1053 |
map.put(SessionKey.UserCodePermission.replace("@", ""), session.getAttribute(SessionKey.UserCodePermission)); |
|
1054 |
map.put(SessionKey.COMPANY_PERMISSION.replace("@", ""), session.getAttribute(SessionKey.COMPANY_PERMISSION)); |
|
1055 |
map.put(SessionKey.AT_TODAY.replace("@", ""), session.getAttribute(SessionKey.AT_TODAY)); |
|
1056 |
map.put(SessionKey.AT_NOW.replace("@", ""), session.getAttribute(SessionKey.AT_NOW)); |
|
1057 |
map.put(SessionKey.DEFAULT_BRAND.replace("@", ""), session.getAttribute(SessionKey.DEFAULT_BRAND)); |
|
1058 |
map.put(SessionKey.CCCODEPERMISSION.replace("@", ""), session.getAttribute(SessionKey.CCCODEPERMISSION)); |
|
1059 |
map.put(SessionKey.USERTYPE.replace("@", ""), session.getAttribute(SessionKey.USERTYPE)); |
|
1060 |
map.put(SessionKey.ISMODIFYPRICEWHENSCANQRCODE, session.getAttribute(SessionKey.ISMODIFYPRICEWHENSCANQRCODE)); |
625716
|
1061 |
map.put(SessionKey.ISMODIFYPRICEWHENSALESORDER, session.getAttribute(SessionKey.ISMODIFYPRICEWHENSALESORDER)); |
F |
1062 |
map.put(SessionKey.ISMODIFYPRICEWHENPURCHASEORDER, session.getAttribute(SessionKey.ISMODIFYPRICEWHENPURCHASEORDER)); |
21e5fd
|
1063 |
map.put(SessionKey.SWITCHTOPAGEWHENLOGONAPP, session.getAttribute(SessionKey.SWITCHTOPAGEWHENLOGONAPP)); |
fe0a59
|
1064 |
map.put(SessionKey.SELECTNEXTDOCUMENTWHENAPPROVED, session.getAttribute(SessionKey.SELECTNEXTDOCUMENTWHENAPPROVED)); |
2f46cc
|
1065 |
map.put(SessionKey.ISSTARTUPPOPUPMESSAGES, session.getAttribute(SessionKey.ISSTARTUPPOPUPMESSAGES)); |
a6a76f
|
1066 |
map.put("day", DateUtil.getDay(0)); |
F |
1067 |
map.put("month", DateUtil.getMonth(0)); |
|
1068 |
map.put("year", DateUtil.getYear(0)); |
|
1069 |
return map; |
|
1070 |
|
|
1071 |
} |
|
1072 |
|
|
1073 |
private void proccError(String account, String pwd, HttpServletRequest request, HttpServletResponse response) { |
d75ad0
|
1074 |
Boolean isApp = Boolean.valueOf((request.getParameter("isApp") == null&&request.getAttribute("isApp") == null) ? false : true);// 手机app传过来 |
a6a76f
|
1075 |
try { |
F |
1076 |
SpObserver.setDBtoInstance("_" + request.getSession().getAttribute(SessionKey.DATA_BASE_ID)); |
|
1077 |
record.loginRecord(account, pwd, IPUtil.getIpAddr(request));// 记录登录登录失败的信息 |
|
1078 |
} catch (Exception e2) { |
d75ad0
|
1079 |
e2.printStackTrace(); |
a6a76f
|
1080 |
this.print2(response, e2.getMessage().replace("\"", ""), request.getParameter("redirect"), isApp); |
F |
1081 |
} finally { |
|
1082 |
SpObserver.setDBtoInstance(); |
|
1083 |
} |
|
1084 |
this.print2(response, "用户账号或密码错误!", request.getParameter("redirect"), isApp); |
|
1085 |
} |
|
1086 |
|
|
1087 |
@RequestMapping("/logout.do") |
|
1088 |
public void logout(HttpServletRequest request, HttpServletResponse response) { |
|
1089 |
try { |
|
1090 |
HttpSession session = request.getSession(); |
|
1091 |
session.invalidate(); |
|
1092 |
this.printJson(response, "{\"success\":\"ok\"}"); |
|
1093 |
} catch (Exception e) { |
|
1094 |
e.printStackTrace(); |
|
1095 |
this.printJson(response, "{\"error\":\"" + e.getMessage() + "\"}"); |
|
1096 |
} |
|
1097 |
} |
|
1098 |
|
|
1099 |
|
|
1100 |
@RequestMapping("/GetLoginUser.do") |
|
1101 |
public void getLoginUser(HttpServletRequest request, HttpServletResponse response) { |
|
1102 |
int pageSize = 0; |
|
1103 |
int curPage = 0; |
|
1104 |
int total = 0; |
|
1105 |
List<Map<String, Object>> list = null; |
|
1106 |
try { |
|
1107 |
pageSize = Integer.parseInt(request.getParameter("rows"));// 每页大小 |
|
1108 |
curPage = Integer.parseInt(request.getParameter("page")); // 当前页 |
|
1109 |
} catch (Exception e) { |
|
1110 |
return; |
|
1111 |
} |
|
1112 |
|
|
1113 |
// 搜索条件 |
|
1114 |
String companyname = request.getParameter("companyname"); |
|
1115 |
String usercode = request.getParameter("usercode"); |
|
1116 |
String username = request.getParameter("username"); |
|
1117 |
try { |
|
1118 |
SpObserver.setDBtoInstance("_" + request.getSession().getAttribute(SessionKey.DATA_BASE_ID)); |
|
1119 |
if (StringUtils.isBlank(companyname) && StringUtils.isBlank(usercode) && StringUtils.isBlank(username)) { |
|
1120 |
total = userAccountService.getUserTotal(); |
|
1121 |
list = userAccountService.getLoginUser(curPage, pageSize); |
|
1122 |
} else { |
|
1123 |
total = userAccountService.getUserTotal(companyname, usercode, username); |
|
1124 |
list = userAccountService.getLoginUser(curPage, pageSize, companyname, usercode, username); |
|
1125 |
} |
|
1126 |
} finally { |
|
1127 |
SpObserver.setDBtoInstance(); |
|
1128 |
} |
|
1129 |
Gson gson = new Gson(); |
|
1130 |
String data = gson.toJson(list); |
|
1131 |
|
|
1132 |
StringBuilder sb = new StringBuilder(); |
|
1133 |
sb.append("{\"total\":").append(total).append(",\"rows\":").append(data).append("}"); |
|
1134 |
|
|
1135 |
try { |
|
1136 |
printText(response, sb.toString()); |
|
1137 |
} catch (IOException e) { |
|
1138 |
e.printStackTrace(); |
|
1139 |
} |
|
1140 |
|
|
1141 |
data = null; |
|
1142 |
sb = null; |
|
1143 |
list = null; |
|
1144 |
gson = null; |
|
1145 |
} |
|
1146 |
|
|
1147 |
/** |
|
1148 |
* 输出信息到客户端 |
|
1149 |
* |
|
1150 |
* @param response |
|
1151 |
* @param str |
|
1152 |
* @throws IOException |
|
1153 |
*/ |
|
1154 |
public void printText(HttpServletResponse response, String str) throws IOException { |
|
1155 |
response.setCharacterEncoding("utf-8"); |
|
1156 |
PrintWriter out = response.getWriter(); |
|
1157 |
out.write(str); |
|
1158 |
out.flush(); |
|
1159 |
out.close(); |
|
1160 |
} |
|
1161 |
|
|
1162 |
/** |
|
1163 |
* 设置session 相关值(添加新的session标识符时应在切换用户功能添加相应的session标识符com.yc.action.login.SwitchUserCodeAction) |
|
1164 |
* |
|
1165 |
* @param dbId |
|
1166 |
* @param userAccount |
|
1167 |
* @param session |
|
1168 |
* @return |
|
1169 |
* @throws Exception |
|
1170 |
*/ |
|
1171 |
public static String setSessionValues(String dbId, UserAccountEntity userAccount, HttpSession session, |
|
1172 |
PerssionEntity perssionEntity) throws Exception { |
|
1173 |
// ------------用SessionKey类来存储session标识符 避免大小写或者忘记session标识符的情况------- |
|
1174 |
Map<String, Object> role = perssionEntity.getRole(); // rIfc.getRole(userAccount.getUserCode()); |
|
1175 |
String userCode = (String) userAccount.getUserCode(); |
|
1176 |
session.setAttribute(SessionKey.HRCODE, ((String) userAccount.getHrCode()).replaceAll("\\s", ""));// 用户ID |
|
1177 |
session.setAttribute(SessionKey.HRNAME, ((String) userAccount.getHrName()).replaceAll("\\s", ""));// 用户ID |
|
1178 |
String userName = (String) userAccount.getUserName();// 用户名 |
|
1179 |
session.setAttribute(SessionKey.USERNAME, userName.replaceAll("\\s", "")); |
|
1180 |
session.setAttribute(SessionKey.USER_NAME, userName.replaceAll("\\s", "")); |
|
1181 |
session.setAttribute(SessionKey.PASSWORD, userAccount.getPassword()); |
|
1182 |
session.setAttribute(SessionKey.ORIGINAL_USERNAME, userName.replaceAll("\\s", "")); |
|
1183 |
session.setAttribute(SessionKey.USER, userCode.replaceAll("\\s", ""));// 用户ID |
|
1184 |
session.setAttribute(SessionKey.ORIGINAL_USERCODE, userCode.replaceAll("\\s", "")); |
|
1185 |
session.setAttribute(SessionKey.USERCODE, userCode.replaceAll("\\s", ""));// 用户ID |
|
1186 |
session.setAttribute(SessionKey.COMPANY_ID, userAccount.getCompanyId());// 公司代码 |
|
1187 |
session.setAttribute(SessionKey.COMPANY_NAME, userAccount.getCompanyName());// 公司代码 |
|
1188 |
session.setAttribute(SessionKey.COMPANYMEMO, userAccount.getCompanyMemo());// 适合于多公司 |
|
1189 |
session.setAttribute(SessionKey.VERSION_ID, 0);// 版本号 |
|
1190 |
session.setAttribute(SessionKey.DEPARTMENT, userAccount.getCcName()); |
|
1191 |
session.setAttribute(SessionKey.CCCODE, userAccount.getCcCode()); |
|
1192 |
session.setAttribute(SessionKey.CCNAME, userAccount.getCcName()); |
3c1697
|
1193 |
session.setAttribute(SessionKey.USER_TELE_PHONE, userAccount.getApp_userCode());//手机号 |
a6a76f
|
1194 |
session.setAttribute(SessionKey.SUPPER_USER, |
ba6749
|
1195 |
("SuperUser".equalsIgnoreCase(userAccount.getUserType()) || "DeveloperUser".equalsIgnoreCase(userAccount.getUserType())) ? "1" : "0");// 系统管理员 |
a6a76f
|
1196 |
session.setAttribute(SessionKey.isStopSystem, userAccount.isStopSystem() ? "1" : "0"); |
F |
1197 |
session.setAttribute(SessionKey.OPEN_ID, userAccount.getOpenId());// openid号 |
|
1198 |
session.setAttribute(SessionKey.CURRENCY, userAccount.getCurrency()); |
|
1199 |
session.setAttribute(SessionKey.SHOP_CCCDOE, userAccount.getShopCcCode());// shopcccode |
|
1200 |
session.setAttribute(SessionKey.COMPANY_PERMISSION, userAccount.getCompanyPermission());// CompanyPermission |
|
1201 |
|
|
1202 |
session.setAttribute(SessionKey.ROLE_NAME, |
|
1203 |
role == null ? "未设置" : role.get("RoleName") == null ? "" : role.get("RoleName"));// 如超级用户 |
|
1204 |
|
|
1205 |
// 根据账号获取相关权限集合 |
|
1206 |
Map<String, Map<String, Object>> perssion = perssionEntity.getPerssion(); // userAccountService.getUserProfiles(userCode); |
|
1207 |
|
|
1208 |
// 获得缺省集合 |
|
1209 |
if (userAccount.getDefaultSet() != null && !"".equals(userAccount.getDefaultSet())) { |
|
1210 |
// DefaultSet.defaultSet2Session(userAccountService.getDefaultSet(userAccount.getDefaultSet()), |
|
1211 |
// session); |
|
1212 |
DefaultSet.defaultSet2Session(perssionEntity.getDefaultSet(), session); |
|
1213 |
} |
|
1214 |
|
|
1215 |
// 构建账号对应的系统菜单 |
|
1216 |
session.setAttribute(SessionKey.PERSSION, perssion);// 权限集合 |
|
1217 |
session.setAttribute(SessionKey.LOGIN_TYPE, userAccount.getLogonType() + ""); |
|
1218 |
session.setAttribute(SessionKey.SYSTEM_LANGUAGE, "cnzh");// 设置语言 |
|
1219 |
session.setAttribute(SessionKey.DIBANG, userAccount.isEnableLoadCollection() ? "1" : "0");// 设置地磅权限 |
|
1220 |
// 添加地磅需要信息 默认先给空白 |
|
1221 |
session.setAttribute(SessionKey.LOADER_NAME, ""); |
|
1222 |
session.setAttribute(SessionKey.IP_ADDRESS, ""); |
|
1223 |
session.setAttribute(SessionKey.HOSTNAME, ""); |
|
1224 |
session.setAttribute(SessionKey.MAC_ADDRESS, ""); |
|
1225 |
session.setAttribute(SessionKey.AT_TODAY, DateUtil.toDayDate()); |
|
1226 |
session.setAttribute(SessionKey.AT_NOW, DateUtil.toDay()); |
|
1227 |
session.setAttribute(SessionKey.DEFAULT_STCODE, userAccount.getDefaultStcode()); |
|
1228 |
session.setAttribute(SessionKey.DEFAULT_ACCTCODE, userAccount.getDefaultAcctCode()); |
|
1229 |
session.setAttribute(SessionKey.UserCodePermission, userAccount.getUserCodePermission()); |
|
1230 |
session.setAttribute(SessionKey.DEFAULT_BRAND, userAccount.getDefaultBrand()); |
|
1231 |
session.setAttribute(SessionKey.CCCODEPERMISSION, userAccount.getCcCodePermission()); |
|
1232 |
session.setAttribute(SessionKey.ISMODIFYPRICEWHENSCANQRCODE, userAccount.getIsModifyPriceWhenScanQrCode()); |
625716
|
1233 |
session.setAttribute(SessionKey.ISMODIFYPRICEWHENSALESORDER, userAccount.getIsModifyPriceWhenSalesOrder()); |
F |
1234 |
session.setAttribute(SessionKey.ISMODIFYPRICEWHENPURCHASEORDER, userAccount.getIsModifyPriceWhenPurchaseOrder()); |
21e5fd
|
1235 |
session.setAttribute(SessionKey.SWITCHTOPAGEWHENLOGONAPP, userAccount.getSwitchToPageWhenLogonApp()); |
fe0a59
|
1236 |
session.setAttribute(SessionKey.SELECTNEXTDOCUMENTWHENAPPROVED, userAccount.getSelectNextDocumentWhenApproved()); |
2f46cc
|
1237 |
session.setAttribute(SessionKey.ISSTARTUPPOPUPMESSAGES, userAccount.getIsStartupPopupMessages()); |
ba6749
|
1238 |
session.setAttribute(SessionKey.USERTYPE, userAccount.getUserType()); |
a6a76f
|
1239 |
|
F |
1240 |
session.setAttribute(SessionKey.PAGE_PATH, |
|
1241 |
File.separator + "app" + File.separator + session.getAttribute(SessionKey.DATA_BASE_ID) + File.separator |
|
1242 |
+ session.getAttribute(SessionKey.VERSION_ID) + File.separator |
|
1243 |
+ session.getAttribute(SessionKey.SYSTEM_LANGUAGE)); |
|
1244 |
String realpath = session.getServletContext().getRealPath("/") + session.getAttribute(SessionKey.PAGE_PATH); |
|
1245 |
session.setAttribute(SessionKey.REAL_PATH, realpath.replaceAll("\\\\", "/")); |
|
1246 |
session.setAttribute(SessionKey.DATA_PATH, |
|
1247 |
File.separator + "app" + File.separator + session.getAttribute(SessionKey.DATA_BASE_ID) + File.separator |
|
1248 |
+ session.getAttribute(SessionKey.VERSION_ID) + File.separator |
|
1249 |
+ session.getAttribute(SessionKey.SYSTEM_LANGUAGE)); |
|
1250 |
InitSystem.getInstance().setMailSavePath(session.getServletContext() |
|
1251 |
.getRealPath(File.separator + "WEB-INF" + File.separator + "MAIL" + File.separator)); |
|
1252 |
// 结束地磅所需信息 |
|
1253 |
// 增加读取授权门店数 |
|
1254 |
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(dbId); |
|
1255 |
if (dataSourceEntity != null) { |
|
1256 |
session.setAttribute(SessionKey.LimitDepartmentNumber, dataSourceEntity.getLimitDepartmentNumber()); |
|
1257 |
session.setAttribute(SessionKey.DATACHECK_PAGENUM, dataSourceEntity.getDataCheckPageNum()); |
|
1258 |
} |
|
1259 |
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 |
|
1260 |
session.setAttribute(SessionKey.LOGIN_TIME, df.format(new Date()));//登录时间 xin 2020-8-31 11:35:22 |
e3dd14
|
1261 |
|
J |
1262 |
session.setAttribute(SessionKey.WEIXIN_USERID,userAccount.getWeiXinCorpUserId()); //企业微信登录userid ,Added by Johns Wang,2022-12-23 |
a6a76f
|
1263 |
return userName; |
F |
1264 |
|
|
1265 |
} |
|
1266 |
|
|
1267 |
public void setRecord(LoginRecordIfc record) { |
|
1268 |
this.record = record; |
|
1269 |
} |
|
1270 |
|
|
1271 |
// 检查session是否失效 |
|
1272 |
@RequestMapping("/checkSession.do") |
|
1273 |
public void sessionCheck(HttpServletRequest request, HttpServletResponse response) throws IOException { |
|
1274 |
HttpSession session = request.getSession(); |
|
1275 |
String result = ""; |
|
1276 |
if (session.getAttribute(SessionKey.HRCODE) == null) { |
|
1277 |
// userAccountService.doQuitLog(request.getParameter("usercode")); by 2014-8-5 |
|
1278 |
// danaus 会话失效写插进数据无意义且会出错 |
|
1279 |
result = "fail"; |
|
1280 |
} else { |
|
1281 |
result = "success"; |
|
1282 |
} |
|
1283 |
printText(response, "{\"status\":\"" + result + "\"}"); |
|
1284 |
} |
|
1285 |
|
|
1286 |
/** |
|
1287 |
* session失效后弹出登录框登录 |
|
1288 |
* |
|
1289 |
* @param request |
|
1290 |
* @param response 2012-09-20 |
|
1291 |
*/ |
|
1292 |
@RequestMapping("/againLogin.do") |
|
1293 |
public String againLogin(String usercode, String password, String dbid, String dbstr, String domain, |
|
1294 |
HttpServletRequest request, HttpServletResponse response) { |
|
1295 |
// System.out.println("againLogin..."+request.getSession().getId()+",时间:"+request.getSession().getCreationTime()); |
|
1296 |
StringBuilder sb = new StringBuilder(); |
|
1297 |
HttpSession session = request.getSession(); |
|
1298 |
CallBackMessage callBackMessage = new CallBackMessage(); |
|
1299 |
if (dbid == null || "".equals(dbid)) { |
|
1300 |
List<DataSourceEntity> dataSourceList = MultiDataSource.getDataSourceMapsByDomain(domain); |
|
1301 |
if (dataSourceList != null && dataSourceList.size() > 0) { |
|
1302 |
dbid = dataSourceList.get(0).getDbId() + ""; |
|
1303 |
} |
|
1304 |
} |
|
1305 |
try { |
|
1306 |
if (dbid == null || "".equals(dbid)) { |
|
1307 |
sb.append("数据库ID不能为空\\n"); |
|
1308 |
} |
|
1309 |
|
|
1310 |
if (StringUtils.isBlank(usercode)) { |
|
1311 |
sb.append("账号不能为空\\n"); |
|
1312 |
} |
|
1313 |
if (StringUtils.isBlank(password)) { |
|
1314 |
sb.append("密码不能为空\\n"); |
|
1315 |
} |
|
1316 |
if (sb.length() > 0) { |
|
1317 |
callBackMessage.sendErrorMessage(sb.toString()); |
|
1318 |
this.printJson(response, callBackMessage.toString()); |
|
1319 |
return null;// 验证出错返回' |
|
1320 |
} |
|
1321 |
|
|
1322 |
session.setAttribute(SessionKey.DATA_BASE_ID, dbid); |
|
1323 |
session.setAttribute(SessionKey.DATABASE_DIS, dbstr); |
|
1324 |
session.setAttribute(SessionKey.DOMAIN, request.getParameter("domain")); |
|
1325 |
|
|
1326 |
// -------------------- |
|
1327 |
// 判断是否超出人数限制 |
|
1328 |
|
|
1329 |
if (SessionListener.checkUserLimit(request, dbid)) { |
|
1330 |
String s = "当前登录人数已超过系统最大登录人数,如有需要增加登录人数,请联系软件公司"; |
|
1331 |
this.print2(response, s, null, null); |
|
1332 |
session.invalidate(); |
|
1333 |
return null;// 验证出错返回' |
|
1334 |
} |
|
1335 |
Boolean isApp = Boolean.valueOf(request.getParameter("isApp") == null ? false : true);// 手机app传过来 |
|
1336 |
if (usercode != null && usercode.length() > 30) {//解密为明文 |
|
1337 |
try { |
|
1338 |
usercode = ChangePassword.getDecryptPassword(usercode); |
|
1339 |
} catch (Exception e) { |
|
1340 |
e.printStackTrace(); |
|
1341 |
print2(response, this.getErrorMsg(e), null, isApp); |
|
1342 |
return null;// 验证出错返回' |
|
1343 |
|
|
1344 |
} |
|
1345 |
} |
|
1346 |
// ---------------- |
|
1347 |
// String dbid=session.getAttribute(SessionKey.DATA_BASE_ID)+""; |
|
1348 |
int recordeCount = 0; |
|
1349 |
try { |
|
1350 |
SpObserver.setDBtoInstance("_" + dbid); |
|
1351 |
recordeCount = record.getRecordCountIn10min(usercode); |
|
1352 |
} finally { |
|
1353 |
SpObserver.setDBtoInstance(); |
|
1354 |
} |
|
1355 |
if (recordeCount >= 5) { |
|
1356 |
try { |
|
1357 |
SpObserver.setDBtoInstance("_" + dbid); |
|
1358 |
record.loginRecord(usercode, password, IPUtil.getIpAddr(request));// 登录次数过多再行登陆作为登录失败处理 |
|
1359 |
} finally { |
|
1360 |
SpObserver.setDBtoInstance(); |
|
1361 |
} |
|
1362 |
this.print2(response, usercode + "在短时间内登录错误次数过多!请耐心的等10分钟后再登录!", null, null); |
|
1363 |
return null;// 验证出错返回 |
|
1364 |
} |
|
1365 |
|
|
1366 |
// session.setAttribute(SessionKey.ONLINE_USERS, new |
|
1367 |
// OnLineUser(usercode,userName,dbid,request.getParameter("domain")));//在线人数统计 |
|
1368 |
// 设置session |
|
1369 |
String ip = IPUtil.getIpAddr(request); |
|
1370 |
// 检查限制用户登录时间和登录IP |
|
1371 |
int s = 0; |
|
1372 |
try { |
|
1373 |
SpObserver.setDBtoInstance("_" + dbid); |
|
1374 |
s = userAccountService.checkUserLoginTimeAndIp(usercode, ip); |
|
1375 |
} finally { |
|
1376 |
SpObserver.setDBtoInstance(); |
|
1377 |
} |
|
1378 |
if (s == 0) { |
|
1379 |
print2(response, "该用户只能在工作时间或固定场所使用本系统[" + ip + "]", null, isApp); |
|
1380 |
return null; |
|
1381 |
} |
|
1382 |
// |
|
1383 |
// -------------- |
|
1384 |
// String ucode = usercode + Math.random();// 是为了区分用户重复问题,同一用户可以多人使用。 |
|
1385 |
// session.setAttribute(SessionKey.SAIL_USERCODE, ucode); |
|
1386 |
// OnLineUser.setOnlineUser(dataString, ucode, session); |
|
1387 |
// session.setAttribute(SessionKey.ONLINE_USERS, new OnLineUser());// 在线人数统计 |
|
1388 |
// ------------------ |
|
1389 |
|
|
1390 |
|
|
1391 |
UserAccountEntity userAccount = null; |
|
1392 |
try { |
|
1393 |
SpObserver.setDBtoInstance("_" + dbid); |
|
1394 |
userAccount = userAccountService.getUserInfoByUserCode(usercode); |
|
1395 |
if (userAccount == null) { |
|
1396 |
userAccount = userAccountService.getUserInfoByTelephone(usercode); //允许电话登录 |
|
1397 |
} |
|
1398 |
|
|
1399 |
if (userAccount == null) { |
|
1400 |
userAccount = userAccountService.getUserInfoByEmail(usercode); //允许邮箱号登录 |
|
1401 |
} |
|
1402 |
} finally { |
|
1403 |
SpObserver.setDBtoInstance(); |
|
1404 |
} |
|
1405 |
|
|
1406 |
if (userAccount == null) { |
|
1407 |
try { |
|
1408 |
SpObserver.setDBtoInstance("_" + dbid); |
|
1409 |
record.loginRecord(usercode, password, IPUtil.getIpAddr(request));// 记录登录登录失败的信息 |
|
1410 |
} finally { |
|
1411 |
SpObserver.setDBtoInstance(); |
|
1412 |
} |
|
1413 |
|
fbcd37
|
1414 |
this.print2(response, usercode+"未开通ERP系统服务,登录失败", request.getParameter("redirect"), isApp); |
a6a76f
|
1415 |
return null; |
fbcd37
|
1416 |
}else { |
F |
1417 |
if(userAccount.isInActive()){ |
|
1418 |
this.print2(response, usercode+"已被停用,禁止登录本系统!", request.getParameter("redirect"), isApp); |
|
1419 |
return null; |
|
1420 |
} |
a6a76f
|
1421 |
} |
F |
1422 |
try { |
|
1423 |
if (!userAccount.checkPassword(password)) { |
|
1424 |
try { |
|
1425 |
SpObserver.setDBtoInstance("_" + dbid); |
|
1426 |
record.loginRecord(usercode, password, IPUtil.getIpAddr(request));// 记录登录登录失败的信息 |
|
1427 |
} finally { |
|
1428 |
SpObserver.setDBtoInstance(); |
|
1429 |
} |
|
1430 |
this.print2(response, "用户密码不正确!", request.getParameter("redirect"), isApp); |
|
1431 |
return null; |
|
1432 |
} |
|
1433 |
} catch (Exception ex) { |
|
1434 |
this.print2(response, ex.getMessage(), request.getParameter("redirect"), isApp); |
|
1435 |
} |
2e5389
|
1436 |
if (isApp) { |
F |
1437 |
session.setAttribute(SessionKey.USER_LOGIN_TYPE, SessionKey.USER_LOGIN_TYPE_APP);//app 类型 |
|
1438 |
//判断当前登录设备是否与最新一次登录设备是一样,不一样需要返回给前端,输出短信进行验证登录 |
|
1439 |
|
|
1440 |
} else { |
|
1441 |
session.setAttribute(SessionKey.USER_LOGIN_TYPE, SessionKey.USER_LOGIN_TYPE_WEB);//web 类型 |
|
1442 |
} |
|
1443 |
final DataSourceEntity dataSourceMap = MultiDataSource.getDataSourceMap(dbid); |
|
1444 |
//--------------------------------- |
|
1445 |
if(dataSourceMap.isLoginOnceForOneUserCode()) { |
|
1446 |
//限制多设备登录 |
|
1447 |
this.singleAccount(isApp ? "2" : "1", dbid, userAccount, request); |
|
1448 |
} |
a6a76f
|
1449 |
// 设置权限 |
ba6749
|
1450 |
processLoginUserToSessionV2(ip, dbid, request, userAccount); |
2e5389
|
1451 |
//把新会话id替换websocket中对应用户的会话id, |
F |
1452 |
//--同一用户重新连接,如果存在已有会话是打开状态,则删除这个会话,启用新会话 |
|
1453 |
if(WebSocketMessageServer.getOnlineUserList()!=null&&WebSocketMessageServer.getOnlineUserList().size()>0) { |
|
1454 |
String key = RedisSocket.CHANEL_WS_MESSAGES + ":" + dbid + ":1:" + usercode + ":"; |
|
1455 |
for (Map.Entry<String, WsMessageUserEntity> entry : WebSocketMessageServer.getOnlineUserList().entrySet()) { |
|
1456 |
if (entry.getKey().contains(key)) { |
|
1457 |
if (entry.getValue().getSession().isOpen()) { |
|
1458 |
WsMessageUserEntity wsMessageUser= entry.getValue(); |
|
1459 |
wsMessageUser.setSessionId(session.getId()); |
|
1460 |
WebSocketMessageServer.getOnlineUserList().put(key+session.getId(),wsMessageUser); |
|
1461 |
break; |
|
1462 |
} |
|
1463 |
} |
|
1464 |
} |
|
1465 |
} |
a6a76f
|
1466 |
callBackMessage.sendSuccessMessage("登录成功"); |
F |
1467 |
this.printJson(response, callBackMessage.toString()); |
|
1468 |
return null; |
|
1469 |
} catch (NullPointerException e) {// 不存在此账号 |
|
1470 |
e.printStackTrace(); |
|
1471 |
proccError(usercode, password, request, response); |
|
1472 |
return null; |
|
1473 |
} catch (RuntimeException e) { |
|
1474 |
e.printStackTrace(); |
|
1475 |
if (e.getMessage().equals(SessionKey.DEMO_REF)) { |
|
1476 |
session.setAttribute(SessionKey.DEMO_REF, SessionKey.DEMO_REF); |
|
1477 |
this.print(response, "<script>alert('请生成正确配置信息');window.location.href='/demo/demoList.jsp';</script>"); |
|
1478 |
} |
|
1479 |
return null; |
|
1480 |
} catch (Exception e) {// 不存在此账号 |
|
1481 |
e.printStackTrace(); |
|
1482 |
proccError(usercode, password, request, response); |
|
1483 |
return null; |
|
1484 |
} |
|
1485 |
} |
|
1486 |
|
|
1487 |
private class AppJsonObject { |
|
1488 |
private boolean myResult; |
|
1489 |
private HttpServletResponse mResponse; |
|
1490 |
private String mUserCode; |
|
1491 |
private String mPassword; |
|
1492 |
private Boolean mIsApp; |
|
1493 |
private String mRedirect; |
|
1494 |
private List<Map<String, Object>> mList; |
|
1495 |
private boolean mCh_userid; |
|
1496 |
private String mDbId; |
|
1497 |
private String mDataBaseDis; |
|
1498 |
private String mDomain; |
|
1499 |
private UserAccountEntity mUserAccount; |
|
1500 |
|
|
1501 |
public AppJsonObject(HttpServletResponse response, String userCode, String password, Boolean isApp, String redirect, List<Map<String, Object>> list) { |
|
1502 |
mResponse = response; |
|
1503 |
mUserCode = userCode; |
|
1504 |
mPassword = password; |
|
1505 |
mIsApp = isApp; |
|
1506 |
mRedirect = redirect; |
|
1507 |
mList = list; |
|
1508 |
} |
|
1509 |
|
|
1510 |
boolean is() { |
|
1511 |
return myResult; |
|
1512 |
} |
|
1513 |
|
|
1514 |
public String getUserCode() { |
|
1515 |
return mUserCode; |
|
1516 |
} |
|
1517 |
|
|
1518 |
public String getPassword() { |
|
1519 |
return mPassword; |
|
1520 |
} |
|
1521 |
|
|
1522 |
public boolean isCh_userid() { |
|
1523 |
return mCh_userid; |
|
1524 |
} |
|
1525 |
|
|
1526 |
public String getDbId() { |
|
1527 |
return mDbId; |
|
1528 |
} |
|
1529 |
|
|
1530 |
public String getDataBaseDis() { |
|
1531 |
return mDataBaseDis; |
|
1532 |
} |
|
1533 |
|
|
1534 |
public String getDomain() { |
|
1535 |
return mDomain; |
|
1536 |
} |
|
1537 |
|
|
1538 |
public UserAccountEntity getUserAccount() { |
|
1539 |
return mUserAccount; |
|
1540 |
} |
|
1541 |
|
|
1542 |
public AppJsonObject invoke() { |
|
1543 |
Map<String, Object> map = mList.get(0); |
|
1544 |
mDbId = map.get("id") + ""; |
|
1545 |
mDataBaseDis = (String) map.get("systemid"); |
|
1546 |
mDomain = (String) map.get("domain"); |
|
1547 |
// 通过数据源id和手机号取得用户usercode进行登录,这时候不需要密码验证 |
|
1548 |
try { |
|
1549 |
SpObserver.setDBtoInstance("_" + mDbId); |
|
1550 |
mUserAccount = userAccountService.getUserInfoByTelephone(mUserCode); |
|
1551 |
if (mUserAccount != null) { |
fbcd37
|
1552 |
if(mUserAccount.isInActive()){ |
F |
1553 |
print2(mResponse, mUserCode+"已被停用,禁止登录本系统", mRedirect, mIsApp); |
|
1554 |
myResult = true; |
|
1555 |
return this; |
|
1556 |
} |
a6a76f
|
1557 |
mUserAccount.setApp_userCode(mUserCode); |
F |
1558 |
mUserAccount.setApp_Password(mPassword); |
|
1559 |
mUserCode = mUserAccount.getUserCode();//转成ERP的usercode进行登陆 |
|
1560 |
mPassword = mUserAccount.getPassword();//转成ERP的密码进行登陆 |
|
1561 |
mCh_userid = true; |
|
1562 |
} else { |
fbcd37
|
1563 |
print2(mResponse, mUserCode+"未开通ERP系统服务,登录失败", mRedirect, mIsApp); |
a6a76f
|
1564 |
myResult = true; |
F |
1565 |
return this; |
|
1566 |
} |
|
1567 |
} finally { |
|
1568 |
SpObserver.setDBtoInstance(); |
|
1569 |
} |
|
1570 |
myResult = false; |
|
1571 |
return this; |
|
1572 |
} |
|
1573 |
} |
|
1574 |
} |