using IMCS.CCS.Common;
using IMCS.CCS.Model;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System.Threading.Tasks;
namespace IMCS.CCS.Controllers
{
public class AuthorizationController : AppBaseController
{
private readonly IConfiguration _configuration;
public AuthorizationController(IConfiguration configuration)
{
_configuration = configuration;
}
///
/// 检查 口令
///
///
///
[HttpPost("check/{password}")]
public async Task CheckAsync(string password)
{
if (string.IsNullOrWhiteSpace(password))
{
return this.ResultWarn("请输入口令!");
}
var tokenKey = _configuration[AppConsts.TokenKeyName];
var tokenValue = _configuration[AppConsts.TokenValueName];
var jwtKeyName = _configuration[AppConsts.JwtKeyName];
var jwtSecurityKey = _configuration[AppConsts.JwtSecurityKey];
if (tokenValue != password)
{
return this.ResultWarn("口令错误!");
}
var token = JwtTokenUtil.CreateToken(tokenValue, jwtSecurityKey, jwtKeyName);
const string tokenType = "Bearer ";
return await Task.FromResult(this.ResultOk(new
{
tokenKey,
token = tokenType + token
}));
}
}
}