| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- 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<IActionResult> 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<Claim> claims = new List<Claim>();
- 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();
- //}
- }
- }
|