public static bool IsUserInAD(string username) { var status = false; AuthenticationResponse authenticationResponse = new AuthenticationResponse(); try { ADService.Service Adservice = new ADService.Service(); Adservice.Url = ConfigurationManager.AppSettings["ADServiceURL"]; string response = Adservice.ADUserDetails(username); if (!string.IsNullOrEmpty(response)) { status = true; } } catch (Exception ex) { status = false; } return(status); }
public static AuthenticationResponse AdCallForNameEmail(AuthenticationRequest request) { AuthenticationResponse authenticationResponse = new AuthenticationResponse(); try { ADService.Service Adservice = new ADService.Service(); Adservice.Url = ConfigurationManager.AppSettings["ADServiceURL"]; if (Helper.IsTest()) { string response = Adservice.ADUserDetails(request.UserID); if (!string.IsNullOrEmpty(response)) { string[] ResponseArray = response.Split('|'); if (ResponseArray != null) { string[] list = ResponseArray[0].Split(" ".ToCharArray()); authenticationResponse.FirstName = list[0]; authenticationResponse.LastName = list.Length > 2 ? list[2] : list[1]; if (ResponseArray[1] != null) { authenticationResponse.Email = ResponseArray[1]; } authenticationResponse.ResponseCode = "0"; authenticationResponse.ResponseDescription = "Success"; } else { authenticationResponse.ResponseCode = "1001"; authenticationResponse.ResponseDescription = "User not authorized."; } return(authenticationResponse); } } else { string response = Adservice.ADValidateUser(request.UserID, request.Password); if (!string.IsNullOrEmpty(response)) { string[] ResponseArray = response.Split('|'); if (ResponseArray != null) { if (ResponseArray[0] == "true") { string[] list = ResponseArray[1].Split(" ".ToCharArray()); authenticationResponse.FirstName = list[0]; authenticationResponse.LastName = list.Length > 2 ? list[2] : list[1]; string _response = Adservice.ADUserDetails(request.UserID); if (_response != null) { string[] _responseArray = _response.Split('|'); if (_responseArray[1] != null) { authenticationResponse.Email = _responseArray[1]; } authenticationResponse.ResponseCode = "0"; authenticationResponse.ResponseDescription = "Success"; } } else { authenticationResponse.ResponseCode = "1001"; authenticationResponse.ResponseDescription = "User not authorized."; } } return(authenticationResponse); } } } catch (Exception ex) { if (request != null) { request.Password = "******"; } authenticationResponse.ResponseCode = "1001"; authenticationResponse.ResponseDescription = "Unable Authenticate the user. Please contact the administrator"; } return(authenticationResponse); }