bag
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Yh.Platform.Abstractions;
|
||||
using Yh.Platform.Auth;
|
||||
using Yh.Platform.OpenApi;
|
||||
using YhCore.Common;
|
||||
|
||||
namespace YhCore.WebApi.Controllers.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户基础接口(对应 Java 版 controller/api/UserController,路由 /api/base/)。
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route(ApiRoutes.ApiPath + "/base")]
|
||||
public class UserController : ControllerBase
|
||||
{
|
||||
private readonly IOpenApiUserClient _openApiUserClient;
|
||||
|
||||
public UserController(IOpenApiUserClient openApiUserClient)
|
||||
{
|
||||
_openApiUserClient = openApiUserClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前用户可见的应用模块(对应 Java GET /api/base/getUserMod,
|
||||
/// 内部调用 YschBaseOpenApi.getUserModule)。
|
||||
/// </summary>
|
||||
[HttpGet("getUserMod")]
|
||||
public async Task<List<BoaModule>> GetUserMod()
|
||||
{
|
||||
var boa = BoaUserContext.Get();
|
||||
return await _openApiUserClient.GetUserModuleAsync(boa?.Id ?? 0, boa?.School?.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前登录用户信息(对应 Java GET /api/base/getUserInfo,
|
||||
/// Java 版直接返回认证切面注入的 authUserWithDept)。
|
||||
/// </summary>
|
||||
[HttpGet("getUserInfo")]
|
||||
public BoaUser GetUserInfo()
|
||||
{
|
||||
return BoaUserContext.Get();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登出(对应 Java GET /api/base/logout:session.invalidate())。
|
||||
/// </summary>
|
||||
[HttpGet("logout")]
|
||||
public async Task<IActionResult> Logout()
|
||||
{
|
||||
// 清除本地 Cookie 登录态
|
||||
await HttpContext.SignOutAsync(YhAuthDefaults.CookieScheme);
|
||||
|
||||
if (HttpContext.Features.Get<ISessionFeature>() != null)
|
||||
{
|
||||
HttpContext.Session.Clear();
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user