123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- 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;
- }
- /// <summary>
- /// 检查 口令
- /// </summary>
- /// <param name="password"></param>
- /// <returns></returns>
- [HttpPost("check/{password}")]
- public async Task<ApiResult> 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
- }));
- }
- }
- }
|