using Business.Sqe; using Business.StructuredDB; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Security.Claims; using System.Text; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.AspNetCore.Mvc; namespace Business.Controllers { [RemoteService] [Area("Sqe")] //[AuthAttribute] [Route("api/Token")] //[ApiController] public class TokenController : AbpController { public IJwtService _jwtService { set; get; } private IConfiguration _configuration; public TokenController(IJwtService jwtService, IConfiguration configuration) { _jwtService = jwtService; _configuration = configuration; } //[AllowAnonymous] [HttpGet] [Route("token")] //public async Task GetToken() public String GetToken(String userid, String password) { ResultCode code = ResultCode.Fail, subCode = ResultCode.Fail; string subMsg = ""; string data = ""; try { JwtOptions jwtOptions = new JwtOptions(); jwtOptions.ExpireSeconds = Convert.ToInt32(_configuration["JWT:ExpireSeconds"]); jwtOptions.Issuer = _configuration["JWT:Issuer"]; jwtOptions.Audience = _configuration["JWT:Audience"]; jwtOptions.Key = _configuration["JWT:Key"]; String Userid = _configuration["jwtAuthorization:userid"]; String Password = _configuration["jwtAuthorization:password"]; if (Userid.CompareTo(userid) != 0 || Password.CompareTo(password) != 0) { data = "userid or password is wrong!"; } else { List claims = new List(); claims.Add(new Claim(ClaimTypes.Name, userid)); data = _jwtService.BuildToken(claims, jwtOptions); if (!string.IsNullOrEmpty(data)) { code = ResultCode.Success; subCode = ResultCode.Success; } } } catch (Exception ex) { subMsg = ex.Message; code = ResultCode.Fail; subCode = ResultCode.Fail; } ResultViewModel result = ResultHelper.CreateResult(code, data, subCode, subMsg); return JsonConvert.SerializeObject(result); } //[HttpGet] //[Route("tokenCheck")] //public String CheckToken(string token) //{ // ResultCode code = ResultCode.Fail, subCode = ResultCode.Fail; // string subMsg = ""; // string data = ""; // try // { // JwtOptions jwtOptions = new JwtOptions(); // jwtOptions.ExpireSeconds = Convert.ToInt32(_configuration["JWT:ExpireSeconds"]); // jwtOptions.Issuer = _configuration["JWT:Issuer"]; // jwtOptions.Audience = _configuration["JWT:Audience"]; // jwtOptions.Key = _configuration["JWT:Key"]; // data = _jwtService.ValidateToken(token, jwtOptions); // if (!string.IsNullOrEmpty(data)) // { // code = ResultCode.Success; // subCode = ResultCode.Success; // } // } // catch (Exception ex) // { // subMsg = ex.Message; // code = ResultCode.Fail; // subCode = ResultCode.Fail; // } // ResultViewModel result = ResultHelper.CreateResult(code, data, subCode, subMsg); // return result.ToString(); //} } }