HttpServletResponse response) throws Exception {
String account = request.getParameter("account");
String password = request.getParameter("password");
password = CodeUtil.encryptBase64(password, G4Constants.BASE64_KEY);
log.info("帐户[" + account + "]正尝试登陆系统...");
Dto dto = new BaseDto();
dto.put("account", account);
Dto outDto = organizationService.getUserInfo(dto);
UserInfoVo userInfo = (UserInfoVo) outDto.get("userInfo");
Dto jsonDto = new BaseDto();
if (G4Utils.isEmpty(userInfo)) {
jsonDto.put("success", new Boolean(false));
jsonDto.put("msg", "帐号输入错误,请重新输入!");
jsonDto.put("errorType", "1");
log.warn("帐户[" + account + "]登陆失败.(失败原因:不存在此帐户)");
write(jsonDto.toJson(), response);
return mapping.findForward("");
}
if (!password.equals(userInfo.getPassword())) {
jsonDto.put("success", new Boolean(false));
jsonDto.put("msg", "密码输入错误,请重新输入!");
jsonDto.put("errorType", "2");
log.warn(userInfo.getUsername() + "[" + userInfo.getAccount() + "]" + "登录系统失败(失败原因:密码输入错误)");
write(jsonDto.toJson(), response);
return mapping.findForward("");
}
String multiSession = WebUtils.getParamValue("MULTI_SESSION", request);
if ("0".equals(multiSession)) {
Integer sessions = (Integer) g4Reader.queryForObject("Organization.countHttpSessions", account);
if (sessions.intValue() > 0) {
jsonDto.put("success", new Boolean(false));
jsonDto.put("msg", "此用户已经登录,系统不允许建立多个会话连接!");
jsonDto.put("errorType", "3");
log.warn(userInfo.getUsername() + "[" + userInfo.getAccount() + "]"
+ "登录系统失败(失败原因:此用户已经登录,系统参数配置为不允许一个用户建立多个连接)");
write(jsonDto.toJson(), response);
return mapping.findForward("");
}
}
userInfo.setSessionID(request.getSession().getId());
userInfo.setSessionCreatedTime(G4Utils.getCurrentTime());
userInfo.setLoginIP(request.getRemoteAddr());
userInfo.setExplorer(G4Utils.getClientExplorerType(request));
if (!checkMultiUser(userInfo, request)) {
jsonDto.put("success", new Boolean(false));
jsonDto.put("msg", "不允许在同一客户端上同时以不同帐户登录系统,请先退出你已经登录的帐户后再尝试登录!");
jsonDto.put("errorType", "1");
log.warn("帐户[" + account + "]登陆失败.(失败原因:不允许在同一客户端上同时以不同帐户登录系统.请先退出你已经登录的帐户后再尝试登录)");
write(jsonDto.toJson(), response);
return mapping.findForward("");
}
super.getSessionContainer(request).setUserInfo(userInfo);
log.info(userInfo.getUsername() + "[" + userInfo.getAccount() + "]" + "成功登录系统!创建了一个有效Session连接,会话ID:["
+ request.getSession().getId() + "]" + G4Utils.getCurrentTime());
SessionListener.addSession(request.getSession(), userInfo); // 保存有效Session
if (g4PHelper.getValue("requestMonitor", "0").equals("1")) {
saveLoginEvent(userInfo, request);
}
jsonDto.put("success", new Boolean(true));
jsonDto.put("userid", userInfo.getUserid());
write(jsonDto.toJson(), response);
return mapping.findForward("");
}