using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, _domain))
{
// 工号一定要全
using (var userPrincipal = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName,
loginModel.JobNumber))
{
if (userPrincipal == null)
{
return "账号不正确,请重新输入";
}
if (!pc.ValidateCredentials(loginModel.JobNumber, loginModel.Password))
{
return @"密码输入错误,请重新输入";
}
//GivenName是用户名称,Surname是工号(无前缀),Name是用户名称+工号(无前缀)
W3PersonDetailInfo personDetailInfo = new W3PersonDetailInfo()
{
SearchName = userPrincipal.Name,
UserName = userPrincipal.GivenName,
JobNumber = userPrincipal.SamAccountName,
EmailAddress = userPrincipal.EmailAddress
};
return personDetailInfo;
}
}