AuthController.java
2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.youjia.system.controller;
import com.youjia.common.core.Result;
import com.youjia.framework.security.AuthIgnore;
import com.youjia.system.dto.LoginDTO;
import com.youjia.system.service.AuthService;
import com.youjia.system.vo.LoginVO;
import com.youjia.system.vo.UserInfoVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 统一登录 / 会话(P1 登录页)。全部接口仅使用 GET / POST 两种请求方式。
*
* <p>登录成功后前端需保存令牌,并在后续请求的 {@code Authorization: Bearer {token}} 头中携带;
* 服务端会话存 Redis,支持多端登录、踢下线与权限缓存精确失效。</p>
*/
@Tag(name = "统一登录")
@RestController
@RequestMapping("/system/auth")
@RequiredArgsConstructor
public class AuthController {
private final AuthService authService;
@AuthIgnore
@Operation(summary = "账号密码登录")
@PostMapping("/login")
public Result<LoginVO> login(@Valid @RequestBody LoginDTO dto) {
return Result.success("登录成功", authService.login(dto));
}
@Operation(summary = "退出登录(注销当前令牌)")
@PostMapping("/logout")
public Result<Void> logout() {
authService.logout();
return Result.success();
}
@Operation(summary = "当前登录用户信息(角色 + 权限码 + 数据域)")
@GetMapping("/info")
public Result<UserInfoVO> info() {
return Result.success(authService.currentUserInfo());
}
@Operation(summary = "刷新当前用户的权限码缓存(权限调整后可用)")
@PostMapping("/perm/refresh")
public Result<Integer> refreshPerm() {
return Result.success(authService.refreshPermCache());
}
}