|
|
@@ -9,8 +9,8 @@ import cn.reghao.tnb.account.app.redis.ds.RedisOps;
|
|
|
import cn.reghao.tnb.account.app.security.form.AccountAuthToken;
|
|
|
import cn.reghao.tnb.account.app.redis.RedisKeys;
|
|
|
import cn.reghao.jutil.web.ServletUtil;
|
|
|
-import cn.reghao.tnb.account.app.db.mapper.LoginAttemptsMapper;
|
|
|
-import cn.reghao.tnb.account.app.model.po.LoginAttempts;
|
|
|
+import cn.reghao.tnb.account.app.db.mapper.UserLoginMapper;
|
|
|
+import cn.reghao.tnb.account.app.model.po.UserLogin;
|
|
|
import cn.reghao.tnb.account.app.redis.ds.RedisString;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.security.web.authentication.preauth.PreAuthenticatedCredentialsNotFoundException;
|
|
|
@@ -29,12 +29,12 @@ import java.util.stream.Collectors;
|
|
|
public class LoginAttemptServiceImpl implements LoginAttemptService {
|
|
|
// 帐号可同时登入的设备数量
|
|
|
private final int maxDevice = 3;
|
|
|
- private final LoginAttemptsMapper attemptsMapper;
|
|
|
+ private final UserLoginMapper attemptsMapper;
|
|
|
private final RedisString redisString;
|
|
|
private final RedisOps redisOps;
|
|
|
private final AccountTokenService accountTokenService;
|
|
|
|
|
|
- public LoginAttemptServiceImpl(LoginAttemptsMapper attemptsMapper, RedisString redisString, RedisOps redisOps,
|
|
|
+ public LoginAttemptServiceImpl(UserLoginMapper attemptsMapper, RedisString redisString, RedisOps redisOps,
|
|
|
AccountTokenService accountTokenService) {
|
|
|
this.attemptsMapper = attemptsMapper;
|
|
|
this.redisString = redisString;
|
|
|
@@ -74,11 +74,11 @@ public class LoginAttemptServiceImpl implements LoginAttemptService {
|
|
|
|
|
|
if (loginIds.size() >= maxDevice) {
|
|
|
// 登出最早登入的设备
|
|
|
- List<LoginAttempts> list = attemptsMapper.findByLoginIds(loginIds).stream()
|
|
|
+ List<UserLogin> list = attemptsMapper.findByLoginIds(loginIds).stream()
|
|
|
.sorted((o1, o2) -> (int) (o1.getLoginAt()-o2.getLoginAt()))
|
|
|
.collect(Collectors.toList());
|
|
|
if (!list.isEmpty()) {
|
|
|
- LoginAttempts oldest = list.get(0);
|
|
|
+ UserLogin oldest = list.get(0);
|
|
|
accountTokenService.logout(oldest.getLoginId());
|
|
|
}
|
|
|
}
|
|
|
@@ -116,8 +116,8 @@ public class LoginAttemptServiceImpl implements LoginAttemptService {
|
|
|
String userAgent = request.getHeader("user-agent");
|
|
|
String loginIp = request.getRemoteAddr();
|
|
|
|
|
|
- LoginAttempts loginAttempts = new LoginAttempts(loginId, userId, plat, loginIp, loginType, userAgent, rememberMe);
|
|
|
- attemptsMapper.save(loginAttempts);
|
|
|
+ UserLogin userLogin = new UserLogin(loginId, userId, plat, loginIp, loginType, userAgent, rememberMe);
|
|
|
+ attemptsMapper.save(userLogin);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -139,24 +139,24 @@ public class LoginAttemptServiceImpl implements LoginAttemptService {
|
|
|
.filter(Objects::nonNull)
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
- List<LoginAttempts> loginAttemptsList = attemptsMapper.findByUserId(userId, 10);
|
|
|
- loginAttemptsList.forEach(loginAttempts -> {
|
|
|
- long userId0 = loginAttempts.getUserId();
|
|
|
- String loginId0 = loginAttempts.getLoginId();
|
|
|
+ List<UserLogin> userLoginList = attemptsMapper.findByUserId(userId, 10);
|
|
|
+ userLoginList.forEach(userLogin -> {
|
|
|
+ long userId0 = userLogin.getUserId();
|
|
|
+ String loginId0 = userLogin.getLoginId();
|
|
|
String redisKey = RedisKeys.getAuthTokenKey(userId0, loginId0);
|
|
|
boolean online = redisOps.exists(redisKey);
|
|
|
});
|
|
|
|
|
|
return attemptsMapper.findByLoginIds(loginIds).stream()
|
|
|
- .map(loginAttempts -> {
|
|
|
+ .map(userLogin -> {
|
|
|
String status = "在线";
|
|
|
- if (loginId.equals(loginAttempts.getLoginId())) {
|
|
|
+ if (loginId.equals(userLogin.getLoginId())) {
|
|
|
status += "(当前设备)";
|
|
|
}
|
|
|
|
|
|
- String loginAtStr = DateTimeConverter.format(loginAttempts.getLoginAt());
|
|
|
- String location = getLocationByIp(loginAttempts.getLoginIp());
|
|
|
- return new LoginRecordVo(loginAttempts.getLoginId(), loginAttempts.getUserAgent(), loginAttempts.getLoginIp(), location, loginAtStr, status);
|
|
|
+ String loginAtStr = DateTimeConverter.format(userLogin.getLoginAt());
|
|
|
+ String location = getLocationByIp(userLogin.getLoginIp());
|
|
|
+ return new LoginRecordVo(userLogin.getLoginId(), userLogin.getUserAgent(), userLogin.getLoginIp(), location, loginAtStr, status);
|
|
|
})
|
|
|
.collect(Collectors.toList());
|
|
|
}
|