using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CMS.UIControls; using CMS.SiteProvider; using CMS.SettingsProvider; using CMS.GlobalHelper; using CMS.ExtendedControls; using CMS.CMSHelper; public partial class CMSModules_Membership_Controls_UnlockUserAccount : CMSUserControl { #region "Private variables" private string mInvalidAttemptsHash = null; private UserInfo mUserAccount = null; #endregion #region "Public properties" /// /// Gets or sets successful unlock text. /// public string SuccessfulUnlockText { get; set; } /// /// Gets or sets unsuccessful unlock text. /// public string UnsuccessfulUnlockText { get; set; } /// /// Gets or sets the unlock info label text. /// public string UnlockInfoText { get; set; } /// /// Gets or sets the unlock button text. /// public string UnlockButtonText { get; set; } /// /// Gets or sets the unlock label CSS class. /// public string UnlockTextCssClass { get; set; } /// /// Gets or sets the unlock button CSS class. /// public string UnlockButtonCssClass { get; set; } /// /// Gets or sets the URL to which user will be redirected after successful account unlock. /// public string RedirectionURL { get; set; } /// /// Get user account object /// public UserInfo UserAccount { get { if (mUserAccount == null) { mUserAccount = UserInfoProvider.GetUserInfoWithSettings("UserInvalidLogOnAttemptsHash = '" + SqlHelperClass.GetSafeQueryString(mInvalidAttemptsHash) + "'"); } return mUserAccount; } } /// /// Messages placeholder /// public override MessagesPlaceHolder MessagesPlaceHolder { get { return plcMess; } } #endregion #region "Methods" protected void Page_Init(object sender, EventArgs e) { // Get data from query string mInvalidAttemptsHash = QueryHelper.GetString("unlockaccounthash", string.Empty); } protected void Page_Load(object sender, EventArgs e) { // If StopProcessing flag is set, do nothing if (StopProcessing) { Visible = false; return; } else { bool controlPb = false; if (RequestHelper.IsPostBack()) { Control pbCtrl = ControlsHelper.GetPostBackControl(Page); if (pbCtrl == btnConfirm) { controlPb = true; } } // Setup controls SetupControls(!controlPb); if (!controlPb) { if (CheckAndUnlock(true)) { ShowInformation(DataHelper.GetNotEmpty(UnlockInfoText, GetString("invalidlogonattempts.unlockaccount.unlocktext"))); } } } } /// /// Button unlock click event /// protected void btnConfirm_Click(object sender, EventArgs e) { CheckAndUnlock(false); } /// /// Initialize controls properties /// private void SetupControls(bool forceReload) { btnConfirm.CssClass = DataHelper.GetNotEmpty(UnlockButtonCssClass, "LongButton"); if (forceReload) { btnConfirm.Text = DataHelper.GetNotEmpty(UnlockButtonText, GetString("forums.unlock")); } } /// /// Check that unlock hash is valid /// /// Indicates if only check will be performed private bool CheckAndUnlock(bool checkOnly) { if ((UserAccount != null) && !UserAccount.Enabled && (UserAccount.UserInvalidLogOnAttempts > 0)) { if (!checkOnly) { AuthenticationHelper.UnlockUserAccount(UserAccount); // Show information message or redirect to specified URL if (string.IsNullOrEmpty(RedirectionURL)) { btnConfirm.Visible = false; if(!string.IsNullOrEmpty(SuccessfulUnlockText)) { ShowConfirmation(SuccessfulUnlockText); } else { ShowConfirmation(GetString("invalidlogonattempts.unlockaccount.accountunlocked")); string url = URLHelper.ResolveUrl(SettingsKeyProvider.GetStringValue(CMSContext.CurrentSiteName + ".CMSSecuredAreasLogonPage")); lblInfo.Text = string.Format(GetString("invalidlogonattempts.unlockaccount.login"), url); } } else { URLHelper.Redirect(RedirectionURL); } } } else { DisplayError(DataHelper.GetNotEmpty(UnsuccessfulUnlockText, GetString("invalidlogonattempts.unlockaccount.errortext"))); return false; } return true; } #endregion #region "Helper methods" /// /// Display error message /// /// Error text to display private void DisplayError(string errorText) { ShowError(errorText); btnConfirm.Visible = false; } #endregion }