Skip to content

Commit

Permalink
fix: 访问次数
Browse files Browse the repository at this point in the history
  • Loading branch information
sayHello committed Mar 20, 2024
1 parent 603963c commit 68e70d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 33 deletions.
17 changes: 6 additions & 11 deletions src/main/java/com/coco/boot/service/impl/CoCoPilotServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,18 @@ public ResponseEntity<String> callback(String code, String state) {
JSONObject userInfo = responseEntity.getBody();
assert userInfo != null;
String userId = userInfo.getString("id");
//登陆次数
RAtomicLong getTokenNum = redissonClient.getAtomicLong(RC_GET_TOKEN_NUM + userId);
long l = getTokenNum.incrementAndGet();
if (l > rcConfig.getGetTokenNum()) {
return new ResponseEntity<>("You Can Try again tomorrow", HttpStatus.UNAUTHORIZED);
}

//检查是否禁止访问
RBucket<Boolean> ban = redissonClient.getBucket(RC_BAN + userId);
if (ban.isExists()) {
if (redissonClient.getBucket(RC_BAN + userId).isExists()) {
return new ResponseEntity<>("You have been banned", HttpStatus.UNAUTHORIZED);
}
RBucket<Boolean> tempBan = redissonClient.getBucket(RC_TEMPORARY_BAN + userId);
if (tempBan.isExists()) {
if (redissonClient.getBucket(RC_TEMPORARY_BAN + userId).isExists()) {
return new ResponseEntity<>("You have been marked, please try again in a few hours", HttpStatus.UNAUTHORIZED);
}

//登陆次数
if (redissonClient.getAtomicLong(RC_GET_TOKEN_NUM + userId).incrementAndGet() > rcConfig.getGetTokenNum()) {
return new ResponseEntity<>("You Can Try again tomorrow", HttpStatus.UNAUTHORIZED);
}

// 检测用户信息 0级用户直接ban
int trustLevel = userInfo.getIntValue("trust_level");
Expand Down
22 changes: 0 additions & 22 deletions src/main/resources/redisson-config.yml

This file was deleted.

0 comments on commit 68e70d7

Please sign in to comment.