protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //Set the hidden field values for the customization cookie hfCustomizationOptionCookieName.Value = Utilities.CustomizationOptionCookieName; hfCustomizationOptionCookieSection.Value = Utilities.CustomizationOptionCookieSection; try { //Get the customization cookie HttpCookie customizationCookie = Request.Cookies[Utilities.CustomizationOptionCookieName]; //If the customization cookie is null, refill from the database if (customizationCookie == null) { //Get the user's customization options from the database List <spGetUserCustomizationOptions_Result> userCustomizationOptions = new List <spGetUserCustomizationOptions_Result>(); using (PyramidContext databaseContext = new PyramidContext()) { //Get the user's customization options userCustomizationOptions = databaseContext.spGetUserCustomizationOptions(Context.User.Identity.Name).ToList(); } //Set the customization cookie Utilities.SetCustomizationOptionCookie(userCustomizationOptions); } } catch (Exception ex) { //Log the exception Utilities.LogException(ex); } } }
/// <summary> /// This method fires when the user clicks the Save button in the /// submitCustomizationOptions user control /// </summary> /// <param name="sender">The submitCustomizationOptions control</param> /// <param name="e">The Click event</param> protected void submitCustomizationOptions_Click(object sender, EventArgs e) { try { List <spGetUserCustomizationOptions_Result> userCustomizationOptions = new List <spGetUserCustomizationOptions_Result>(); using (PyramidContext context = new PyramidContext()) { //Get the user's customization options userCustomizationOptions = context.spGetUserCustomizationOptions(CurrentUser.UserName).ToList(); //Get the selected fireworks option spGetUserCustomizationOptions_Result selectedFireworksOption = userCustomizationOptions .Where(uco => uco.OptionTypeDescription.ToLower() == "fireworks") .FirstOrDefault(); //Update the customization options //------------------ Fireworks -------------------------- UserCustomizationOption fireworksOption; if (selectedFireworksOption.UserCustomizationOptionPK.HasValue && selectedFireworksOption.UserCustomizationOptionPK.Value > 0) { //Edit the fireworks option fireworksOption = context.UserCustomizationOption .Where(uco => uco.UserCustomizationOptionPK == selectedFireworksOption.UserCustomizationOptionPK.Value) .FirstOrDefault(); fireworksOption.Editor = User.Identity.Name; fireworksOption.EditDate = DateTime.Now; fireworksOption.CustomizationOptionValueCodeFK = Convert.ToInt32(ddFireworks.Value); context.SaveChanges(); } else { //Create the fireworks option fireworksOption = new UserCustomizationOption(); fireworksOption.Creator = User.Identity.Name; fireworksOption.CreateDate = DateTime.Now; fireworksOption.Username = CurrentUser.UserName; fireworksOption.CustomizationOptionTypeCodeFK = selectedFireworksOption.OptionTypePK; fireworksOption.CustomizationOptionValueCodeFK = Convert.ToInt32(ddFireworks.Value); context.UserCustomizationOption.Add(fireworksOption); context.SaveChanges(); } //------------------ End Fireworks -------------------------- //Refresh the user's customization options userCustomizationOptions = context.spGetUserCustomizationOptions(CurrentUser.UserName).ToList(); } //Set the customization options cookie bool isCookieSaved = Utilities.SetCustomizationOptionCookie(userCustomizationOptions); //Check to see if the cookie saved if (isCookieSaved) { //Show a success message msgSys.ShowMessageToUser("success", "Options Saved", "The customization options have been saved!", 10000); } else { //Tell the user it failed msgSys.ShowMessageToUser("warning", "Save Failed", "The customization options failed to save.", 10000); } } catch (Exception ex) { //Log any exceptions Utilities.LogException(ex); //Tell the user it failed msgSys.ShowMessageToUser("warning", "Save Failed", "The customization options failed to save.", 10000); } }
protected void Page_Load() { //Get the user manager userManager = Context.GetOwinContext().GetUserManager <ApplicationUserManager>(); //Get the current user CurrentUser = userManager.FindById(User.Identity.GetUserId()); if (!IsPostBack) { //Fill the text boxes txtPhoneNumber.Value = CurrentUser.PhoneNumber; txtEmail.Text = CurrentUser.Email; // Render success message var message = Request.QueryString["m"]; if (message != null) { // Strip the query string from action Form.Action = ResolveUrl("~/Account/Manage"); SuccessMessage = message == "ChangePwdSuccess" ? "Your password has been successfully changed!" : message == "SetPwdSuccess" ? "Your password has been successfully set!" : message == "RemoveLoginSuccess" ? "The account was successfully removed!" : message == "AddPhoneNumberSuccess" ? "Phone number has been successfully added!" : message == "VerifyPhoneNumberSuccess" ? "Phone number has been successfully verified!" : message == "RemovePhoneNumberSuccess" ? "Phone number was successfully removed!" : String.Empty; //Show the message msgSys.ShowMessageToUser("success", "Success", SuccessMessage, 15000); } //Show or hide the two-factor buttons ShowHideTwoFactorButtons(CurrentUser.TwoFactorEnabled); //Show or hide the phone buttons ShowHidePhoneButtons(CurrentUser.PhoneNumber, CurrentUser.PhoneNumberConfirmed); using (PyramidContext context = new PyramidContext()) { //Get the user's selected customization options List <spGetUserCustomizationOptions_Result> selectedOptions = context.spGetUserCustomizationOptions(CurrentUser.UserName).ToList(); //Fill and set the user customization option dropdowns //----------------- Fireworks ------------------------- List <CodeCustomizationOptionValue> fireworkOptions = context.CodeCustomizationOptionValue.AsNoTracking() .Include(ccov => ccov.CodeCustomizationOptionType) .Where(ccov => ccov.CodeCustomizationOptionType.Description.ToLower() == "fireworks") .OrderBy(ccov => ccov.OrderBy) .ToList(); ddFireworks.DataSource = fireworkOptions; ddFireworks.DataBind(); //Set the selected value int fireworksOption = selectedOptions.Where(so => so.OptionTypeDescription.ToLower() == "fireworks").Select(so => so.OptionValuePK).FirstOrDefault().GetValueOrDefault(); ddFireworks.SelectedItem = ddFireworks.Items.FindByValue(fireworksOption); //----------------- End Fireworks ------------------------- } } }
/// <summary> /// This method fires when the user clicks the Login button and it attempts to log /// the user in /// </summary> /// <param name="sender">The btnLogin DevExpress button</param> /// <param name="e">The Click event</param> protected void btnLogin_Click(object sender, EventArgs e) { if (ASPxEdit.AreEditorsValid(this, btnLogin.ValidationGroup)) { // Validate the user password var manager = Context.GetOwinContext().GetUserManager <ApplicationUserManager>(); var signinManager = Context.GetOwinContext().GetUserManager <ApplicationSignInManager>(); //Try to get the user PyramidUser user = manager.FindByName(txtUsername.Text); //Make sure that the user is confirmed if (user != null && manager.IsEmailConfirmed(user.Id)) { //Try to sign the user in var result = signinManager.PasswordSignIn(txtUsername.Text, txtPassword.Text, false, user.LockoutEnabled); switch (result) { case SignInStatus.Success: //The user successfully logged in List <UserProgramRole> userProgramRoles; List <spGetUserCustomizationOptions_Result> userCustomizationOptions; using (PyramidContext context = new PyramidContext()) { //Get the user's program roles userProgramRoles = context.UserProgramRole.AsNoTracking() .Include(upr => upr.CodeProgramRole) .Include(upr => upr.Program) .Where(upr => upr.Username == txtUsername.Text).ToList(); //Get the user's customization options userCustomizationOptions = context.spGetUserCustomizationOptions(txtUsername.Text).ToList(); //Keep a record of successful logins LoginHistory history = new LoginHistory(); history.Username = txtUsername.Text; history.LoginTime = DateTime.Now; //If the user only has one program role, record it in the login history if (userProgramRoles.Count == 1) { history.ProgramFK = userProgramRoles.First().ProgramFK; history.Role = userProgramRoles.First().CodeProgramRole.RoleName; } //Save the login history context.LoginHistory.Add(history); context.SaveChanges(); //Save the LoginHistory primary key to the session for later access Session["LoginHistoryPK"] = history.LoginHistoryPK; } //Set the user customization options cookie Utilities.SetCustomizationOptionCookie(userCustomizationOptions); //Redirect the user based on the number of roles they have if (userProgramRoles.Count > 1) { Response.Redirect(String.Format("/Account/SelectRole.aspx?ReturnUrl={0}", (Request.QueryString["ReturnUrl"] != null ? Request.QueryString["ReturnUrl"].ToString() : "/Default.aspx"))); } else { //To hold the role information ProgramAndRoleFromSession roleInfo = new ProgramAndRoleFromSession(); //Get the UserProgramRole UserProgramRole userRole = userProgramRoles.FirstOrDefault(); //Set the session variables for the program roles roleInfo.RoleFK = userRole.CodeProgramRole.CodeProgramRolePK; roleInfo.RoleName = userRole.CodeProgramRole.RoleName; roleInfo.AllowedToEdit = userRole.CodeProgramRole.AllowedToEdit; roleInfo.CurrentProgramFK = userRole.ProgramFK; roleInfo.ProgramName = userRole.Program.ProgramName; //Get the hub and state information using (PyramidContext context = new PyramidContext()) { Program currentProgram = context.Program.AsNoTracking() .Include(p => p.Hub) .Include(p => p.State) .Include(p => p.ProgramType) .Where(p => p.ProgramPK == userRole.ProgramFK).FirstOrDefault(); roleInfo.HubFK = currentProgram.HubFK; roleInfo.HubName = currentProgram.Hub.Name; roleInfo.StateFK = currentProgram.StateFK; roleInfo.StateName = currentProgram.State.Name; roleInfo.StateLogoFileName = currentProgram.State.LogoFilename; roleInfo.StateCatchphrase = currentProgram.State.Catchphrase; roleInfo.StateDisclaimer = currentProgram.State.Disclaimer; //Set the allowed program fks if (roleInfo.RoleFK == (int)Utilities.ProgramRoleFKs.HUB_DATA_VIEWER) { //Hub viewer, allow them to see the programs in that hub var hubPrograms = context.Program.AsNoTracking() .Where(p => p.HubFK == roleInfo.HubFK.Value) .ToList(); roleInfo.ProgramFKs = hubPrograms .Select(hp => hp.ProgramPK) .ToList(); //Allow them to see all cohorts in their hub roleInfo.CohortFKs = hubPrograms .Select(hp => hp.CohortFK) .Distinct() .ToList(); //Don't restrict their view of the BOQs roleInfo.ShowBOQ = true; roleInfo.ShowBOQFCC = true; } else if (roleInfo.RoleFK == (int)Utilities.ProgramRoleFKs.APPLICATION_ADMIN) { //App admin, allow them to see all programs in a state roleInfo.ProgramFKs = context.Program.AsNoTracking() .Where(p => p.StateFK == roleInfo.StateFK.Value) .Select(p => p.ProgramPK).ToList(); //Allow them to see all cohorts in a state roleInfo.CohortFKs = context.Cohort.AsNoTracking() .Where(c => c.StateFK == roleInfo.StateFK.Value) .Select(c => c.CohortPK).ToList(); //Don't restrict their view of the BOQs roleInfo.ShowBOQ = true; roleInfo.ShowBOQFCC = true; } else if (roleInfo.RoleFK == (int)Utilities.ProgramRoleFKs.SUPER_ADMIN) { //Super admin, all programs in all states roleInfo.ProgramFKs = context.Program.AsNoTracking() .Select(p => p.ProgramPK).ToList(); //All cohorts roleInfo.CohortFKs = context.Cohort.AsNoTracking() .Select(c => c.CohortPK).ToList(); //Don't restrict their view of the BOQs roleInfo.ShowBOQ = true; roleInfo.ShowBOQFCC = true; } else { //Something else, limit to the current program fk List <int> programFKs = new List <int>(); programFKs.Add(roleInfo.CurrentProgramFK.Value); roleInfo.ProgramFKs = programFKs; //Limit to current cohort fk List <int> cohortFKs = new List <int>(); cohortFKs.Add(currentProgram.CohortFK); roleInfo.CohortFKs = cohortFKs; //Determine if this program is a FCC program var fccProgramTypes = currentProgram.ProgramType .Where(pt => pt.TypeCodeFK == (int)Utilities.ProgramTypeFKs.FAMILY_CHILD_CARE || pt.TypeCodeFK == (int)Utilities.ProgramTypeFKs.GROUP_FAMILY_CHILD_CARE) .ToList(); //Limit their view to the right BOQ type if (fccProgramTypes.Count > 0) { roleInfo.ShowBOQ = false; roleInfo.ShowBOQFCC = true; } else { roleInfo.ShowBOQ = true; roleInfo.ShowBOQFCC = false; } } } //Add the role information to the session Utilities.SetProgramRoleInSession(Session, roleInfo); //Redirect the user Response.Redirect(Request.QueryString["ReturnUrl"] != null ? Request.QueryString["ReturnUrl"].ToString() : "/Default.aspx"); } break; case SignInStatus.LockedOut: Response.Redirect("/Account/Lockout"); break; case SignInStatus.RequiresVerification: Response.Redirect(String.Format("/Account/TwoFactorAuthenticationSignIn?ReturnUrl={0}", Request.QueryString["ReturnUrl"]), true); break; case SignInStatus.Failure: default: //Show the user an error message msgSys.ShowMessageToUser("danger", "Error", "Invalid login attempt", 120000); //Focus the password text box txtPassword.Focus(); break; } } else { msgSys.ShowMessageToUser("danger", "Error", "Invalid login attempt", 120000); } } }