|
|
|
@ -2,12 +2,9 @@ package cn.estsh.i3plus.core.apiservice.controller.base;
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.base.ISystemLoginService;
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.busi.*;
|
|
|
|
|
import cn.estsh.i3plus.core.apiservice.controller.DemoAuthController;
|
|
|
|
|
import cn.estsh.i3plus.core.apiservice.serviceimpl.busi.SysLocaleLanguageService;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.ServletRequestTool;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SessionUser;
|
|
|
|
@ -27,6 +24,7 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
@ -89,20 +87,17 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
|
|
|
|
|
@GetMapping(value="/auth/login")
|
|
|
|
|
@ApiOperation(value="登陆",notes="登陆")
|
|
|
|
|
public ResultBean login(HttpServletRequest request, String loginName, String loginPwd, String languageCode){
|
|
|
|
|
public ResultBean login(HttpServletRequest request, String loginName, String loginPwd, String languageCode,
|
|
|
|
|
@RequestParam(required = false) String ipAddr){
|
|
|
|
|
LOGGER.info("用户登陆 loginName:{} loginPwd:{} languageCode:{}",loginName,loginPwd,languageCode);
|
|
|
|
|
ResultBean result = null;
|
|
|
|
|
try {
|
|
|
|
|
ValidatorBean.checkNotNull(loginName,"用户名不能为空");
|
|
|
|
|
ValidatorBean.checkNotNull(loginPwd,"密码不能为空");
|
|
|
|
|
ValidatorBean.checkNotNull(languageCode,"语言不能为空");
|
|
|
|
|
// ValidatorBean.checkNotNull(ipAddr,"IP 地址不能为空");
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
//先进行登出
|
|
|
|
|
AuthUtil.logout();
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
logout();
|
|
|
|
|
|
|
|
|
|
SessionUser user = userService.queryUserLogin(loginName,loginPwd.trim(),languageCode);
|
|
|
|
|
|
|
|
|
@ -115,10 +110,10 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
result.setUrl("/");
|
|
|
|
|
|
|
|
|
|
// 记录登录记录
|
|
|
|
|
recordSysUserLog(user.getUser().getUserInfoId(), loginName,CommonEnumUtil.USER_LOGIN_STATUS.LOGIN_SUCCESS.getValue(), request);
|
|
|
|
|
recordSysUserLog(user.getUser().getUserInfoId(), loginName,CommonEnumUtil.USER_LOGIN_STATUS.LOGIN_SUCCESS.getValue(), ipAddr);
|
|
|
|
|
} catch (IncorrectCredentialsException e) {
|
|
|
|
|
// 密码错误
|
|
|
|
|
Integer num = systemLoginService.doLoginPasswordError(loginName,request.getSession().getId());
|
|
|
|
|
Integer num = systemLoginService.doLoginPasswordError(loginName, ipAddr);
|
|
|
|
|
num = CommonConstWords.USER_LOGIN_ERROR_MAX_NUM - num;
|
|
|
|
|
result = ResultBean.fail(ImppExceptionEnum.LOGIN_EXCEPTION_USER_PASSWORD);
|
|
|
|
|
if(num == 0){
|
|
|
|
@ -128,55 +123,55 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 记录登录记录
|
|
|
|
|
recordSysUserLog(null, loginName, CommonEnumUtil.USER_LOGIN_STATUS.WRONG_PASSWORD.getValue(), request);
|
|
|
|
|
recordSysUserLog(null, loginName, CommonEnumUtil.USER_LOGIN_STATUS.WRONG_PASSWORD.getValue(), ipAddr);
|
|
|
|
|
} catch (CredentialsException e) {
|
|
|
|
|
// 用户名或密码错误
|
|
|
|
|
result = ResultBean.fail(ImppExceptionEnum.LOGIN_EXCEPTION_USER_NAME);
|
|
|
|
|
|
|
|
|
|
// 记录登录记录
|
|
|
|
|
recordSysUserLog(null, loginName,CommonEnumUtil.USER_LOGIN_STATUS.WRONG_USERNAME_OR_PASSWORD.getValue(), request);
|
|
|
|
|
recordSysUserLog(null, loginName,CommonEnumUtil.USER_LOGIN_STATUS.WRONG_USERNAME_OR_PASSWORD.getValue(), ipAddr);
|
|
|
|
|
} catch (LockedAccountException e) {
|
|
|
|
|
// 账号已锁定
|
|
|
|
|
result = ResultBean.fail(ImppExceptionEnum.LOGIN_EXCEPTION_USER_LOCKING);
|
|
|
|
|
|
|
|
|
|
// 记录登录记录
|
|
|
|
|
recordSysUserLog(null, loginName,CommonEnumUtil.USER_LOGIN_STATUS.USER_LOGIN_LOCKING.getValue(), request);
|
|
|
|
|
recordSysUserLog(null, loginName,CommonEnumUtil.USER_LOGIN_STATUS.USER_LOGIN_LOCKING.getValue(), ipAddr);
|
|
|
|
|
} catch (UnknownAccountException e) {
|
|
|
|
|
// 用户信息不存在
|
|
|
|
|
result = ResultBean.fail(ImppExceptionEnum.LOGIN_EXCEPTION_USER_INFO_NULL);
|
|
|
|
|
|
|
|
|
|
// 记录登录记录
|
|
|
|
|
recordSysUserLog(null, loginName,CommonEnumUtil.USER_LOGIN_STATUS.USER_INFO_NULL.getValue(), request);
|
|
|
|
|
recordSysUserLog(null, loginName,CommonEnumUtil.USER_LOGIN_STATUS.USER_INFO_NULL.getValue(), ipAddr);
|
|
|
|
|
} catch (AuthenticationException e) {
|
|
|
|
|
// 系统异常
|
|
|
|
|
result = ResultBean.fail(e.getMessage()).setCode(ImppExceptionEnum.SYSTEM_EXCEPTION.getCode());
|
|
|
|
|
result.setErrorMsg(e.getMessage());
|
|
|
|
|
|
|
|
|
|
// 记录登录记录
|
|
|
|
|
recordSysUserLog(null, loginName,CommonEnumUtil.USER_LOGIN_STATUS.SYSTEM_ERROR.getValue(), request);
|
|
|
|
|
recordSysUserLog(null, loginName,CommonEnumUtil.USER_LOGIN_STATUS.SYSTEM_ERROR.getValue(), ipAddr);
|
|
|
|
|
} catch (ImppBusiException e) {
|
|
|
|
|
result = ResultBean.fail(e);
|
|
|
|
|
|
|
|
|
|
// 记录登录记录
|
|
|
|
|
recordSysUserLog(null, loginName,CommonEnumUtil.USER_LOGIN_STATUS.SYSTEM_ERROR.getValue(), request);
|
|
|
|
|
recordSysUserLog(null, loginName,CommonEnumUtil.USER_LOGIN_STATUS.SYSTEM_ERROR.getValue(), ipAddr);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
result = ResultBean.fail(e.getMessage()).setCode(ImppExceptionEnum.SYSTEM_EXCEPTION.getCode())
|
|
|
|
|
.setErrorMsg(ImppExceptionEnum.SYSTEM_EXCEPTION.getDescription());
|
|
|
|
|
|
|
|
|
|
// 记录登录记录
|
|
|
|
|
recordSysUserLog(null, loginName,CommonEnumUtil.USER_LOGIN_STATUS.SYSTEM_ERROR.getValue(), request);
|
|
|
|
|
recordSysUserLog(null, loginName,CommonEnumUtil.USER_LOGIN_STATUS.SYSTEM_ERROR.getValue(), ipAddr);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void recordSysUserLog(Long userId, String username,Integer userLoginStatus,HttpServletRequest request){
|
|
|
|
|
private void recordSysUserLog(Long userId, String username,Integer userLoginStatus,String IpAddr){
|
|
|
|
|
SysLogUserLogin log = new SysLogUserLogin();
|
|
|
|
|
|
|
|
|
|
log.setUserId(userId);
|
|
|
|
|
log.setLogLoginName(username);
|
|
|
|
|
log.setLogLoginStatus(userLoginStatus);
|
|
|
|
|
log.setLogLoginBrowser(ServletRequestTool.getRequestBrowser(request));
|
|
|
|
|
log.setLogLoginHost(ServletRequestTool.getRequestHost(request));
|
|
|
|
|
log.setLogLoginHost(IpAddr);
|
|
|
|
|
log.setLogLoginPlatform(CommonEnumUtil.LOG_LOGIN_PLATFORM.descOf(ServletRequestTool.getRequestOs(request)));
|
|
|
|
|
log.setLogLoginDateTime(TimeTool.getNowTime(true));
|
|
|
|
|
|
|
|
|
|