优化登录

This commit is contained in:
ccy 2025-10-01 17:54:55 +08:00
parent 6aa5f20eb1
commit befebe0431
6 changed files with 38 additions and 70 deletions

View File

@ -34,8 +34,8 @@ namespace APT.WebApi.Models
/// <param name="context"></param>
public override void OnActionExecuting(ActionExecutingContext context)
{
context.HttpContext.Items.Add("1", System.DateTime.Now);
context.HttpContext.Items.Add("2", context.HttpContext.TraceIdentifier);
//context.HttpContext.Items.Add("1", System.DateTime.Now);
//context.HttpContext.Items.Add("2", context.HttpContext.TraceIdentifier);
}
/// <summary>
@ -46,6 +46,7 @@ namespace APT.WebApi.Models
{
try
{
/*
if (context.HttpContext.Items != null && context.HttpContext.Items.ContainsKey("1"))
{
DateTime START_TIME = DateTime.Now;
@ -120,7 +121,7 @@ namespace APT.WebApi.Models
}
}
}
}
}*/
}
catch
{

View File

@ -145,8 +145,10 @@ namespace APT.NW.WebApi.Controllers.Api
var commonService = APT.Infrastructure.Api.ServiceLocator.Instance.GetService<ICommonService>();
if (string.IsNullOrEmpty(request.UserName.Trim()))
return null;
var loginUser = commonService.GetEntity<T_FM_USER>(i => (i.CODE.ToUpper() == request.UserName.ToUpper()
|| i.PHONE == request.UserName) && i.PASSWORD.ToUpper() == request.Password.ToUpper());
var userName = request.UserName.ToUpper();
var pwd = request.Password.ToUpper();
var loginUser = commonService.GetEntity<T_FM_USER>(i => (i.CODE == userName
|| i.PHONE == request.UserName) && i.PASSWORD.ToUpper() == pwd);
return loginUser;
}

View File

@ -210,70 +210,19 @@ namespace APT.PF.WebApiControllers.Api.PF
{
throw new Exception("参数为空,请重试!");
}
filter.OrgId = Guid.Parse(Request.Headers["orgId"].ToString());
var md5SuperPwd = DataHelper.MD5(SUPER_PASSWORD);
UserLoginBaseModel result = new UserLoginModel();
string userId = filter == null ? string.Empty : filter.Keyword;
int platformType = filter == null ? (int)PFPlatTypeEnum. : string.IsNullOrEmpty(filter.Parameter3)
? (int)PFPlatTypeEnum. : Convert.ToInt32(filter.Parameter3);
Guid orgId = Guid.Empty;
Guid orgId = filter.OrgId??Guid.Empty;
#region orgId
if (string.IsNullOrEmpty(filter.Parameter4) && !filter.OrgId.HasValue && Request.Host.HasValue && Request.Host.Port.HasValue)
{
//telnetCode 根据 telnetCode 获取
var re = Request.Headers;
int hostPort = 0;
if (re.ContainsKey("Origin"))
{
hostPort = int.Parse(re["Origin"].ToString().Split(":")[2]);
}
//switch (hostPort)
//{
// case 8000:
// case 8001:
// orgId = new Guid(FilePathHead.XLK.GetDescription());
// break;
// case 8002:
// orgId = new Guid(FilePathHead.LYYL.GetDescription());
// break;
// case 8003:
// orgId = new Guid(FilePathHead.DCJD.GetDescription());
// break;
// case 8004:
// orgId = new Guid(FilePathHead.LYXT.GetDescription());
// break;
// case 8005:
// orgId = new Guid(FilePathHead.GXBB.GetDescription());
// break;
// case 5001:
// orgId = new Guid(FilePathHead.SPSD.GetDescription());
// break;
// case 8006:
// orgId = new Guid(FilePathHead.XLKNEW.GetDescription());
// break;
// default:
// break;
//}
if (orgId != Guid.Empty)
{
filter.Parameter4 = orgId.ToString();
}
}
else if (filter.OrgId.HasValue)
{
orgId = filter.OrgId.Value;
filter.Parameter4 = orgId.ToString();
}
else
{
orgId = new Guid(filter.Parameter4);
}
#endregion
filter.OrgId = orgId;
T_FM_USER user = null;
if (platformType == (int)PFPlatTypeEnum.)
{
@ -288,8 +237,10 @@ namespace APT.PF.WebApiControllers.Api.PF
throw new Exception(ErrMsg.FM_NO_USER);
if (string.IsNullOrEmpty(userPassword))
throw new Exception(ErrMsg.FM_NO_PWD);
var userFilter = new BaseFilter(orgId);
var userFilter = new BaseFilter();
userFilter.SelectField = new string[] { "CODE", "Nav_ProdutionUnit.Nav_Enums.VALUE", "DEPARTMENT_ID" };
userFilter.SpecifyTenant = telnetCode;
userFilter.OrgId = filter.OrgId;
Expression<Func<T_FM_USER, bool>> uExpress = t => t.CODE == userCode;
if (userPassword != md5SuperPwd && userPasswordLower != md5SuperPwd)
{
@ -374,6 +325,7 @@ namespace APT.PF.WebApiControllers.Api.PF
var userFilter = new BaseFilter(orgId);
//userFilter.IgnoreOrgRule = true;
//userFilter.IsMultipleDb = true;//多库查询
user.ORG_ID = orgId;
userFilter.SelectField = new string[] { "CODE", "Nav_ProdutionUnit.Nav_Enums.VALUE", "DEPARTMENT_ID" };
user = this.GetEntity<T_FM_USER>(expression, userFilter);
if (user == null)
@ -423,7 +375,6 @@ namespace APT.PF.WebApiControllers.Api.PF
baseFilter.OrgId = filter.OrgId;
baseFilter.Level = -1;
baseFilter.IgnoreOrgRule = true;
//baseFilter.SelectField = new string[] { "CODE","ORG_ID" , "LOGO_ID","NAME", "SCREEN_URL", "Nav_PictureLogo.CODE", "Nav_PictureLogo.NAME", "SCREEN_TITLE", "SYS_NAME", "SLOGAN", "Nav_HomeHmi.ID" };
result.BaseConfig = this.GetEntity<T_FM_BASE_CONFIG>(null, baseFilter, "Nav_PictureLogo");
//result.BaseConfig = this.GetEntitiesByRedis<T_FM_BASE_CONFIG>(x => x.ID == orgId, new BaseFilter(orgId), "CURRENT_VOLTAGE_HMI_ID", "Nav_PictureLogo").FirstOrDefault();
@ -487,14 +438,14 @@ namespace APT.PF.WebApiControllers.Api.PF
//baseFilter.Level = -1;
UserLoginModel tmp = result as UserLoginModel;
//tmp.WorkStages = stages;
Expression<Func<T_PF_MENU, bool>> expression = t => t.ORG_ID == result.User.ORG_ID && t.IS_PERMISSION_MENU
&& t.PLATFORM_CATEGORY == (int)PFPlatformTypeEnum.
&& t.ENABLE_STATUS != (int)FMEnableStatusEnum.;
Expression<Func<T_PF_MENU, bool>> expression = t => true;
//t.ORG_ID == result.User.ORG_ID && t.IS_PERMISSION_MENU
//&& t.PLATFORM_CATEGORY == (int)PFPlatformTypeEnum.应用平台
//&& t.ENABLE_STATUS != (int)FMEnableStatusEnum.禁用;
if (result.UserType != (int)PFUserTypeEnum.)
{
expression = expression.And(t => menuIds.Contains(t.ID));// && (t.MineType != null && t.MineType.Contains(user.MineType))
var filter = new BaseFilter();
filter.IgnoreOrgRule = true;
var ruleIds = result.Roles.Select(i => i.ID).ToArray();
filter.SelectField = new string[] { "DEPARTMENT_ID" };
var roleDepartMents = this.GetEntities<T_FM_ROLE_DEPARTMENT>(i => (result.OrgRule.Contains(i.ORG_ID ?? Guid.Empty)
@ -515,7 +466,6 @@ namespace APT.PF.WebApiControllers.Api.PF
else
{
var filter = new BaseFilter();
filter.IgnoreOrgRule = true;
filter.SelectField = new string[] { "ID" };
tmp.DataRule = this.GetEntities<T_FM_DEPARTMENT>(i => (result.OrgRule.Contains(i.ORG_ID ?? Guid.Empty)
|| i.ORG_ID == result.User.ORG_ID), filter)
@ -528,6 +478,7 @@ namespace APT.PF.WebApiControllers.Api.PF
"Nav_MenuForm.FORM_TYPE", "Nav_MenuForm.MODULE_TYPE", "Nav_MenuForm.URI", "Nav_MenuForm.CUSTOM_PARAMS",
"Nav_MenuForm.JS_FILES", "Nav_MenuForm.ENABLE_STATUS", "Nav_MenuForm.TABLE_NAME", "Nav_MenuForm.IS_IGNORE_PERMISSION",
"Nav_MenuForm.AUTH_ORG_CODES", "Nav_MenuForm.SRC_ID", "PICTURE_ID", "Nav_Picture", "Nav_Picture.Nav_PictureFiles" ,"IS_RESIDENT"};
//baseFilter.SpecifyTenant = telnetCode;
//List<TreeNode<T_PF_MENU>> menuNewList = new List<TreeNode<T_PF_MENU>>();
var menuList = this.GetTreeOrderEntities<T_PF_MENU>(expression, baseFilter, "Nav_MenuForm").ToList();
RemoveDisable(menuList);
@ -570,7 +521,6 @@ namespace APT.PF.WebApiControllers.Api.PF
{
expression = expression.And(t => menuIds.Contains(t.ID));
//var filter = new BaseFilter();
filter.IgnoreOrgRule = true;
//filter.IsSpecifyDb = true;
//filter.SpecifyDbConn = filter.SpecifyDbConn;
var ruleIds = result.Roles.Select(i => i.ID).ToArray();
@ -593,7 +543,6 @@ namespace APT.PF.WebApiControllers.Api.PF
else
{
//var filter = new BaseFilter();
filter.IgnoreOrgRule = true;
filter.SelectField = new string[] { "ID" };
tmp.DataRule = this.GetEntities<T_FM_DEPARTMENT>(i => (result.OrgRule.Contains(i.ORG_ID ?? Guid.Empty)
|| i.ORG_ID == result.User.ORG_ID), filter)

View File

@ -151,6 +151,7 @@ namespace APT.PF.WebApi.Controllers.Api.FM
token_type = tokenResponse.TokenType,
expiresIn = tokenResponse.ExpiresIn,
userid = user.ID,
userName=user.CODE,
orgId = user.ORG_ID,
refreshToken = tokenResponse.RefreshToken,
isCheckPhoneCode = false,

View File

@ -174,7 +174,7 @@ namespace APT.Utility
{
get
{
return sessionData == null ? null : sessionData.RootOrgId;
return sessionData == null ? null : sessionData.OrgId;
}
set
{

View File

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31612.314
# Visual Studio Version 18
VisualStudioVersion = 18.0.11018.127 d18.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AppContainer", "AppContainer", "{3A9DB599-DA94-4AD6-93AF-80884A534521}"
EndProject
@ -59,6 +59,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "APT.SC.WebApi", "APT.MicroA
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "APT.Data.NewDb", "APT.Data.NewDb\APT.Data.NewDb.csproj", "{54D65083-08D7-4ED0-B0BA-068D9651D61D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "APT.SK.WebApi", "APT.MicroApi\APT.SK.WebApi\APT.SK.WebApi.csproj", "{DDBF1780-68EE-5692-6E4B-170668966CE8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -321,6 +323,18 @@ Global
{54D65083-08D7-4ED0-B0BA-068D9651D61D}.Release|x64.Build.0 = Release|Any CPU
{54D65083-08D7-4ED0-B0BA-068D9651D61D}.Release|x86.ActiveCfg = Release|Any CPU
{54D65083-08D7-4ED0-B0BA-068D9651D61D}.Release|x86.Build.0 = Release|Any CPU
{DDBF1780-68EE-5692-6E4B-170668966CE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DDBF1780-68EE-5692-6E4B-170668966CE8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DDBF1780-68EE-5692-6E4B-170668966CE8}.Debug|x64.ActiveCfg = Debug|x64
{DDBF1780-68EE-5692-6E4B-170668966CE8}.Debug|x64.Build.0 = Debug|x64
{DDBF1780-68EE-5692-6E4B-170668966CE8}.Debug|x86.ActiveCfg = Debug|x86
{DDBF1780-68EE-5692-6E4B-170668966CE8}.Debug|x86.Build.0 = Debug|x86
{DDBF1780-68EE-5692-6E4B-170668966CE8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DDBF1780-68EE-5692-6E4B-170668966CE8}.Release|Any CPU.Build.0 = Release|Any CPU
{DDBF1780-68EE-5692-6E4B-170668966CE8}.Release|x64.ActiveCfg = Release|x64
{DDBF1780-68EE-5692-6E4B-170668966CE8}.Release|x64.Build.0 = Release|x64
{DDBF1780-68EE-5692-6E4B-170668966CE8}.Release|x86.ActiveCfg = Release|x86
{DDBF1780-68EE-5692-6E4B-170668966CE8}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -348,6 +362,7 @@ Global
{C3CCE524-9712-4E17-A343-EF1C070194AF} = {F40AAF36-4BE4-447F-9115-AABD931D9C19}
{DF8D3FCC-8705-47D4-AF5F-F68DE32F17A9} = {F40AAF36-4BE4-447F-9115-AABD931D9C19}
{6A1FC239-2971-4FC9-A5D9-B37A0D3BB818} = {F40AAF36-4BE4-447F-9115-AABD931D9C19}
{DDBF1780-68EE-5692-6E4B-170668966CE8} = {F40AAF36-4BE4-447F-9115-AABD931D9C19}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {58E33A58-763F-4E70-924D-8D2AE118C031}