fix: normalize WPF login identities at legacy boundary
This commit is contained in:
@@ -76,7 +76,10 @@ namespace Lskj.Main.Hosting
|
|||||||
DataTable users = SystemInfo.Instance.DisplayUserCode
|
DataTable users = SystemInfo.Instance.DisplayUserCode
|
||||||
? MainImpl.GetEmployeeListNew()
|
? MainImpl.GetEmployeeListNew()
|
||||||
: MainImpl.GetEmployeeList();
|
: MainImpl.GetEmployeeList();
|
||||||
return users ?? new DataTable("Users");
|
return NormalizeUsersForLogin(
|
||||||
|
users ?? new DataTable("Users"),
|
||||||
|
SystemInfo.Instance.LoginUsername,
|
||||||
|
SystemInfo.Instance.DisplayUserCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataTable SelectLedger(string ledgerName)
|
public DataTable SelectLedger(string ledgerName)
|
||||||
@@ -197,8 +200,7 @@ namespace Lskj.Main.Hosting
|
|||||||
ERPInfo.Instance.LoginResult = false;
|
ERPInfo.Instance.LoginResult = false;
|
||||||
if (string.IsNullOrWhiteSpace(loginName))
|
if (string.IsNullOrWhiteSpace(loginName))
|
||||||
return ResourceKeys.UserNameNotNull;
|
return ResourceKeys.UserNameNotNull;
|
||||||
if (password == null)
|
password = NormalizePassword(password);
|
||||||
password = string.Empty;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -420,13 +422,77 @@ namespace Lskj.Main.Hosting
|
|||||||
return selected == null ? string.Empty : Value(selected, "ShowName");
|
return selected == null ? string.Empty : Value(selected, "ShowName");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static DataTable NormalizeUsersForLogin(
|
||||||
|
DataTable users,
|
||||||
|
string configuredLoginColumn,
|
||||||
|
bool displayUserCode)
|
||||||
|
{
|
||||||
|
DataTable normalized = new DataTable("Users");
|
||||||
|
normalized.Columns.Add("UserId", typeof(string));
|
||||||
|
normalized.Columns.Add("LoginName", typeof(string));
|
||||||
|
normalized.Columns.Add("DisplayName", typeof(string));
|
||||||
|
|
||||||
|
if (users == null)
|
||||||
|
return normalized;
|
||||||
|
|
||||||
|
string loginColumn = ResolveLoginColumn(
|
||||||
|
users,
|
||||||
|
configuredLoginColumn);
|
||||||
|
foreach (DataRow row in users.Rows)
|
||||||
|
{
|
||||||
|
string loginName = Value(row, loginColumn).Trim();
|
||||||
|
string userCode = Value(row, "UserCode").Trim();
|
||||||
|
if (string.IsNullOrWhiteSpace(loginName))
|
||||||
|
loginName = userCode;
|
||||||
|
if (string.IsNullOrWhiteSpace(loginName))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
string displayName = loginName;
|
||||||
|
if (displayUserCode &&
|
||||||
|
!string.IsNullOrWhiteSpace(userCode) &&
|
||||||
|
!string.Equals(
|
||||||
|
loginName,
|
||||||
|
userCode,
|
||||||
|
StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
displayName = loginName + "(" + userCode + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
normalized.Rows.Add(
|
||||||
|
Value(row, "UserId"),
|
||||||
|
loginName,
|
||||||
|
displayName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string NormalizePassword(string password)
|
||||||
|
{
|
||||||
|
return (password ?? string.Empty).Trim();
|
||||||
|
}
|
||||||
|
|
||||||
private static string ResolveDisplayColumn(DataTable users)
|
private static string ResolveDisplayColumn(DataTable users)
|
||||||
{
|
{
|
||||||
string configured = SystemInfo.Instance.LoginUsername;
|
return ResolveLoginColumn(
|
||||||
return !string.IsNullOrWhiteSpace(configured) &&
|
users,
|
||||||
users.Columns.Contains(configured)
|
SystemInfo.Instance.LoginUsername);
|
||||||
? configured
|
}
|
||||||
: "UserName";
|
|
||||||
|
private static string ResolveLoginColumn(
|
||||||
|
DataTable users,
|
||||||
|
string configuredLoginColumn)
|
||||||
|
{
|
||||||
|
if (users != null &&
|
||||||
|
!string.IsNullOrWhiteSpace(configuredLoginColumn) &&
|
||||||
|
users.Columns.Contains(configuredLoginColumn))
|
||||||
|
{
|
||||||
|
return configuredLoginColumn;
|
||||||
|
}
|
||||||
|
|
||||||
|
return users != null && users.Columns.Contains("UserName")
|
||||||
|
? "UserName"
|
||||||
|
: "UserCode";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string Value(DataRow row, string columnName)
|
private static string Value(DataRow row, string columnName)
|
||||||
|
|||||||
Reference in New Issue
Block a user