64 lines
1.9 KiB
C#
64 lines
1.9 KiB
C#
using Bootstrap.Admin.Query;
|
|
using Bootstrap.DataAccess;
|
|
using Bootstrap.Security;
|
|
using Longbow.Web;
|
|
using Longbow.Web.Mvc;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace Bootstrap.Admin.Controllers.Api
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class LoginController : ControllerBase
|
|
{
|
|
/// <summary>
|
|
/// 获得登录历史记录
|
|
/// </summary>
|
|
/// <param name="value"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public QueryData<LoginUser> Get([FromQuery]QueryLoginOption value) => value.RetrieveData();
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="onlineUserSvr"></param>
|
|
/// <param name="ipLocator"></param>
|
|
/// <param name="value"></param>
|
|
/// <returns></returns>
|
|
[AllowAnonymous]
|
|
[HttpPost]
|
|
public string Post([FromServices]IOnlineUsers onlineUserSvr, [FromServices]IIPLocatorProvider ipLocator, [FromBody]JObject value)
|
|
{
|
|
string token = null;
|
|
dynamic user = value;
|
|
string userName = user.userName;
|
|
string password = user.password;
|
|
if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password) && UserHelper.Authenticate(userName, password, loginUser => AccountController.CreateLoginUser(onlineUserSvr, ipLocator, HttpContext, loginUser)))
|
|
{
|
|
token = BootstrapAdminJwtTokenHandler.CreateToken(userName);
|
|
}
|
|
return token;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[AllowAnonymous]
|
|
[HttpOptions]
|
|
public string Options()
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|