Esempio n. 1
0
    /// <summary>
    /// Page load.
    /// </summary>
    /// <param name="sender">Sender.</param>
    /// <param name="e">Arguments</param>
    protected void Page_Load(object sender, EventArgs e)
    {
        hash      = QueryHelper.GetString("hash", string.Empty);
        time      = QueryHelper.GetString("datetime", string.Empty);
        policyReq = QueryHelper.GetInteger("policyreq", 0);
        pwdExp    = QueryHelper.GetInteger("exp", 0);

        // Prepare URL of logon page
        securedAreasLogonUrl = AuthenticationHelper.GetSecuredAreasLogonPage(SiteContext.CurrentSiteName);
        securedAreasLogonUrl = UrlResolver.ResolveUrl(securedAreasLogonUrl);

        returnUrl = QueryHelper.GetString("returnurl", securedAreasLogonUrl);

        rfvConfirmPassword.Text = GetString("general.requiresvalue");

        siteName = SiteContext.CurrentSiteName;

        // Get interval from settings
        interval = SettingsKeyInfoProvider.GetDoubleValue("CMSResetPasswordInterval", siteName);

        // Prepare failed message
        string invalidRequestMessage = DataHelper.GetNotEmpty(InvalidRequestText, String.Format(ResHelper.GetString("membership.passwresetfailed"), URLHelper.AddParameterToUrl(securedAreasLogonUrl, "forgottenpassword", "1")));

        // Reset password cancelation
        if (QueryHelper.GetBoolean("cancel", false))
        {
            // Get user info
            UserInfo ui = UserInfoProvider.GetUsersDataWithSettings()
                          .WhereEquals("UserPasswordRequestHash", hash)
                          .FirstObject;

            if (ui != null)
            {
                ui.UserPasswordRequestHash = null;
                UserInfoProvider.SetUserInfo(ui);
                ClearResetRequestID();

                ShowInformation(GetString("membership.passwresetcancelled"));
            }
            else
            {
                ShowError(invalidRequestMessage);
            }

            pnlReset.Visible = false;
            return;
        }

        // Reset password request
        if (!URLHelper.IsPostback())
        {
            if (policyReq > 0)
            {
                ShowInformation(GetString("passwordpolicy.policynotmet") + "<br />" + passStrength.GetPasswordPolicyHint());
            }

            UserInfo ui;

            // Get user info
            int userId = GetResetRequestID();
            if (userId > 0)
            {
                ui = UserInfoProvider.GetUserInfo(userId);
                if (ui != null)
                {
                    // Invalidation forces user info to load user settings from DB and not use cached values.
                    ui.Generalized.Invalidate(false);
                }
            }
            else
            {
                ui = UserInfoProvider.GetUsersDataWithSettings()
                     .WhereEquals("UserPasswordRequestHash", hash).FirstObject;
            }

            // There is nobody to reset password for
            if (ui == null)
            {
                return;
            }

            // Validate request
            ResetPasswordResultEnum result = AuthenticationHelper.ValidateResetPassword(ui, hash, time, interval, "Reset password control");

            // Prepare messages
            string resultMessage = string.Empty;

            // Check result
            switch (result)
            {
            case ResetPasswordResultEnum.Success:
                // Save user to session
                SetResetRequestID(ui.UserID);

                // Delete it from user info
                ui.UserPasswordRequestHash = null;
                UserInfoProvider.SetUserInfo(ui);

                break;

            case ResetPasswordResultEnum.TimeExceeded:
                resultMessage = DataHelper.GetNotEmpty(ExceededIntervalText, String.Format(ResHelper.GetString("membership.passwreqinterval"), URLHelper.AddParameterToUrl(securedAreasLogonUrl, "forgottenpassword", "1")));
                break;

            default:
                resultMessage = invalidRequestMessage;
                break;
            }

            if (!string.IsNullOrEmpty(resultMessage))
            {
                // Show error message
                ShowError(resultMessage);

                pnlReset.Visible = false;
            }
        }
    }
    /// <summary>
    /// Page load.
    /// </summary>
    /// <param name="sender">Sender.</param>
    /// <param name="e">Arguments</param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (this.ViewMode != ViewModeEnum.LiveSite)
        {
            return;
        }

        lbSubmit.Click += LbSubmit_Click;
        cVNewPassword.ServerValidate += CVNewPassword_ServerValidate;

        hash      = QueryHelper.GetString("hash", string.Empty);
        time      = QueryHelper.GetString("datetime", string.Empty);
        policyReq = QueryHelper.GetInteger("policyreq", 0);
        pwdExp    = QueryHelper.GetInteger("exp", 0);
        returnUrl = QueryHelper.GetString("returnurl", null);

        siteName = SiteContext.CurrentSiteName;

        // Get interval from settings
        interval = SettingsKeyInfoProvider.GetDoubleValue(siteName + ".CMSResetPasswordInterval");

        // Prepare failed message
        string invalidRequestMessage = DataHelper.GetNotEmpty(InvalidRequestText, String.Format(ResHelper.GetString("membership.passwresetfailed"), ResolveUrl(RequestPasswordResetURL)));

        // Reset password cancelation
        if (QueryHelper.GetBoolean("cancel", false))
        {
            // Get user info
            UserInfo ui = UserInfoProvider.GetUsersDataWithSettings()
                          .WhereEquals("UserPasswordRequestHash", hash)
                          .FirstObject;

            if (ui != null)
            {
                ui.UserPasswordRequestHash = null;
                UserInfoProvider.SetUserInfo(ui);
                ClearResetRequestID();

                ShowInformation(GetString("membership.passwresetcancelled"));
            }
            else
            {
                ShowError(invalidRequestMessage);
            }

            pnlReset.Visible = false;
            return;
        }

        // Reset password request
        if (!URLHelper.IsPostback())
        {
            if (policyReq > 0)
            {
                ShowInformation(GetString("passwordpolicy.policynotmet"));
            }

            // Get user info
            var uiData = UserInfoProvider.GetUsersDataWithSettings()
                         .WhereEquals("UserPasswordRequestHash", hash);

            int userId = GetResetRequestID();
            if (userId > 0)
            {
                uiData
                .Or()
                .WhereEquals("UserID", userId);
            }


            UserInfo ui = uiData.FirstObject;

            // Validate request
            ResetPasswordResultEnum result = AuthenticationHelper.ValidateResetPassword(ui, hash, time, interval, "Reset password control");

            // Prepare messages
            string timeExceededMessage = DataHelper.GetNotEmpty(ExceededIntervalText, String.Format(ResHelper.GetString("membership.passwreqinterval"), ResolveUrl(RequestPasswordResetURL)));
            string resultMessage       = string.Empty;

            // Check result
            switch (result)
            {
            case ResetPasswordResultEnum.Success:
                // Save user to session
                SetResetRequestID(ui.UserID);

                // Delete it from user info
                ui.UserPasswordRequestHash = null;
                UserInfoProvider.SetUserInfo(ui);

                break;

            case ResetPasswordResultEnum.TimeExceeded:
                resultMessage = timeExceededMessage;
                break;

            default:
                resultMessage = invalidRequestMessage;
                break;
            }

            if (!string.IsNullOrEmpty(resultMessage))
            {
                // Show error message
                ShowError(resultMessage);

                pnlReset.Visible = false;
            }
        }
    }
