using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.DirectoryServices; /// /// Summary description for PPSUtilities /// public class PPSUtilities { public PPSUtilities() { // // TODO: Add constructor logic here // } public static string GetPPStatusImage(string ppStatus) { string imageURL; switch (ppStatus) { case "New": imageURL = "new_event.gif"; break; case "Pre-event Details": imageURL = "pre_event_details.gif"; break; case "Pre-event Review": imageURL = "peit_review.gif"; break; case "Event Implementation": imageURL = "event_implementation.gif"; break; case "Post-event Fix (PEIT)": imageURL = "fix_peit.gif"; break; case "Post-event Fix (Finance)": imageURL = "fix_finance.gif"; break; case "Post-event Review": imageURL = "peit_review.gif"; break; case "Post-event Finance Review": imageURL = "finance_review.gif"; break; case "Complete": imageURL = "complete.gif"; break; case "Cancelled": imageURL = "cancelled.gif"; break; default: imageURL = ""; break; } return "images/" + imageURL; } public static string CleanSPKeyPartner(string spKeyPartners) { // Get the clean name, since the string contains some prefixed chars spKeyPartners = spKeyPartners.Trim(); // Get rid of the ; character spKeyPartners = Utilities.replaceString(spKeyPartners, ";", ""); // Get rid of the beggining # character spKeyPartners = Utilities.GetStringPartAfterChar(spKeyPartners, "#"); // Get rid of the ending # character spKeyPartners = Utilities.GetStringPartBeforeChar(spKeyPartners, "#"); return spKeyPartners; } /// /// login: check ldap account /// /// bool public bool CheckLdapAccount(string username, string password) { using (DirectoryEntry entry = new DirectoryEntry()) { entry.AuthenticationType = AuthenticationTypes.Secure; entry.Path = ConfigurationManager.AppSettings["LDAP"]; entry.Username = username; entry.Password = password; DirectorySearcher searcher = new DirectorySearcher(entry); searcher.Filter = "(&(objectClass=*)(mail=" + username + "))"; try { SearchResult obj = searcher.FindOne(); if (obj != null) { string[] groupsUser = GetGroupForUser(obj); string[] groupsConfig = GetGroupForConfig(); foreach (string gu in groupsUser) { foreach (string gc in groupsConfig) { if (gu.Equals(gc, StringComparison.OrdinalIgnoreCase)) { HttpContext.Current.Session.Timeout = 60; HttpContext.Current.Session["MEMBEROF"] = groupsUser; return true; } } } } return false; } catch (Exception ex) { return false; } } } private string[] GetGroupForUser(SearchResult obj) { string[] results = new string[obj.Properties["memberof"].Count]; for (int i = 0; i < obj.Properties["memberof"].Count; i++) { string theGroupPath = obj.Properties["memberof"][i].ToString(); results[i] = theGroupPath.Substring(3, theGroupPath.IndexOf(",") - 3); } return results; } private string[] GetGroupForConfig() { string[] results = ConfigurationManager.AppSettings["GROUP"].Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); return results; } }