BootstrapAdmin/Bootstrap.Admin/Controllers/Api/LoginController.cs

50 lines
1.3 KiB
C#
Raw Normal View History

2018-10-19 23:09:52 +08:00
using Bootstrap.DataAccess;
using Bootstrap.Security;
2018-06-07 00:45:47 +08:00
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
2018-06-07 00:45:47 +08:00
{
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
[AllowAnonymous]
[HttpPost]
public string Post([FromBody]JObject value)
2018-06-07 00:45:47 +08:00
{
string token = null;
2018-06-07 00:45:47 +08:00
dynamic user = value;
string userName = user.userName;
string password = user.password;
if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password) && UserHelper.Authenticate(userName, password))
2018-06-07 00:45:47 +08:00
{
token = BootstrapAdminJwtTokenHandler.CreateToken(userName);
2018-06-07 00:45:47 +08:00
}
return token;
2018-06-07 00:45:47 +08:00
}
/// <summary>
///
/// </summary>
/// <returns></returns>
[AllowAnonymous]
[HttpOptions]
public string Options()
{
return null;
}
}
}