Esempio n. 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        SetupControl();

        userID = ValidationHelper.GetInteger(SessionHelper.GetValue("UserPasswordRequestID"), 0);

        hash      = QueryHelper.GetString("hash", string.Empty);
        time      = QueryHelper.GetString("datetime", string.Empty);
        policyReq = QueryHelper.GetInteger("policyreq", 0);
        pwdExp    = QueryHelper.GetInteger("exp", 0);
        returnUrl = QueryHelper.GetString("returnurl", null);

        btnReset.Text           = GetString("general.reset");
        rfvConfirmPassword.Text = GetString("general.requiresvalue");

        siteName = SiteContext.CurrentSiteName;

        // Get interval from settings
        interval = SettingsKeyInfoProvider.GetDoubleValue(siteName + ".CMSResetPasswordInterval");

        // Prepare failed message
        string invalidRequestMessage = DataHelper.GetNotEmpty(InvalidRequestText, String.Format(ResHelper.GetString("membership.passwresetfailed"), ResolveUrl("~/cmspages/logon.aspx?forgottenpassword=1")));

        // Reset password cancelation
        if (QueryHelper.GetBoolean("cancel", false))
        {
            // Get user info
            UserInfo ui = UserInfoProvider.GetUserInfoWithSettings("UserPasswordRequestHash = '" + SecurityHelper.GetSafeQueryString(hash, true) + "'");
            if (ui != null)
            {
                ui.UserPasswordRequestHash = null;
                UserInfoProvider.SetUserInfo(ui);

                SessionHelper.Remove("UserPasswordRequestID");

                ShowInformation(GetString("membership.passwresetcancelled"));
            }
            else
            {
                ShowError(invalidRequestMessage);
            }

            pnlReset.Visible = false;
            return;
        }

        // Reset password request
        if (!URLHelper.IsPostback())
        {
            if (policyReq > 0)
            {
                ShowInformation(GetString("passwordpolicy.policynotmet") + "<br />" + passStrength.GetPasswordPolicyHint());
            }

            // Prepare query
            string query = "UserPasswordRequestHash = '" + SecurityHelper.GetSafeQueryString(hash, true) + "'";
            if (userID > 0)
            {
                query = SqlHelper.AddWhereCondition(query, "UserID = " + userID, "OR");
            }

            // Get user info
            UserInfo ui = UserInfoProvider.GetUserInfoWithSettings(query);

            // Validate request
            ResetPasswordResultEnum result = AuthenticationHelper.ValidateResetPassword(ui, hash, time, interval, "Reset password control");

            // Prepare messages
            string timeExceededMessage = DataHelper.GetNotEmpty(ExceededIntervalText, String.Format(ResHelper.GetString("membership.passwreqinterval"), ResolveUrl("~/cmspages/logon.aspx?forgottenpassword=1")));
            string resultMessage       = string.Empty;

            // Check result
            switch (result)
            {
            case ResetPasswordResultEnum.Success:
                // Save user is to session
                SessionHelper.SetValue("UserPasswordRequestID", ui.UserID);

                // Delete it from user info
                ui.UserPasswordRequestHash = null;
                UserInfoProvider.SetUserInfo(ui);

                break;

            case ResetPasswordResultEnum.TimeExceeded:
                resultMessage = timeExceededMessage;
                break;

            default:
                resultMessage = invalidRequestMessage;
                break;
            }

            if (!string.IsNullOrEmpty(resultMessage))
            {
                // Show error message
                ShowError(resultMessage);

                pnlReset.Visible = false;

                return;
            }
        }
    }
Esempio n. 4
0
 public double GetDoubleSettingValue(string SiteName, string SettingsKeyCode)
 {
     return(SettingsKeyInfoProvider.GetDoubleValue(SettingsKeyCode, new SiteInfoIdentifier(SiteName)));
 }