protected void btnSubmit_Click(object sender, System.EventArgs e) { Facade.Security facSecurity = new Facade.Security(); Entities.User busUser = new Entities.User(); Entities.CustomPrincipal loggedOnUser = (Entities.CustomPrincipal)Page.User; if (facSecurity.ValidatePassword(txtUsername.Text, txtNewPassword.Text)) { if (facSecurity.UpdatePassword(txtUsername.Text, txtNewPassword.Text, loggedOnUser.UserName)) { pnlChangePassword.Visible = false; pnlChangePasswordConfirmation.Visible = true; if (Request["returnURL"] != null) { Response.Redirect(Request.QueryString["returnURL"]); } } else { lblMessage.Text = ("The password has not been updated. Please note old passwords cannot be used again for at least one year."); lblMessage.Visible = true; } } else { rfvComplexPwd.IsValid = false; lblMessage.Visible = false; } }
private void addUser() { if (Page.IsValid) { Entities.CustomPrincipal loggedOnUser = (Entities.CustomPrincipal)Page.User; Facade.IUserAdmin facUserAdmin = new Facade.UserAdmin(); Facade.ISecurity facSecurity = new Facade.Security(); int organisationId = 0; int teamId = 0; bool plannerRemoved = false; if (m_isClient == true) { organisationId = Convert.ToInt32(cboClient.SelectedValue); } else { teamId = Convert.ToInt32(cboTeam.SelectedItem.Value); } int retIdentityId; if (string.IsNullOrEmpty(txtSelectedRoles.Value)) { lblMessage.Text = "Edit user failed. At least one role must be selected."; return; } string[] sRoles = txtSelectedRoles.Value.Substring(1).Split(','); int[] iRoles = new int[sRoles.Length]; for (int count = 0; count <= sRoles.Length - 1; count++) { iRoles[count] = Convert.ToInt32(sRoles[count]); } var validateRolesResult = facUserAdmin.ValidateUserRoles(txtUserName.Text, iRoles); if (!validateRolesResult.Success) { if (validateRolesResult.Infringements.Select(i => i.Description).Contains("PlannerRemoved") && validateRolesResult.Infringements.Count == 1) { plannerRemoved = true; } else { lblMessage.Text = string.Join("<br />", validateRolesResult.Infringements.Select(i => i.Description)); return; } } if (btnAdd.Text == "Add") { // Validate password if (facSecurity.ValidatePassword(txtUserName.Text, txtPassword.Text)) { rfvComplex.IsValid = true; } else { rfvComplex.IsValid = false; return; } if (!m_isClient) { retIdentityId = facUserAdmin.AddUser(txtUserName.Text, txtPassword.Text, txtForenames.Text, txtSurname.Text, iRoles, teamId, loggedOnUser.Name, txtEmail.Text, chkCanAccessFromAnywhere.Checked, chkScannedLicense.Checked); } else { retIdentityId = facUserAdmin.AddUserForClient(txtUserName.Text, txtPassword.Text, txtForenames.Text, txtSurname.Text, iRoles, organisationId, loggedOnUser.Name, txtEmail.Text, chkScannedLicense.Checked); } if (retIdentityId > 0) { if (chkEmailDetails.Checked && m_isClient && pnlEmailDetails.Visible) { EmailClient(); } this.ReturnValue = "CloseAndRefresh"; this.Close(); } else if (retIdentityId == -1) { lblMessage.Text = "The Username has already been added to the application."; } else { lblMessage.Text = "Add new User failed. Please try again."; } } else if (btnAdd.Text == "Update") { bool success = false; if (!m_isClient) { success = facUserAdmin.UpdateUser((int)ViewState["identityId"], txtPassword.Text, txtForenames.Text, txtSurname.Text, Convert.ToInt32(cboUserStatus.SelectedValue), iRoles, teamId, loggedOnUser.Name, txtEmail.Text, chkCanAccessFromAnywhere.Checked, chkScannedLicense.Checked, plannerRemoved); } else { success = facUserAdmin.UpdateUserForClient((int)ViewState["identityId"], txtPassword.Text, txtForenames.Text, txtSurname.Text, Convert.ToInt32(cboUserStatus.SelectedValue), iRoles, organisationId, loggedOnUser.Name, txtEmail.Text, chkScannedLicense.Checked); } if (success) { this.ReturnValue = "CloseAndRefresh"; this.Close(); } else { lblMessage.Text = "Update User failed. Please try again."; } } } }