Skip to content

Commit 0f7cf0c

Browse files
author
Ansj
committed
fix time
1 parent 5e3b2ea commit 0f7cf0c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/main/java/org/nlpcn/jcoder/job/MasterCleanTokenJob.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void run() {
6262
Map<String, Token> stringTokenMap = tokenCache.toMap();
6363

6464
for (Map.Entry<String, Token> entry : stringTokenMap.entrySet()) {
65-
if (entry.getValue().getExpirationTime().getTime() < System.currentTimeMillis() + 600000) { //过期10分钟的清除。防止服务器时间不太同步
65+
if (entry.getValue().getExpirationTime().getTime() < System.currentTimeMillis() - 600000) { //过期10分钟的清除。防止服务器时间不太同步
6666
tokenCache.remove(entry.getKey());
6767
}
6868
}

src/main/java/org/nlpcn/jcoder/service/TokenService.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,24 @@ public static String regToken(User user, String key) {
8080
return token.getToken();
8181
}
8282

83+
84+
/**
85+
* regeidt a token by user
86+
*
87+
* @param key ,用户自定义自己的token,用户自己保持不重复
88+
*/
89+
public static String regToken(User user, String key, long expiration) {
90+
LOG.info(user.getName() + " to create a key");
91+
Token token = new Token();
92+
token.setExpiration(expiration);
93+
token.setToken(key);
94+
token.setCreateTime(new Date());
95+
token.setExpirationTime(new Date(System.currentTimeMillis() + token.getExpiration()));
96+
token.setUser(user);
97+
space().getTokenCache().put(token.getToken(), token);
98+
return token.getToken();
99+
}
100+
83101
/**
84102
* login out by token
85103
*/

0 commit comments

Comments
 (0)