🎨 优化记录最后在线时间代码
This commit is contained in:
parent
a620d4664b
commit
f63ed152fc
@ -37,7 +37,7 @@ public class SecurityAspect {
|
||||
Logger logger = LoggerFactory.getLogger(SecurityAspect.class);
|
||||
|
||||
@Pointcut("@annotation(com.rymcu.forest.core.service.security.annotation.SecurityInterceptor)")
|
||||
public void pointCut() {
|
||||
public void securityPointCut() {
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,7 +47,7 @@ public class SecurityAspect {
|
||||
* @return 方法执行结果
|
||||
* @throws Throwable 调用出错
|
||||
*/
|
||||
@Before(value = "pointCut()")
|
||||
@Before(value = "securityPointCut()")
|
||||
public void doBefore(JoinPoint joinPoint) throws BaseApiException {
|
||||
logger.info("检查用户修改信息权限 start ...");
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
|
@ -5,12 +5,12 @@ import com.rymcu.forest.jwt.def.JwtConstants;
|
||||
import com.rymcu.forest.jwt.model.TokenModel;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -46,7 +46,7 @@ public class RedisTokenManager implements TokenManager {
|
||||
if (model == null) {
|
||||
return false;
|
||||
}
|
||||
String token = (String) redisTemplate.boundValueOps(model.getUsername()).get();
|
||||
String token = redisTemplate.boundValueOps(model.getUsername()).get();
|
||||
if (token == null || !token.equals(model.getToken())) {
|
||||
return false;
|
||||
}
|
||||
@ -54,7 +54,10 @@ public class RedisTokenManager implements TokenManager {
|
||||
redisTemplate.boundValueOps(model.getUsername()).expire(JwtConstants.TOKEN_EXPIRES_HOUR, TimeUnit.HOURS);
|
||||
StringBuilder key = new StringBuilder();
|
||||
key.append(JwtConstants.LAST_ONLINE).append(model.getUsername());
|
||||
String result = redisTemplate.boundValueOps(key.toString()).get();
|
||||
if (StringUtils.isBlank(result)) {
|
||||
redisTemplate.boundValueOps(key.toString()).set(LocalDateTime.now().toString(), JwtConstants.LAST_ONLINE_EXPIRES_MINUTE, TimeUnit.MINUTES);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,6 @@ import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CodeGenerator
|
||||
* @date 2018/05/29
|
||||
*/
|
||||
@ -109,6 +108,7 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
|
||||
if (user != null) {
|
||||
if (Utils.comparePwd(password, user.getPassword())) {
|
||||
userMapper.updateLastLoginTime(user.getIdUser());
|
||||
userMapper.updateLastOnlineTimeByEmail(user.getEmail());
|
||||
TokenUser tokenUser = new TokenUser();
|
||||
BeanCopierUtil.copy(user, tokenUser);
|
||||
tokenUser.setToken(tokenManager.createToken(account));
|
||||
|
Loading…
Reference in New Issue
Block a user