//======================================================================= public static void LogonAs(int companyID, string userName) { if (userName == null) { throw new ArgumentNullException("userName"); } if (userName.Length == 0) { throw new ArgumentException("userName cannot be an empty string", "userName"); } System.Diagnostics.Debug.WriteLine("LogonAs(" + companyID.ToString() + "," + userName + ")"); CurrentlyRetrievingUserInfo = true; try { // Look up person DataRow personRow = UserData.GetPersonByUserName(companyID, userName); // Not found? if (personRow == null) { } if (personRow.Table.Columns.Contains("Enabled") && Change.ToBool(personRow["Enabled"]) == false) { RedirectToAccessDeniedPage("UserInfo-AccountStatus"); } // Finally, create and cache in Session UserInfo userInfo = new UserInfo(personRow); HttpContext.Current.Session["IbUserInfo"] = userInfo; HttpContext.Current.Items["JustLoggedIn"] = true; System.Diagnostics.Debug.WriteLine("LogonAs complete: " + userInfo); } finally { CurrentlyRetrievingUserInfo = false; } }
//===================================================================== public UserInfo(DataRow person) { if (person == null) { throw new ArgumentNullException("person"); } ID = Change.ToInt(person["ID"]); Name = person["Name"].ToString(); ChineseName = person["ChineseName"].ToString(); if (string.IsNullOrEmpty(ChineseName)) { ChineseName = Name; } Email = person["Email"].ToString(); CompanyID = Change.ToInt(person["CompanyID"]); CompanyCode = Change.ToString(person["CompanyCode"]); CompanyName = Change.ToString(person["CompanyName"]); CompanyLogo = Change.ToString(person["CompanyLogo"]); MustChangePassword = Change.ToBool(person["MustChangePassword"]); LegalAcceptDate = Change.ToDateTime(person["LegalAcceptDate"]); DefaultPageSize = Change.ToInt(person["DefaultPageSize"]); if (DefaultPageSize == 0) { DefaultPageSize = 20; } LogonCount = Change.ToInt(person["LogonCount"]); IsClientAdmin = Change.ToBool(person["IsClientAdmin"]); UserPortraitPath = Change.ToString(person["UserPortraitPath"]); if (string.IsNullOrEmpty(UserPortraitPath)) { UserPortraitPath = Global.Default_User_Portrait_Path; } }