|
@@ -0,0 +1,98 @@
|
|
|
+package pay.platform.api.system.controller;
|
|
|
+
|
|
|
+import cn.bzvs.otp.OtpAuthUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import jakarta.servlet.http.HttpServletRequest;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import pay.platform.api.system.model.vo.PayAgentVO;
|
|
|
+import pay.platform.api.system.model.vo.RestPasswdVO;
|
|
|
+import pay.platform.api.system.servcie.PayMerchantService;
|
|
|
+import pay.platform.core.common.Result;
|
|
|
+import pay.platform.core.security.model.UserInfo;
|
|
|
+import pay.platform.core.security.util.SecurityUtil;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 用户管理
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/sys/user")
|
|
|
+@Tag(name = "系统:用户管理")
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class PayAgentController {
|
|
|
+
|
|
|
+ private final PayMerchantService sysUserService;
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping("/check/username")
|
|
|
+ @Operation(summary = "检查用户名是否存在")
|
|
|
+ public Result<Boolean> checkUsername(HttpServletRequest request, @RequestParam String username) {
|
|
|
+ return sysUserService.hashUsername(username);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @PutMapping("/update/{id}")
|
|
|
+ @Operation(summary = "修改")
|
|
|
+ @PreAuthorize("@permission.hashPermission('user:update')")
|
|
|
+ public Result<PayAgentVO> update(HttpServletRequest request, @PathVariable String id,
|
|
|
+ @Validated @RequestBody PayAgentVO userVO) {
|
|
|
+
|
|
|
+ userVO.setUpdateTime(LocalDateTime.now());
|
|
|
+ userVO.setUpdateUser(SecurityUtil.getCurrentUsername());
|
|
|
+ return sysUserService.updateById(id, userVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PutMapping("/reset/passwd/{username}")
|
|
|
+ @Operation(summary = "重置密码")
|
|
|
+ @PreAuthorize("@permission.hashPermission('user:reset:passwd')")
|
|
|
+ public Result<String> resetPasswd(HttpServletRequest request, @PathVariable(value = "username") String username,
|
|
|
+ @Validated @RequestBody RestPasswdVO vo) {
|
|
|
+ if (StrUtil.isBlank(vo.getNewPassword())) {
|
|
|
+ return Result.NG("新密码不能为空");
|
|
|
+ }
|
|
|
+ if (!vo.getNewPassword().equals(vo.getConfirmPassword())) {
|
|
|
+ return Result.NG("两次密码不一致");
|
|
|
+ }
|
|
|
+ return sysUserService.resetPassword(username, vo.getConfirmPassword());
|
|
|
+ }
|
|
|
+
|
|
|
+ @PutMapping("/change/passwd/{username}")
|
|
|
+ @Operation(summary = "修改密码")
|
|
|
+ public Result<String> changePasswd(HttpServletRequest request,
|
|
|
+ @PathVariable("username") String username, @Validated @RequestBody RestPasswdVO vo) {
|
|
|
+ if (StrUtil.isBlank(vo.getNewPassword())) {
|
|
|
+ return Result.NG("新密码不能为空");
|
|
|
+ }
|
|
|
+ if (!vo.getNewPassword().equals(vo.getConfirmPassword())) {
|
|
|
+ return Result.NG("两次密码不一致");
|
|
|
+ }
|
|
|
+ if (vo.getOldPassword().equals(vo.getNewPassword())) {
|
|
|
+ return Result.NG("新密码不能与旧密码相同");
|
|
|
+ }
|
|
|
+ return sysUserService.changePasswd(username, vo.getOldPassword(), vo.getNewPassword());
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/get/google/qrcode")
|
|
|
+ @Operation(summary = "获取谷歌二维码")
|
|
|
+ public Result<String> getGoogleQrcode() {
|
|
|
+ UserInfo userInfo = SecurityUtil.getCurrentUser();
|
|
|
+ String otp = sysUserService.createGoogleOtp(userInfo.getUserid());
|
|
|
+ OtpAuthUtil.getOtpAuthUrl("Game-System", otp);
|
|
|
+ return Result.OK(otp);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @PostMapping("/check/google/otp")
|
|
|
+ @Operation(summary = "校验谷歌验证码")
|
|
|
+ public Result<Boolean> googleOtpCheck(String code) {
|
|
|
+ UserInfo userInfo = SecurityUtil.getCurrentUser();
|
|
|
+ boolean status = sysUserService.checkGoogleOtp(userInfo.getUserid(), code);
|
|
|
+ return Result.OK(status);
|
|
|
+ }
|
|
|
+}
|