コード例 #1
0
        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;
                }

                // user requested a password for an email address that is not in the database
                // if account doesn't exist, send an email saying so
                var values = new {
                    SystemName    = SRPSettings.GetSettingValue("SysName"),
                    ContactName   = SRPSettings.GetSettingValue("ContactName"),
                    ContactEmail  = SRPSettings.GetSettingValue("ContactEmail"),
                    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");
                Response.Redirect("~");
            }
        }
コード例 #2
0
        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;
                    }
                }
            }
        }
コード例 #3
0
        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");
                Response.Redirect("~");
            }
        }
コード例 #4
0
        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;
                    }
                }
            }
        }