protected void btnLogin_Click(object sender, EventArgs e) { this.lbError.Text = string.Empty; RequestMeasure requestMeasure = new RequestMeasure("btnLogin_Click"); CallContext resultContext = AdminClientRef.Login(this.tbxUserName.Text, this.tbxPassword.Text); LogDebug(requestMeasure.ToString()); if (resultContext.ResultCode == ETEMEnums.ResultEnum.Success) { this.userProps = new UserProps(); ETEMModel.Models.User currentUser = AdminClientRef.GetUserByUserID(resultContext.EntityID); if (currentUser != null) { this.userProps = MakeLoginByUserID(resultContext.EntityID); LogDebug("Потребител " + this.userProps.UserName + " влезе в системата"); Response.Redirect(Welcome.formResource.PagePath); } else { this.lbError.Text = ETEMModel.Helpers.BaseHelper.GetCaptionString("Съществува проблем с базата данни"); } } else { this.lbError.Text = resultContext.Message; } }
public UserProps MakeLoginByUserID(string UserID) { UserProps userProps = new UserProps(); ETEMModel.Models.User currentUser = AdminClientRef.GetUserByUserID(UserID); if (currentUser != null) { userProps.Roles = AdminClientRef.GetAllRolesByUser(currentUser.idUser.ToString(), null, null); for (int i = 0; i < userProps.Roles.Count; i++) { List <int> currentRolePermmitedActionsIds = AdminClientRef. GetAllPermittedActionsByRole(userProps.Roles[i].idRole.ToString(), null, null) .Select(r => r.idPermittedAction).ToList(); for (int j = 0; j < currentRolePermmitedActionsIds.Count; j++) { bool isDuplicate = userProps.ListUserPermittedActionsID.Any(p => p == currentRolePermmitedActionsIds[j]); if (!isDuplicate) { userProps.ListUserPermittedActionsID.Add(currentRolePermmitedActionsIds[j]); } } } //userProps.ListUserPermittedActionsID = AdminClientRef.getallp userProps.IdUser = currentUser.idUser.ToString(); userProps.UserName = currentUser.UserName; Person person = this.AdminClientRef.GetPersonByPersonID(currentUser.idPerson.ToString()); userProps.PersonNamePlusTitle = person.FullNamePlusTitle; userProps.PersonNameNoTitle = person.FullName; userProps.PersonNameAndFamily = person.FullNameTwo; userProps.PersonTwoNamePlusTitle = person.TwoNamesPlusTitle; userProps.PersonID = person.idPerson.ToString(); userProps.SessionID = this.Session.SessionID; userProps.IPAddress = Request.UserHostAddress; userProps.LoginDateTime = DateTime.Now; this.Session.Timeout = Convert.ToInt32(BasicPage.GetValueFromWebConfig("SessionTimeOut")); userProps.idStudent = Constants.INVALID_ID; userProps.IsCheckDomain = currentUser.idCheckDomain == GetKeyValueByIntCode("YES_NO", "Yes").idKeyValue; userProps.IsKilled = false; this.Session.Add(ETEMModel.Helpers.Constants.SESSION_USER_PROPERTIES, userProps); this.Session.Timeout = Int32.Parse(GetSettingByCode(ETEMEnums.AppSettings.WebSessionTimeOut).SettingValue); Dictionary <string, HttpSessionState> sessionData = (Dictionary <string, HttpSessionState>)Application[Constants.APPLICATION_ALL_SESSIONS]; if (sessionData.Keys.Contains(HttpContext.Current.Session.SessionID)) { sessionData.Remove(HttpContext.Current.Session.SessionID); sessionData.Add(HttpContext.Current.Session.SessionID, HttpContext.Current.Session); } } return(userProps); }