dengjunjie
2025-03-12 f43b7df8400f4fcffc9f19dca0888d61e2b33d5f
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/System/Sys_UserController.cs
@@ -1,5 +1,4 @@

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
@@ -7,11 +6,13 @@
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_IServices;
using WIDESEA_ISystemService;
using WIDESEA_Model;
using WIDESEA_Model.Models;
@@ -22,17 +23,48 @@
    public class Sys_UserController : ApiBaseController<ISys_UserService, Sys_User>
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly ICacheService _cacheService;
        public Sys_UserController(ISys_UserService userService, IHttpContextAccessor httpContextAccessor) : base(userService)
        public Sys_UserController(ISys_UserService userService, IHttpContextAccessor httpContextAccessor, ICacheService cacheService) : base(userService)
        {
            _httpContextAccessor = httpContextAccessor;
            _cacheService = cacheService;
        }
        /// <summary>
        /// ç”¨æˆ·ç™»é™†
        /// </summary>
        /// <param name="loginInfo"></param>
        /// <returns></returns>
        [HttpPost, Route("login"), AllowAnonymous]
        public IActionResult Login([FromBody] LoginInfo loginInfo)
        {
            return Json(Service.Login(loginInfo));
        }
        [HttpPost, Route("swgLogin"), AllowAnonymous]
        public dynamic SwgLogin([FromBody] SwaggerLoginRequest loginRequest)
        {
            if (loginRequest is null)
            {
                return new { result = false };
            }
            try
            {
                if (loginRequest.name == "admin" && loginRequest.pwd == $"admin!{DateTime.Now.ToString("yyyyMMdd")}")
                {
                    HttpContext.SuccessSwagger();
                    return new { result = true };
                }
            }
            catch (Exception ex)
            {
            }
            return new { result = false };
        }
        [HttpPost, Route("getCurrentUserInfo")]
        public WebResponseContent GetCurrentUser()
        {
@@ -40,9 +72,9 @@
        }
        [HttpPost, Route("modifyPwd")]
        public IActionResult ModifyPwd(string oldPwd, string newPwd)
        public IActionResult ModifyPwd(string oldPwd, string newPwd, string userName)
        {
            return Json( Service.ModifyPwd(oldPwd, newPwd));
            return Json(Service.ModifyPwd(oldPwd, newPwd, userName));
        }
        [HttpGet, Route("getVierificationCode"), AllowAnonymous]
@@ -63,5 +95,38 @@
        {
            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);
                _cacheService.AddOrUpdate(tokenModelJwt.UserId.ToString(), newToken);
                return responseContent = WebResponseContent.Instance.OK(data: newToken);
            }
            catch (Exception ex)
            {
                return responseContent.Error(ex.Message);
            }
        }
        public class SwaggerLoginRequest
        {
            public string name { get; set; }
            public string pwd { get; set; }
        }
    }
}