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]")]
|
2018-11-24 15:12:44 +08:00
|
|
|
|
[ApiController]
|
|
|
|
|
public class LoginController : ControllerBase
|
2018-06-07 00:45:47 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
[HttpPost]
|
2018-10-18 11:16:02 +08:00
|
|
|
|
public string Post([FromBody]JObject value)
|
2018-06-07 00:45:47 +08:00
|
|
|
|
{
|
2019-01-17 12:13:30 +08:00
|
|
|
|
string token = null;
|
2018-06-07 00:45:47 +08:00
|
|
|
|
dynamic user = value;
|
|
|
|
|
string userName = user.userName;
|
|
|
|
|
string password = user.password;
|
2018-10-24 17:57:31 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password) && UserHelper.Authenticate(userName, password))
|
2018-06-07 00:45:47 +08:00
|
|
|
|
{
|
2019-01-17 12:13:30 +08:00
|
|
|
|
token = BootstrapAdminJwtTokenHandler.CreateToken(userName);
|
2018-06-07 00:45:47 +08:00
|
|
|
|
}
|
2019-01-17 12:13:30 +08:00
|
|
|
|
return token;
|
2018-06-07 00:45:47 +08:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
[HttpOptions]
|
|
|
|
|
public string Options()
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|