/// <summary> /// Date Created: 18/08/2011 /// Created By: Josephine Gad /// Description: Get login role /// -------------------------------- /// Date Modified: 27/10/2011 /// Modified By: Josephine Gad /// Description: get the primary role of the user /// </summary> public static string GetUserRole() { //return Roles.GetRolesForUser(GetUserName())[0]; return(GlobalCode.Field2String(HttpContext.Current.Session["UserRole"])); }
public static List <UserList_LDAP> GetLDAPUser(string sEmail) { List <UserList_LDAP> list = new List <UserList_LDAP>(); string sCompany; using (System.Net.WebClient client = new System.Net.WebClient()) { string sAPI = MUser.GetLDAP(); client.Headers.Add("content-type", "application/json");//set your header here, you can add multiple headers //verify if the username exist in LDAP string sResult = client.DownloadString(sAPI + "search?user="******",{".ToCharArray()); foreach (var arrayValue in ArrayResult) { var key = arrayValue.Key; var value = arrayValue.Value; if (key == "status") { if (GlobalCode.Field2String(value).ToLower() == "true") { } else { break; } } else if (key == "result") { if (value != null) { ArrayResultChild = (Dictionary <string, object>)value; foreach (var ResultChild in ArrayResultChild) { var resultChildKey = ResultChild.Key; var resultChildValue = ResultChild.Value; //if (resultChildKey == "entries") //{ // if (resultChildValue != null) // { // ArrayResultEntries = (Dictionary<string, object>)resultChildValue; // foreach (var resultEntries in ArrayResultEntries) // { // if (resultEntries.Key == "uid") // sUserName = GlobalCode.Field2String(resultEntries.Value); // } // } //} if (resultChildKey == "member") { if (resultChildValue != null) { var arrCompanyValue = (ArrayList)resultChildValue;//(List<string>)resultChildValue; for (var i = 0; i < arrCompanyValue.Count; i++) { if (GlobalCode.Field2String(arrCompanyValue[i]) == MUser.GetLDAPCompany()) { sCompany = GlobalCode.Field2String(GlobalCode.Field2String(arrCompanyValue[i])); } } } } } } } } } return(list); }
/// <summary> /// Date Created: 28/Oct/2015 /// Created By: Josephine Monteza /// (description) Add/Edit user from LDAP /// </summary> public static string AddEditUserFromLDAP(string strUsername, string strFName, string strLName, string strEmail, string strPWD, string sType, string strEmailNew) { string sReturn = ""; try { using (System.Net.WebClient client = new System.Net.WebClient()) { string sAPI = MUser.GetLDAP(); client.Headers.Add("content-type", "application/json");//set your header here, you can add multiple headers //verify if the username exist in LDAP string sResult = client.DownloadString(sAPI + "search?user="******",{".ToCharArray()); string sUserName = ""; string sCompany = ""; //bool IsExistinLDAP = false; foreach (var arrayValue in ArrayResult) { var key = arrayValue.Key; var value = arrayValue.Value; if (key == "status") { if (GlobalCode.Field2String(value).ToLower() == "true") { sUserName = strUsername; } else { break; } } else if (key == "result") { if (value != null) { ArrayResultChild = (Dictionary <string, object>)value; foreach (var ResultChild in ArrayResultChild) { var resultChildKey = ResultChild.Key; var resultChildValue = ResultChild.Value; //if (resultChildKey == "entries") //{ // if (resultChildValue != null) // { // ArrayResultEntries = (Dictionary<string, object>)resultChildValue; // foreach (var resultEntries in ArrayResultEntries) // { // if (resultEntries.Key == "uid") // sUserName = GlobalCode.Field2String(resultEntries.Value); // } // } //} if (resultChildKey == "member") { if (resultChildValue != null) { var arrCompanyValue = (ArrayList)resultChildValue;//(List<string>)resultChildValue; for (var i = 0; i < arrCompanyValue.Count; i++) { if (GlobalCode.Field2String(arrCompanyValue[i]) == MUser.GetLDAPCompany()) { sCompany = GlobalCode.Field2String(GlobalCode.Field2String(arrCompanyValue[i])); } } } } } } } } client.Headers.Add("content-type", "application/json");//set your header here, you can add multiple headers client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; //if user exist in LDAP TM, do not do anything if (strUsername == sUserName && sCompany == MUser.GetLDAPCompany()) { //Update user string sEditUser = sAPI + "modify"; string sParameter = "user="******"&firstname=" + strFName; //sParameter = sParameter + "&middlename=" + ""; //sParameter = sParameter + "&lastname=" + strLName; //sParameter = sParameter + "&description=EditedFromTravelmartSite"; //sParameter = sParameter + "&active=1"; //sResult = client.UploadString(sEditUser, sParameter); //Update Email sEditUser = sAPI + "changemail"; sParameter = "user="******"&email=" + strEmailNew; client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; sResult = client.UploadString(sEditUser, sParameter); sResultArray = sResult.Split(",{".ToCharArray()); string[] sSuccessArray; string sSuccessfull; for (int i = 0; i < sResultArray.Count(); i++) { if (sResultArray[i].Contains("\"message\"")) { sSuccessArray = sResultArray[i].Split(":".ToCharArray()); sSuccessfull = sSuccessArray[1].Replace("\"", ""); sReturn = sSuccessfull.Replace("}", ""); } } sReturn = " User Edit: " + sReturn; } //if user exist but no TM app, password is blank else if (strUsername == sUserName && sCompany != MUser.GetLDAPCompany()) { string sAddUser = sAPI + "add"; string sParameter = "user="******"&pass="******"&email=" + strEmail; sParameter = sParameter + "&firstname=" + strFName; sParameter = sParameter + "&middlename=" + ""; sParameter = sParameter + "&lastname=" + strLName; sParameter = sParameter + "&description=AddedFromTravelmartSite"; sParameter = sParameter + "&company=" + MUser.GetLDAPCompany(); sResult = client.UploadString(sAddUser, sParameter); sResultArray = sResult.Split(",{".ToCharArray()); string[] sSuccessArray; string sSuccessfull; for (int i = 0; i < sResultArray.Count(); i++) { if (sResultArray[i].Contains("\"message\"")) { sSuccessArray = sResultArray[i].Split(":".ToCharArray()); sSuccessfull = sSuccessArray[1].Replace("\"", ""); sReturn = sSuccessfull.Replace("}", ""); } } sReturn = " User Add with Other App: " + sReturn; } else { if (sType == "Edit") { MembershipUser mUser = Membership.GetUser(strUsername); string sPassword = DateTime.Now.ToLongTimeString().Replace(" ", "").Replace(":", ""); strPWD = sPassword; } string sAddUser = sAPI + "add"; string sParameter = "user="******"&pass="******"&email=" + strEmail; sParameter = sParameter + "&firstname=" + strFName; sParameter = sParameter + "&middlename=" + ""; sParameter = sParameter + "&lastname=" + strLName; sParameter = sParameter + "&description=FirstAddedFromTravelmartSite"; sParameter = sParameter + "&company=" + MUser.GetLDAPCompany(); sResult = client.UploadString(sAddUser, sParameter); sResultArray = sResult.Split(",{".ToCharArray()); string[] sSuccessArray; string sSuccessfull; for (int i = 0; i < sResultArray.Count(); i++) { if (sResultArray[i].Contains("\"message\"")) { sSuccessArray = sResultArray[i].Split(":".ToCharArray()); sSuccessfull = sSuccessArray[1].Replace("\"", ""); sReturn = sSuccessfull.Replace("}", ""); } } sReturn = " User Add New User: "******" - " + ex.Message; throw ex; } finally { sReturn = ""; } }