|
|
@@ -8,13 +8,9 @@ import com.ruoyi.common.core.constant.UserConstants;
|
|
8
|
8
|
import com.ruoyi.common.core.domain.R;
|
|
9
|
9
|
import com.ruoyi.common.core.enums.UserStatus;
|
|
10
|
10
|
import com.ruoyi.common.core.exception.ServiceException;
|
|
11
|
|
-import com.ruoyi.common.core.utils.ServletUtils;
|
|
12
|
11
|
import com.ruoyi.common.core.utils.StringUtils;
|
|
13
|
|
-import com.ruoyi.common.core.utils.ip.IpUtils;
|
|
14
|
12
|
import com.ruoyi.common.security.utils.SecurityUtils;
|
|
15
|
|
-import com.ruoyi.system.api.RemoteLogService;
|
|
16
|
13
|
import com.ruoyi.system.api.RemoteUserService;
|
|
17
|
|
-import com.ruoyi.system.api.domain.SysLogininfor;
|
|
18
|
14
|
import com.ruoyi.system.api.domain.SysUser;
|
|
19
|
15
|
import com.ruoyi.system.api.model.LoginUser;
|
|
20
|
16
|
|
|
|
@@ -27,10 +23,13 @@ import com.ruoyi.system.api.model.LoginUser;
|
|
27
|
23
|
public class SysLoginService
|
|
28
|
24
|
{
|
|
29
|
25
|
@Autowired
|
|
30
|
|
- private RemoteLogService remoteLogService;
|
|
|
26
|
+ private RemoteUserService remoteUserService;
|
|
31
|
27
|
|
|
32
|
28
|
@Autowired
|
|
33
|
|
- private RemoteUserService remoteUserService;
|
|
|
29
|
+ private SysPasswordService passwordService;
|
|
|
30
|
+
|
|
|
31
|
+ @Autowired
|
|
|
32
|
+ private SysRecordLogService recordLogService;
|
|
34
|
33
|
|
|
35
|
34
|
/**
|
|
36
|
35
|
* 登录
|
|
|
@@ -40,21 +39,21 @@ public class SysLoginService
|
|
40
|
39
|
// 用户名或密码为空 错误
|
|
41
|
40
|
if (StringUtils.isAnyBlank(username, password))
|
|
42
|
41
|
{
|
|
43
|
|
- recordLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写");
|
|
|
42
|
+ recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写");
|
|
44
|
43
|
throw new ServiceException("用户/密码必须填写");
|
|
45
|
44
|
}
|
|
46
|
45
|
// 密码如果不在指定范围内 错误
|
|
47
|
46
|
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
|
48
|
47
|
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH)
|
|
49
|
48
|
{
|
|
50
|
|
- recordLogininfor(username, Constants.LOGIN_FAIL, "用户密码不在指定范围");
|
|
|
49
|
+ recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户密码不在指定范围");
|
|
51
|
50
|
throw new ServiceException("用户密码不在指定范围");
|
|
52
|
51
|
}
|
|
53
|
52
|
// 用户名不在指定范围内 错误
|
|
54
|
53
|
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
|
55
|
54
|
|| username.length() > UserConstants.USERNAME_MAX_LENGTH)
|
|
56
|
55
|
{
|
|
57
|
|
- recordLogininfor(username, Constants.LOGIN_FAIL, "用户名不在指定范围");
|
|
|
56
|
+ recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户名不在指定范围");
|
|
58
|
57
|
throw new ServiceException("用户名不在指定范围");
|
|
59
|
58
|
}
|
|
60
|
59
|
// 查询用户信息
|
|
|
@@ -67,33 +66,29 @@ public class SysLoginService
|
|
67
|
66
|
|
|
68
|
67
|
if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData()))
|
|
69
|
68
|
{
|
|
70
|
|
- recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");
|
|
|
69
|
+ recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");
|
|
71
|
70
|
throw new ServiceException("登录用户:" + username + " 不存在");
|
|
72
|
71
|
}
|
|
73
|
72
|
LoginUser userInfo = userResult.getData();
|
|
74
|
73
|
SysUser user = userResult.getData().getSysUser();
|
|
75
|
74
|
if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
|
|
76
|
75
|
{
|
|
77
|
|
- recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
|
|
|
76
|
+ recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
|
|
78
|
77
|
throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
|
|
79
|
78
|
}
|
|
80
|
79
|
if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
|
|
81
|
80
|
{
|
|
82
|
|
- recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
|
|
|
81
|
+ recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
|
|
83
|
82
|
throw new ServiceException("对不起,您的账号:" + username + " 已停用");
|
|
84
|
83
|
}
|
|
85
|
|
- if (!SecurityUtils.matchesPassword(password, user.getPassword()))
|
|
86
|
|
- {
|
|
87
|
|
- recordLogininfor(username, Constants.LOGIN_FAIL, "用户密码错误");
|
|
88
|
|
- throw new ServiceException("用户不存在/密码错误");
|
|
89
|
|
- }
|
|
90
|
|
- recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
|
|
|
84
|
+ passwordService.validate(user, password);
|
|
|
85
|
+ recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
|
|
91
|
86
|
return userInfo;
|
|
92
|
87
|
}
|
|
93
|
88
|
|
|
94
|
89
|
public void logout(String loginName)
|
|
95
|
90
|
{
|
|
96
|
|
- recordLogininfor(loginName, Constants.LOGOUT, "退出成功");
|
|
|
91
|
+ recordLogService.recordLogininfor(loginName, Constants.LOGOUT, "退出成功");
|
|
97
|
92
|
}
|
|
98
|
93
|
|
|
99
|
94
|
/**
|
|
|
@@ -128,32 +123,6 @@ public class SysLoginService
|
|
128
|
123
|
{
|
|
129
|
124
|
throw new ServiceException(registerResult.getMsg());
|
|
130
|
125
|
}
|
|
131
|
|
- recordLogininfor(username, Constants.REGISTER, "注册成功");
|
|
132
|
|
- }
|
|
133
|
|
-
|
|
134
|
|
- /**
|
|
135
|
|
- * 记录登录信息
|
|
136
|
|
- *
|
|
137
|
|
- * @param username 用户名
|
|
138
|
|
- * @param status 状态
|
|
139
|
|
- * @param message 消息内容
|
|
140
|
|
- * @return
|
|
141
|
|
- */
|
|
142
|
|
- public void recordLogininfor(String username, String status, String message)
|
|
143
|
|
- {
|
|
144
|
|
- SysLogininfor logininfor = new SysLogininfor();
|
|
145
|
|
- logininfor.setUserName(username);
|
|
146
|
|
- logininfor.setIpaddr(IpUtils.getIpAddr(ServletUtils.getRequest()));
|
|
147
|
|
- logininfor.setMsg(message);
|
|
148
|
|
- // 日志状态
|
|
149
|
|
- if (StringUtils.equalsAny(status, Constants.LOGIN_SUCCESS, Constants.LOGOUT, Constants.REGISTER))
|
|
150
|
|
- {
|
|
151
|
|
- logininfor.setStatus(Constants.LOGIN_SUCCESS_STATUS);
|
|
152
|
|
- }
|
|
153
|
|
- else if (Constants.LOGIN_FAIL.equals(status))
|
|
154
|
|
- {
|
|
155
|
|
- logininfor.setStatus(Constants.LOGIN_FAIL_STATUS);
|
|
156
|
|
- }
|
|
157
|
|
- remoteLogService.saveLogininfor(logininfor, SecurityConstants.INNER);
|
|
|
126
|
+ recordLogService.recordLogininfor(username, Constants.REGISTER, "注册成功");
|
|
158
|
127
|
}
|
|
159
|
|
-}
|
|
|
128
|
+}
|