| | |
| | | using Microsoft.AspNetCore.Http; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using Microsoft.Extensions.Caching.Memory; |
| | | using Newtonsoft.Json; |
| | | using StackExchange.Profiling; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.Authorization; |
| | | using WIDESEAWCS_Core.BaseController; |
| | | using WIDESEAWCS_Core.CodeGenerator; |
| | | using WIDESEAWCS_Core.Const; |
| | | using WIDESEAWCS_Core.Extensions; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.HttpContextUser; |
| | | using WIDESEAWCS_Core.Utilities; |
| | |
| | | _httpContextAccessor = httpContextAccessor; |
| | | } |
| | | |
| | | [HttpPost, Route("swgLogin"), AllowAnonymous] |
| | | public dynamic SwgLogin([FromBody] SwaggerLoginRequest loginRequest) |
| | | { |
| | | if (loginRequest is null) |
| | | { |
| | | return new { result = false }; |
| | | } |
| | | |
| | | try |
| | | { |
| | | LoginInfo loginInfo = new LoginInfo |
| | | { |
| | | Password = loginRequest.pwd, |
| | | UserName = loginRequest.name |
| | | }; |
| | | var result = Service.Login(loginInfo); |
| | | if (result.Status) |
| | | { |
| | | HttpContext.SuccessSwagger(); |
| | | Dictionary<string, object>? dict = JsonConvert.DeserializeObject<Dictionary<string, object>>(result.Data.Serialize()); |
| | | if (dict != null) |
| | | { |
| | | HttpContext.SuccessSwaggerJwt((dict.ContainsKey("token") ? dict["token"].ToString() : "") ?? ""); |
| | | } |
| | | string str = HttpContext.GetSuccessSwaggerJwt(); |
| | | return new { result = true }; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | } |
| | | |
| | | return new { result = false }; |
| | | } |
| | | |
| | | [HttpPost, Route("login"), AllowAnonymous] |
| | | public IActionResult Login([FromBody] LoginInfo loginInfo) |
| | | { |
| | |
| | | [HttpPost, Route("modifyPwd")] |
| | | public IActionResult ModifyPwd(string oldPwd, string newPwd) |
| | | { |
| | | return Json( Service.ModifyPwd(oldPwd, newPwd)); |
| | | return Json(Service.ModifyPwd(oldPwd, newPwd)); |
| | | } |
| | | |
| | | [HttpGet, Route("getVierificationCode"), AllowAnonymous] |
| | |
| | | { |
| | | return WebResponseContent.Instance.OK(data: JwtHelper.SerializeJwt(code)); |
| | | } |
| | | [HttpPost, Route("replaceToken")] |
| | | public WebResponseContent ReplaceToken() |
| | | { |
| | | WebResponseContent responseContent = new WebResponseContent(); |
| | | try |
| | | { |
| | | string token = App.User.GetToken(); |
| | | if (string.IsNullOrEmpty(token)) |
| | | { |
| | | return responseContent = WebResponseContent.Instance.Error("token无效,请重新登录!"); |
| | | } |
| | | TokenModelJwt tokenModelJwt = new TokenModelJwt() |
| | | { |
| | | RoleId = App.User.RoleId, |
| | | TenantId = App.User.TenantId, |
| | | UserId = App.User.UserId, |
| | | UserName = App.User.UserName |
| | | }; |
| | | string newToken = JwtHelper.IssueJwt(tokenModelJwt); |
| | | return responseContent = WebResponseContent.Instance.OK(data: newToken); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return responseContent.Error(ex.Message); |
| | | } |
| | | |
| | | } |
| | | |
| | | [HttpPost, Route("CreateIRepository"), AllowAnonymous] |
| | | public WebResponseContent CreateIRepository(string tableName, string nameSpace) |
| | | { |
| | | CodeGenertors.CreateIRepository(tableName, nameSpace); |
| | | CodeGenertors.CreateRepository(tableName, nameSpace); |
| | | CodeGenertors.CreateIService(tableName, nameSpace); |
| | | CodeGenertors.CreateService(tableName, nameSpace); |
| | | CodeGenertors.CreateController(tableName, nameSpace); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | } |
| | | |
| | | public class SwaggerLoginRequest |
| | | { |
| | | public string name { get; set; } |
| | | public string pwd { get; set; } |
| | | } |
| | | } |