更新框架,增加云库搜索模块
This commit is contained in:
1 parent
8526e5e0d2
commit
f2caec6083
192 files changed
+3626
-804
No files matched your search
@@ -0,0 +1,108 @@
|
||||
using Asp.Versioning;
|
||||
using MAX.Framework.Dtos;
|
||||
using MAX.Framework.Security;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace Store.Api.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]/[action]")]
|
||||
public class AuthController : ControllerBase
|
||||
{
|
||||
//private readonly IUserService _userService;
|
||||
private readonly ITokenService _tokenService;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly IOnlineUserStore _onlineUserStore;
|
||||
|
||||
public AuthController( ITokenService tokenService, ICurrentUser currentUser, IOnlineUserStore onlineUserStore)
|
||||
{
|
||||
//_userService = userService;
|
||||
_tokenService = tokenService;
|
||||
_currentUser = currentUser;
|
||||
_onlineUserStore = onlineUserStore;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登录:校验用户名/密码,签发 JWT(单点登录:同用户的新登录会使旧令牌失效)
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public async Task<ApiResult<object?>> Login([FromBody] LoginRequest request)
|
||||
{
|
||||
if (request is null || string.IsNullOrWhiteSpace(request.UserName) || string.IsNullOrWhiteSpace(request.Password))
|
||||
{
|
||||
return ApiResult.Fail("用户名或密码不能为空", 400);
|
||||
}
|
||||
|
||||
//UserDto? user = await _userService.LoginAsync(request.UserName, request.Password);
|
||||
//if (user is null)
|
||||
//{
|
||||
// return ApiResult.Error("用户名或密码错误", 401);
|
||||
//}
|
||||
|
||||
//var claims = new List<Claim>
|
||||
//{
|
||||
// new(JwtClaimTypes.UserName, user.UserName),
|
||||
// new(JwtClaimTypes.NickName, user.NickName),
|
||||
//};
|
||||
|
||||
//TokenResult token = _tokenService.CreateToken(claims);
|
||||
return ApiResult<object?>.Success(111);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 退出登录:销毁当前用户的服务端在线会话,令牌立即失效
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public ApiResult<object?> Logout()
|
||||
{
|
||||
if (_currentUser.UserName is string username)
|
||||
{
|
||||
_onlineUserStore.SignOut(username);
|
||||
}
|
||||
|
||||
return ApiResult<object?>.Success(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前登录用户信息(需携带 Bearer Token)
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public ApiResult<object?> Me()
|
||||
{
|
||||
return ApiResult<object?>.Success(new
|
||||
{
|
||||
UserName = _currentUser.UserName,
|
||||
NickName = _currentUser.NickName,
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在线人员列表(需携带 Bearer Token)
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public ApiResult<object?> OnlineUsers()
|
||||
{
|
||||
IReadOnlyList<OnlineUserInfo> users = _onlineUserStore.GetOnlineUsers();
|
||||
return ApiResult<object?>.Success(new
|
||||
{
|
||||
Count = users.Count,
|
||||
Users = users,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class LoginRequest
|
||||
{
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Store.Framework.Repositorys;
|
||||
using System.ComponentModel;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Store.Api.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[ApiVersionNeutral]
|
||||
[Route("wxxd_user/[action]")]
|
||||
public class UserController : ControllerBase
|
||||
{
|
||||
private readonly IUserRepository _userRepository;
|
||||
|
||||
public UserController(IUserRepository userRepository)
|
||||
{
|
||||
_userRepository = userRepository;
|
||||
}
|
||||
[HttpGet]
|
||||
public string GetUser()
|
||||
{
|
||||
return JsonSerializer.Serialize(_userRepository.Select.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Asp.Versioning;
|
||||
using MAX.Framework.Dtos;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Store.Api;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Store.Api.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Description("测试温度")]
|
||||
[ApiVersion("1.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
public class WeatherForecastController : ControllerBase
|
||||
{
|
||||
private static readonly string[] Summaries =
|
||||
[
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
];
|
||||
|
||||
[HttpGet(Name = "GetWeatherForecast")]
|
||||
public IEnumerable<WeatherForecast> Get()
|
||||
{
|
||||
IEnumerable<WeatherForecast> data = Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Asp.Versioning;
|
||||
using MAX.Framework.Dtos;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Store.Api;
|
||||
|
||||
namespace Store.Api.Controllers.v2
|
||||
{
|
||||
[ApiController]
|
||||
[ApiVersion("2.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
public class WeatherForecastController : ControllerBase
|
||||
{
|
||||
private static readonly string[] Summaries =
|
||||
[
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
];
|
||||
|
||||
[HttpGet(Name = "GetWeatherForecastV2")]
|
||||
public ApiResult<IEnumerable<WeatherForecastV2>> Get()
|
||||
{
|
||||
IEnumerable<WeatherForecastV2> data = Enumerable.Range(1, 10).Select(index => new WeatherForecastV2
|
||||
{
|
||||
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
FeelsLikeC = Random.Shared.Next(-20, 55),
|
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
return ApiResult<IEnumerable<WeatherForecastV2>>.Success(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user