🌚防止pwdLastSet为null时报错

This commit is contained in:
KaneLeung 2024-12-13 15:51:55 +08:00
parent 048fca377c
commit 732a49c7fe

View File

@ -266,15 +266,15 @@ public class SysLdapService : IDynamicApiController, ITransient
{ {
var userLdap = new SysUserLdap var userLdap = new SysUserLdap
{ {
Account = !attrs.ContainsKey(bindAttrAccount) ? null : attrs.GetAttribute(bindAttrAccount)?.StringValue, Account = attrs.ContainsKey(bindAttrAccount) ? attrs.GetAttribute(bindAttrAccount)?.StringValue : null,
EmployeeId = !attrs.ContainsKey(bindAttrEmployeeId) ? null : attrs.GetAttribute(bindAttrEmployeeId)?.StringValue, EmployeeId = attrs.ContainsKey(bindAttrEmployeeId) ? attrs.GetAttribute(bindAttrEmployeeId)?.StringValue : null,
DeptCode = deptCode, DeptCode = deptCode,
UserName = !attrs.ContainsKey("name") ? null : attrs.GetAttribute("name")?.StringValue, UserName = attrs.ContainsKey("name") ? attrs.GetAttribute("name")?.StringValue : null,
Mail = !attrs.ContainsKey("mail") ? null : attrs.GetAttribute("mail")?.StringValue Mail = attrs.ContainsKey("mail") ? attrs.GetAttribute("mail")?.StringValue : null
}; };
var pwdLastSet = !attrs.ContainsKey("pwdLastSet") ? null : attrs.GetAttribute("pwdLastSet")?.StringValue; var pwdLastSet = attrs.ContainsKey("pwdLastSet") ? attrs.GetAttribute("pwdLastSet")?.StringValue : null;
if (!pwdLastSet!.Equals("0")) userLdap.PwdLastSetTime = DateTime.FromFileTime(Convert.ToInt64(pwdLastSet)); if (pwdLastSet != null && !pwdLastSet.Equals("0")) userLdap.PwdLastSetTime = DateTime.FromFileTime(Convert.ToInt64(pwdLastSet));
var userAccountControl = !attrs.ContainsKey("userAccountControl") ? null : attrs.GetAttribute("userAccountControl")?.StringValue; var userAccountControl = attrs.ContainsKey("userAccountControl") ? attrs.GetAttribute("userAccountControl")?.StringValue : null;
if ((Convert.ToInt32(userAccountControl) & 0x2) == 0x2) // 检查账户是否已过期通过检查userAccountControl属性的特定位 if ((Convert.ToInt32(userAccountControl) & 0x2) == 0x2) // 检查账户是否已过期通过检查userAccountControl属性的特定位
userLdap.AccountExpiresFlag = true; userLdap.AccountExpiresFlag = true;
if ((Convert.ToInt32(userAccountControl) & 0x10000) == 0x10000) // 检查账户密码设置是否永不过期 if ((Convert.ToInt32(userAccountControl) & 0x10000) == 0x10000) // 检查账户密码设置是否永不过期
@ -428,9 +428,9 @@ public class SysLdapService : IDynamicApiController, ITransient
{ {
Pid = org.Id, Pid = org.Id,
Id = YitIdHelper.NextId(), Id = YitIdHelper.NextId(),
Code = !attrs.ContainsKey(sysLdap.BindAttrCode) ? null : new Guid(attrs.GetAttribute(sysLdap.BindAttrCode)?.ByteValue).ToString(), Code = attrs.ContainsKey(sysLdap.BindAttrCode) ? new Guid(attrs.GetAttribute(sysLdap.BindAttrCode)?.ByteValue).ToString() : null,
Level = org.Level + 1, Level = org.Level + 1,
Name = !attrs.ContainsKey(sysLdap.BindAttrAccount) ? null : attrs.GetAttribute(sysLdap.BindAttrAccount)?.StringValue, Name = attrs.ContainsKey(sysLdap.BindAttrAccount) ? attrs.GetAttribute(sysLdap.BindAttrAccount)?.StringValue : null,
OrderNo = listOrgs.Count + 1, OrderNo = listOrgs.Count + 1,
}; };
} }