com.github.rexsheng.springboot.faster.system.auth.adapter.AuthController Maven / Gradle / Ivy
The newest version!
package com.github.rexsheng.springboot.faster.system.auth.adapter;
import com.github.rexsheng.springboot.faster.common.domain.Result;
import com.github.rexsheng.springboot.faster.logging.RequestLog;
import com.github.rexsheng.springboot.faster.security.IgnorePermission;
import com.github.rexsheng.springboot.faster.system.auth.application.AuthService;
import com.github.rexsheng.springboot.faster.system.auth.application.dto.*;
import com.github.rexsheng.springboot.faster.system.auth.domain.SysUserDetail;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
@RestController
@Tag(name = "AuthController",description = "权限管理")
@RequestMapping("/sys/auth")
@ConditionalOnProperty(prefix = "app.module.management",name = "controller",havingValue = "true",matchIfMissing = true)
@ConditionalOnClass(Authentication.class)
public class AuthController {
@Resource
private AuthService authService;
@GetMapping("/me")
@PreAuthorize("@ss.denyApi()")
public Result getCurrentUser(Authentication authentication){
return Result.success(AuthUserResponse.of((SysUserDetail) authentication.getPrincipal()));
}
@PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).USER_OFFLINE)")
@PutMapping("/offline")
@RequestLog("下线用户")
public Result offlineUser(@RequestBody Long[] ids){
OfflineUserRequest request=new OfflineUserRequest();
request.setUserIds(Arrays.asList(ids));
authService.offline(request);
return Result.success();
}
@IgnorePermission
@PostMapping("/validateUserAccount")
public Result validateUserAccount(@RequestBody @Validated ValidateAccountRequest request){
return Result.success(authService.validateUserAccount(request));
}
@IgnorePermission
@PostMapping("/sendResetPasswordMail")
public Result sendResetPasswordMail(@RequestParam String uid){
authService.sendResetPasswordMail(uid);
return Result.success();
}
@IgnorePermission
@PostMapping("/kaptcha/valid/remote")
public Result validateUserRemoteKaptcha(@RequestBody @Validated ValidateUserRemoteKaptchaRequest request){
return Result.success(authService.validateUserRemoteKaptcha(request));
}
@IgnorePermission
@PostMapping("/findPassword")
@RequestLog("找回密码")
public Result findPassword(@RequestBody @Validated FindPasswordRequest request){
authService.findPassword(request);
return Result.success();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy