-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cubewhy
committed
Oct 3, 2024
1 parent
f7c32a0
commit bfa2156
Showing
5 changed files
with
124 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/fuck/manthe/nmsl/controller/admin/ColdDownAdminController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package fuck.manthe.nmsl.controller.admin; | ||
|
||
import fuck.manthe.nmsl.entity.RestBean; | ||
import fuck.manthe.nmsl.utils.Const; | ||
import jakarta.annotation.Resource; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Log4j2 | ||
@RestController | ||
@RequestMapping("admin/colddown") | ||
public class ColdDownAdminController { | ||
@Resource | ||
RedisTemplate<String, Long> redisTemplate; | ||
|
||
@PostMapping("reset") | ||
public ResponseEntity<RestBean<String>> reset() { | ||
log.info("Global inject cold down was reset."); | ||
// todo migrate to VapeAccountService | ||
redisTemplate.opsForValue().set(Const.COLD_DOWN, System.currentTimeMillis()); | ||
return ResponseEntity.ok(RestBean.success("Reset CD.")); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
src/main/java/fuck/manthe/nmsl/controller/admin/UserManageController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package fuck.manthe.nmsl.controller.admin; | ||
|
||
import cn.hutool.crypto.SecureUtil; | ||
import fuck.manthe.nmsl.entity.CrackedUser; | ||
import fuck.manthe.nmsl.entity.RestBean; | ||
import fuck.manthe.nmsl.entity.dto.CrackedUserDTO; | ||
import fuck.manthe.nmsl.service.AnalysisService; | ||
import fuck.manthe.nmsl.service.CrackedUserService; | ||
import jakarta.annotation.Resource; | ||
import jakarta.transaction.Transactional; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@Log4j2 | ||
@RestController | ||
@RequestMapping("/admin/user") | ||
public class UserManageController { | ||
@Resource | ||
CrackedUserService crackedUserService; | ||
|
||
@Resource | ||
AnalysisService analysisService; | ||
|
||
@GetMapping("list") | ||
public List<CrackedUserDTO> listUsers() { | ||
return crackedUserService.list().stream().map((user) -> CrackedUserDTO.builder() | ||
.id(user.getId()) | ||
.username(user.getUsername()) | ||
.expire(user.getExpire()) | ||
.totalLaunch(analysisService.getTotalLaunch(user.getUsername())) | ||
.lastLaunch(analysisService.getLastLaunch(user.getUsername())) | ||
.build()).toList(); | ||
} | ||
|
||
@PostMapping("add") | ||
public ResponseEntity<RestBean<String>> addUser(@RequestParam String username, @RequestParam String password, @RequestParam int day) { | ||
long expire = -1L; | ||
log.info("User {} has added by an admin", username); | ||
if (day != -1) { | ||
expire = System.currentTimeMillis() + (long) day * 24 * 60 * 60 * 1000; | ||
} | ||
if (crackedUserService.addUser(CrackedUser.builder().password(SecureUtil.sha1(password)).username(username).expire(expire).build())) { | ||
return ResponseEntity.ok(RestBean.success("OK")); | ||
} | ||
return new ResponseEntity<>(RestBean.failure(409, "Conflict"), HttpStatus.CONFLICT); | ||
} | ||
|
||
|
||
@PostMapping("renew/{username}") | ||
public ResponseEntity<RestBean<String>> renew(@PathVariable String username, @RequestParam int day) { | ||
log.info("An admin renewed the expire date of user {} ({}d)", username, day); | ||
if (crackedUserService.renewUser(username, day)) { | ||
return ResponseEntity.ok(RestBean.success("OK")); | ||
} | ||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST); | ||
} | ||
|
||
@DeleteMapping("remove/{username}") | ||
public RestBean<Object> removeUser(@PathVariable String username) { | ||
log.info("An admin removed a user with name {}", username); | ||
crackedUserService.removeUser(username); | ||
return RestBean.success(); | ||
} | ||
|
||
@PostMapping("password/{username}/reset") | ||
public ResponseEntity<RestBean<String>> resetPassword(@PathVariable String username, @RequestParam String password) { | ||
log.info("An admin reset the password of user {}", username); | ||
if (crackedUserService.resetPassword(username, password)) { | ||
return ResponseEntity.ok(RestBean.success()); | ||
} | ||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST); | ||
} | ||
|
||
@DeleteMapping("removeExpired") | ||
@Transactional | ||
public RestBean<String> removeExpired() { | ||
crackedUserService.removeExpired(); | ||
return RestBean.success("Success"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters