wanshenmean
3 天以前 4b483d9d06bead231b88ca212fd799196668a057
Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/System/Sys_UserController.cs
@@ -1,17 +1,12 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using Newtonsoft.Json;
using StackExchange.Profiling;
using WIDESEA_Core;
using WIDESEA_Core.Authorization;
using WIDESEA_Core.BaseController;
using WIDESEA_Core.Caches;
using WIDESEA_Core.Const;
using WIDESEA_Core.Extensions;
using WIDESEA_Core.Helper;
using WIDESEA_Core.HttpContextUser;
using WIDESEA_Core.Utilities;
using WIDESEA_ISystemService;
using WIDESEA_Model;
@@ -41,6 +36,11 @@
            return Json(Service.Login(loginInfo));
        }
        /// <summary>
        /// Swagger 登录接口
        /// </summary>
        /// <param name="loginRequest">登录请求</param>
        /// <returns>登录结果</returns>
        [HttpPost, Route("swgLogin"), AllowAnonymous]
        public dynamic SwgLogin([FromBody] SwaggerLoginRequest loginRequest)
        {
@@ -71,7 +71,8 @@
            }
            catch (Exception ex)
            {
                // 记录异常日志
                return new { result = false, message = ex.Message };
            }
            return new { result = false };
@@ -89,11 +90,17 @@
            return Json(Service.ModifyPwd(oldPwd, newPwd));
        }
        /// <summary>
        /// 获取验证码
        /// 注意:当前版本使用固定验证码 "1234" 用于测试
        /// </summary>
        /// <returns>验证码图片和唯一标识</returns>
        [HttpGet, Route("getVierificationCode"), AllowAnonymous]
        public IActionResult GetVierificationCode()
        {
            //var html = MiniProfiler.Current.RenderIncludes(_httpContextAccessor.HttpContext);
            string code = "1234" /*VierificationCode.RandomText()*/;
            // TODO: 生产环境应启用真实验证码生成
            // var html = MiniProfiler.Current.RenderIncludes(_httpContextAccessor.HttpContext);
            string code = "1234"; // 测试用固定验证码,生产环境应使用 VierificationCode.RandomText()
            var data = new
            {
                img = VierificationCode.CreateBase64Imgage(code),
@@ -102,11 +109,17 @@
            return Json(data);
        }
        [HttpGet, Route("SerializeJwt"), AllowAnonymous]
        public WebResponseContent SerializeJwt(string code)
        {
            return WebResponseContent.Instance.OK(data: JwtHelper.SerializeJwt(code));
        }
        /// <summary>
        /// 替换Token(刷新令牌)
        /// </summary>
        /// <returns>新的Token</returns>
        [HttpPost, Route("replaceToken")]
        public WebResponseContent ReplaceToken()
        {
@@ -116,7 +129,7 @@
                string token = App.User.GetToken();
                if (string.IsNullOrEmpty(token))
                {
                    return responseContent = WebResponseContent.Instance.Error("token无效,请重新登录!");
                    return responseContent.Error("Token无效,请重新登录!");
                }
                TokenModelJwt tokenModelJwt = new TokenModelJwt()
                {
@@ -128,24 +141,24 @@
                string newToken = JwtHelper.IssueJwt(tokenModelJwt);
                App.User.UpdateToke(newToken, App.User.UserId);
                return responseContent = WebResponseContent.Instance.OK(data: newToken);
                return responseContent.OK(data: newToken);
            }
            catch (Exception ex)
            {
                return responseContent.Error(ex.Message);
            }
        }
        /// <summary>
        /// 更新密码
        /// </summary>
        /// <param name="password">密码</param>
        /// <param name="userName">用户名</param>
        /// <returns></returns>
        [HttpPost,Route("ModifyUserPwd")]
        [HttpPost, Route("ModifyUserPwd")]
        public WebResponseContent ModifyUserPwd(string password, string userName)
        {
            return Service.ModifyUserPwd(password,userName);
            return Service.ModifyUserPwd(password, userName);
        }
    }
@@ -154,4 +167,4 @@
        public string name { get; set; }
        public string pwd { get; set; }
    }
}
}