protected void loginClick(object sender, EventArgs e) { if (!(string.IsNullOrEmpty(loginUsername.Text.Trim()) || string.IsNullOrEmpty(loginPassword.Text.Trim()))) { var patron = new Patron(); if (Patron.Login(loginUsername.Text.Trim(), loginPassword.Text)) { var bp = Patron.GetObjectByUsername(loginUsername.Text.Trim()); var pgm = DAL.Programs.FetchObject(bp.ProgID); if (pgm == null) { var progID = Programs.GetDefaultProgramForAgeAndGrade(bp.Age, bp.SchoolGrade.SafeToInt()); bp.ProgID = progID; bp.Update(); } new SessionTools(Session).EstablishPatron(bp); TestingBL.CheckPatronNeedsPreTest(); TestingBL.CheckPatronNeedsPostTest(); if (loginRememberMe.Checked) { var loginUsernameCookie = new HttpCookie(CookieKey.Username); loginUsernameCookie.Expires = DateTime.Now.AddDays(14); loginUsernameCookie.Value = loginUsername.Text.Trim(); Response.SetCookie(loginUsernameCookie); } else { if (Request.Cookies[CookieKey.Username] != null) { Response.Cookies[CookieKey.Username].Expires = DateTime.Now.AddDays(-1); } } if (ViewState[SessionKey.RequestedPath] != null) { string requestedPath = ViewState[SessionKey.RequestedPath].ToString(); Response.Redirect(requestedPath); } else { Response.Redirect("~"); } } else { Session[SessionKey.PatronMessage] = "Invalid username or password."; Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Danger; Session[SessionKey.PatronMessageGlyphicon] = "remove"; Session[SessionKey.Patron] = null; } } }
protected void loginPopupClick(object sender, EventArgs e) { if (!(string.IsNullOrEmpty(loginPopupUsername.Text.Trim()) || string.IsNullOrEmpty(loginPopupPassword.Text.Trim()))) { var patron = new Patron(); if (Patron.Login(loginPopupUsername.Text.Trim(), loginPopupPassword.Text)) { var bp = Patron.GetObjectByUsername(loginPopupUsername.Text.Trim()); var pgm = DAL.Programs.FetchObject(bp.ProgID); if (pgm == null) { int schoolGrade; int.TryParse(bp.SchoolGrade, out schoolGrade); var progID = Programs.GetDefaultProgramForAgeAndGrade(bp.Age, schoolGrade); bp.ProgID = progID; bp.Update(); } /* recalulate goal cache to accomdate changes in program length and point multipliers */ ProgramGamePointConversion pgc = null; foreach (ActivityType activityTypeValue in Enum.GetValues(typeof(ActivityType))) { int activityTypeId = (int)activityTypeValue; var temp = ProgramGamePointConversion.FetchObjectByActivityId(pgm.PID, activityTypeId); if (temp != null && temp.PointCount > 0) { if (activityTypeValue == ActivityType.Minutes || activityTypeValue == ActivityType.Pages) { pgc = temp; break; } } } if (pgc != null) { bp.RecalculateGoalCache(pgm, pgc); bp.Update(); } new SessionTools(Session).EstablishPatron(bp); TestingBL.CheckPatronNeedsPreTest(); TestingBL.CheckPatronNeedsPostTest(); if (loginPopupRememberMe.Checked) { var loginUsernameCookie = new HttpCookie(CookieKey.Username); loginUsernameCookie.Expires = DateTime.Now.AddDays(14); loginUsernameCookie.Value = loginPopupUsername.Text.Trim(); Response.SetCookie(loginUsernameCookie); } else { if (Request.Cookies[CookieKey.Username] != null) { Response.Cookies[CookieKey.Username].Expires = DateTime.Now.AddDays(-1); } } if (Session[SessionKey.RequestedPath] != null) { string requestedPath = Session[SessionKey.RequestedPath].ToString(); Session.Remove(SessionKey.RequestedPath); Response.Redirect(requestedPath); } else if (ViewState[SessionKey.RequestedPath] != null) { string requestedPath = ViewState[SessionKey.RequestedPath].ToString(); Response.Redirect(requestedPath); } else { Response.Redirect("~"); } } else { LoginPopupErrorMessage = "Invalid username or password."; new SessionTools(Session).ClearPatron(); } } }
protected void Page_Load(object sender, EventArgs e) { base.PageLoad(sender, e); CurrentPage = (BaseSRPPage)Page; if (string.IsNullOrEmpty(Page.Title) && !string.IsNullOrEmpty(SystemNameText)) { Page.Title = SystemNameText.Trim(); } Control ctl = LoadControl("~/Controls/ProgramCSS.ascx"); var plc = FindControl("ProgramCSS"); plc.Controls.Add(ctl); if (CurrentPage.IsSecure && !CurrentPage.IsLoggedIn) { Response.Redirect("~/Logout.aspx"); } if (string.IsNullOrEmpty(CurrentPage.MetaDescription)) { CurrentPage.MetaDescription = DefaultMetaDescription; } Page.MetaDescription = CurrentPage.MetaDescription; var currentTenant = HttpContext.Current.Session["TenantID"] == null || HttpContext.Current.Session["TenantID"].ToString() == "" ? -1 : (int)HttpContext.Current.Session["TenantID"]; var sessionTool = new SessionTools(Session); if (PatronTakingTest) { adventuresNav.Visible = false; challengesNav.Visible = false; offersNav.Visible = false; badgesNav.Visible = false; eventsNav.Visible = false; mailNav.Visible = false; homeNav.Visible = false; accountNav.Visible = false; } else { homeNav.Visible = true; homeNav.Attributes.Add("class", DashboardPageActive); mailNav.Visible = true; mailNav.Attributes.Add("class", MailSectionActive); accountNav.Visible = true; accountNav.Attributes.Add("class", AccountSectionActive); LoggedOutRegister.Attributes.Add("class", RegisterPageActive); LoggedOutLogin.Attributes.Add("class", LoginPageActive); var adventuresActive = sessionTool.GetCache(Cache, CacheKey.AdventuresActive) as bool?; if (adventuresActive == null) { var programGames = DAL.ProgramGame.GetAll(); adventuresActive = programGames.Tables.Count > 0 && programGames.Tables[0].Rows.Count > 0; sessionTool.SetCache(Cache, CacheKey.AdventuresActive, adventuresActive); } adventuresNav.Visible = adventuresActive == true; adventuresNav.Attributes.Add("class", AdventuresSectionActive); var challengesActive = sessionTool.GetCache(Cache, CacheKey.ChallengesActive) as bool?; if (challengesActive == null) { var challenges = DAL.BookList.GetAll(); challengesActive = challenges.Tables.Count > 0 && challenges.Tables[0].Rows.Count > 0; sessionTool.SetCache(Cache, CacheKey.ChallengesActive, challengesActive); } challengesNav.Visible = challengesActive == true; challengesAnonNav.Visible = challengesActive == true; challengesNav.Attributes.Add("class", ChallengesSectionActive); challengesAnonNav.Attributes.Add("class", ChallengesSectionActive); var offersActive = sessionTool.GetCache(Cache, CacheKey.OffersActive) as bool?; if (offersActive == null) { var offers = DAL.Offer.GetAll(); offersActive = offers.Tables.Count > 0 && offers.Tables[0].Rows.Count > 0; sessionTool.SetCache(Cache, CacheKey.OffersActive, offersActive); } offersNav.Visible = offersActive == true; offersNav.Attributes.Add("class", OffersPageActive); var badgesActive = sessionTool.GetCache(Cache, CacheKey.BadgesActive) as bool?; if (badgesActive == null) { badgesActive = DAL.Badge.GetVisibleCount() > 0; sessionTool.SetCache(Cache, CacheKey.BadgesActive, badgesActive); } badgesNav.Visible = badgesActive == true; badgesAnonNav.Visible = badgesActive == true; badgesNav.Attributes.Add("class", BadgesSectionActive); badgesAnonNav.Attributes.Add("class", BadgesSectionActive); var eventsActive = sessionTool.GetCache(Cache, CacheKey.EventsActive) as bool?; if (eventsActive == null) { var events = DAL.Event.GetAll(); eventsActive = events.Tables.Count > 0 && events.Tables[0].Rows.Count > 0; sessionTool.SetCache(Cache, CacheKey.EventsActive, eventsActive); } eventsNav.Visible = eventsActive == true; eventsAnonNav.Visible = eventsActive == true; eventsNav.Attributes.Add("class", EventsSectionActive); eventsAnonNav.Attributes.Add("class", EventsSectionActive); } if (!IsPostBack) { if (CurrentPage.IsLoggedIn) { //f.Visible = ((Patron) Session["Patron"]).IsMasterAccount; if (Session[SessionKey.IsMasterAccount] as bool? == true) { a.Title = "My Account & Family"; } Unread = Notifications.GetAllUnreadToPatron(((Patron)Session["Patron"]).PID).Tables[0].Rows.Count.ToString(); if (!(Page is AddlSurvey || Page is Register || Page is Login || Page is Logout || Page is Recover)) { if (Session["PreTestMandatory"] != null && (bool)Session["PreTestMandatory"]) { TestingBL.PatronNeedsPreTest(); } } } else { loginPopupPanel.Visible = true; if (Session[SessionKey.RequestedPath] != null) { ShowLoginPopup = true; ViewState[SessionKey.RequestedPath] = Session[SessionKey.RequestedPath]; Session.Remove(SessionKey.RequestedPath); } if (Request.Cookies[CookieKey.Username] != null) { loginPopupUsername.Text = Request.Cookies[CookieKey.Username].Value; loginPopupRememberMe.Checked = true; } string programId = Request["PID"]; if (string.IsNullOrEmpty(programId)) { var sessProgId = Session["ProgramID"]; if (sessProgId != null) { programId = sessProgId.ToString(); } } if (string.IsNullOrEmpty(programId)) { programId = Programs.GetDefaultProgramID().ToString(); } var program = DAL.Programs.FetchObject(int.Parse(programId)); if (!program.IsRegistrationOpen) { LoggedOutRegister.Visible = false; } if (!program.IsOpen && !program.IsRegistrationOpen) { LoggedOutLogin.Visible = false; } } } }
protected void btnLogin_Click(object sender, EventArgs e) { if (Page.IsValid) { object tokenObject = this.ViewState["token"]; if (tokenObject == null) { new SessionTools(Session).AlertPatron(GetResourceString("password-recovery-expired"), PatronMessageLevels.Warning, "exclamation-sign"); Response.Redirect("~/Recover.aspx"); return; } var user = Patron.UpdatePasswordByToken(tokenObject.ToString(), NPassword.Text); if (user == null) { new SessionTools(Session).AlertPatron(GetResourceString("password-recovery-expired"), PatronMessageLevels.Warning, "exclamation-sign"); Response.Redirect("~/Recovery.aspx"); return; } var values = new { SystemName = SRPSettings.GetSettingValue("SysName", user.TenID), ContactName = SRPSettings.GetSettingValue("ContactName", user.TenID), ContactEmail = SRPSettings.GetSettingValue("ContactEmail", user.TenID), RemoteAddress = Request.UserHostAddress, UserEmail = user.EmailAddress, Username = user.Username, LoginLink = string.Format("{0}{1}", WebTools.GetBaseUrl(Request), "/Login.aspx"), PasswordResetSuccessSubject = "Your password has been reset!" }; this.Log().Info("Password reset process for {0} ({1}) complete from {2}", values.Username, values.UserEmail, values.RemoteAddress); // TODO email - move this template out to the database StringBuilder body = new StringBuilder(); body.Append("<p>The password change has been successful for the {SystemName} account: {Username}.</p>"); body.Append("<p>You may now <a href=\"{LoginLink}\">log in</a> using your new password.</p>"); body.Append("<p>If you have any comments or questions, please contact "); body.Append("{ContactName} at <a href=\"mailto:{ContactEmail}\">{ContactEmail}</a>.</p>"); body.Append("<p style=\"font-size: smaller;\"><em>This password request was "); body.Append("completed from: {RemoteAddress}.</em></p>"); new EmailService().SendEmail(user.EmailAddress, "{SystemName} - {PasswordResetSuccessSubject}".FormatWith(values), body.ToString().FormatWith(values)); var st = new SessionTools(Session); st.EstablishPatron(user); st.AlertPatron(GetResourceString("Your password has been reset!"), glyphicon: "ok"); TestingBL.CheckPatronNeedsPreTest(); TestingBL.CheckPatronNeedsPostTest(); Response.Redirect("~"); } }
protected void Page_Load(object sender, EventArgs e) { base.PageLoad(sender, e); this.CurrentPage = (BaseSRPPage)Page; if (string.IsNullOrEmpty(Page.Title) && !string.IsNullOrEmpty(this.SystemNameText)) { Page.Title = this.SystemNameText.Trim(); } Control ctl = LoadControl("~/Controls/ProgramCSS.ascx"); var plc = FindControl("ProgramCSS"); plc.Controls.Add(ctl); if (this.CurrentPage.IsSecure && !this.CurrentPage.IsLoggedIn) { Response.Redirect("~/Logout.aspx"); } if (string.IsNullOrEmpty(this.CurrentPage.MetaDescription)) { this.CurrentPage.MetaDescription = this.DefaultMetaDescription; } HtmlMeta meta = new HtmlMeta(); meta.Name = "description"; meta.Content = this.CurrentPage.MetaDescription; MetaDescriptionPlaceholder.Controls.Add(meta); if (Cache[CacheKey.AdventuresActive] == null) { var programGames = DAL.ProgramGame.GetAll(); if (programGames.Tables.Count > 0 && programGames.Tables[0].Rows.Count > 0) { Cache[CacheKey.AdventuresActive] = true; } else { Cache[CacheKey.AdventuresActive] = false; } } adventuresNav.Visible = Cache[CacheKey.AdventuresActive] as bool? == true; adventuresNav.Attributes.Add("class", this.AdventuresSectionActive); if (Cache[CacheKey.ChallengesActive] == null) { var challenges = DAL.BookList.GetAll(); if (challenges.Tables.Count > 0 && challenges.Tables[0].Rows.Count > 0) { Cache[CacheKey.ChallengesActive] = true; } else { Cache[CacheKey.ChallengesActive] = false; } } challengesNav.Visible = Cache[CacheKey.ChallengesActive] as bool? == true; challengesNav.Attributes.Add("class", this.ChallengesSectionActive); if (Cache[CacheKey.OffersActive] == null) { var offers = DAL.Offer.GetAll(); if (offers.Tables.Count > 0 && offers.Tables[0].Rows.Count > 0) { Cache[CacheKey.OffersActive] = true; } else { Cache[CacheKey.OffersActive] = false; } } offersNav.Visible = Cache[CacheKey.OffersActive] as bool? == true; offersNav.Attributes.Add("class", this.OffersPageActive); if (Cache[CacheKey.BadgesActive] == null) { var badges = DAL.Badge.GetAll(); if (badges.Tables.Count > 0 && badges.Tables[0].Rows.Count > 0) { Cache[CacheKey.BadgesActive] = true; } else { Cache[CacheKey.BadgesActive] = false; } } badgesNav.Visible = Cache[CacheKey.BadgesActive] as bool? == true; badgesAnonNav.Visible = Cache[CacheKey.BadgesActive] as bool? == true; badgesNav.Attributes.Add("class", this.BadgesSectionActive); badgesAnonNav.Attributes.Add("class", this.BadgesSectionActive); if (Cache[CacheKey.EventsActive] == null) { var events = DAL.Event.GetAll(); if (events.Tables.Count > 0 && events.Tables[0].Rows.Count > 0) { Cache[CacheKey.EventsActive] = true; } else { Cache[CacheKey.EventsActive] = false; } } eventsNav.Visible = Cache[CacheKey.EventsActive] as bool? == true; eventsAnonNav.Visible = Cache[CacheKey.EventsActive] as bool? == true; eventsNav.Attributes.Add("class", this.EventsSectionActive); eventsAnonNav.Attributes.Add("class", this.EventsSectionActive); if (!IsPostBack) { if (this.CurrentPage.IsLoggedIn) { homeLink.HRef = "~"; //f.Visible = ((Patron) Session["Patron"]).IsMasterAccount; if (Session[SessionKey.IsMasterAccount] as bool? == true) { a.Title = "My Account & Family"; } this.Unread = Notifications.GetAllUnreadToPatron(((Patron)Session["Patron"]).PID).Tables[0].Rows.Count.ToString(); if (!(Page is AddlSurvey || Page is Register || Page is Login || Page is Logout || Page is Recover)) { if (Session["PreTestMandatory"] != null && (bool)Session["PreTestMandatory"]) { TestingBL.PatronNeedsPreTest(); } } } else { this.loginPopupPanel.Visible = true; if (Session[SessionKey.RequestedPath] != null) { this.ShowLoginPopup = true; ViewState[SessionKey.RequestedPath] = Session[SessionKey.RequestedPath]; Session.Remove(SessionKey.RequestedPath); } if (Request.Cookies[CookieKey.Username] != null) { loginPopupUsername.Text = Request.Cookies[CookieKey.Username].Value; loginPopupRememberMe.Checked = true; } } } }