/// <summary>
 /// Connects to database and returns user's name.
 /// </summary>
 /// <param name="Code">Activation code.</param>
 /// <param name="PortalID">Portal ID.</param>
 /// <returns>User's name.</returns>
 public static ForgotPasswordInfo GetUsernameByActivationOrRecoveryCode(string Code, int PortalID)
 {
     try
     {
         SQLHandler SQLH = new SQLHandler();
         List <KeyValuePair <string, object> > ParamCollInput = new List <KeyValuePair <string, object> >();
         ParamCollInput.Add(new KeyValuePair <string, object>("@Code", Code));
         ParamCollInput.Add(new KeyValuePair <string, object>("@PortalID", PortalID));
         List <ForgotPasswordInfo> lstpwdinfo = new List <ForgotPasswordInfo>();
         lstpwdinfo = SQLH.ExecuteAsList <ForgotPasswordInfo>("[dbo].[sp_GetUsernameByActivationOrRecoveryCode]", ParamCollInput);
         ForgotPasswordInfo objInfo = new ForgotPasswordInfo();
         if (lstpwdinfo.Count > 0)
         {
             return(lstpwdinfo[0]);
         }
         else
         {
             objInfo.IsAlreadyUsed = true;
             return(objInfo);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        /// <summary>
        /// Connects to database and returns message template by message template type ID.
        /// </summary>
        /// <param name="MessageTemplateTypeID">Message template type ID.</param>
        /// <param name="PortalID">Portal ID.</param>
        /// <returns>User's password details.</returns>
        public static ForgotPasswordInfo GetMessageTemplateByMessageTemplateTypeID(int MessageTemplateTypeID, int PortalID)
        {
            SqlDataReader reader = null;

            try
            {
                SQLHandler SQLH = new SQLHandler();
                List <KeyValuePair <string, object> > ParamCollInput = new List <KeyValuePair <string, object> >();
                ParamCollInput.Add(new KeyValuePair <string, object>("@MessageTemplateTypeID", MessageTemplateTypeID));
                ParamCollInput.Add(new KeyValuePair <string, object>("@PortalID", PortalID));
                reader = SQLH.ExecuteAsDataReader("[dbo].[sp_MessageTemplateByMessageTemplateTypeID]", ParamCollInput);
                ForgotPasswordInfo objList = new ForgotPasswordInfo();
                while (reader.Read())
                {
                    objList.MessageTemplateID     = int.Parse(reader["MessageTemplateID"].ToString());
                    objList.MessageTemplateTypeID = int.Parse(reader["MessageTemplateTypeID"].ToString());
                    objList.Subject  = reader["Subject"].ToString();
                    objList.Body     = reader["Body"].ToString();
                    objList.MailFrom = reader["MailFrom"].ToString();
                }
                return(objList);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     ForgotPasswordInfo objInfo = UserManagementController.GetMessageTemplateByMessageTemplateTypeID(SystemSetting.PASSWORD_RECOVERED_HELP, GetPortalID);
     if (objInfo != null)
     {
         helpTemplate = objInfo.Body;
     }
     if (!IsPostBack)
     {
         string RecoveringCode = string.Empty;
         if (Request.QueryString["RecoveringCode"] != null)
         {
             RecoveringCode = Request.QueryString["RecoveringCode"].ToString();
             try
             {
                 RecoveringCode = EncryptionMD5.Decrypt(RecoveringCode);
                 hdnRecoveryCode.Value = RecoveringCode;
                 AddImageUrls();
                 sageframeuser = UserManagementController.GetUsernameByActivationOrRecoveryCode(hdnRecoveryCode.Value, GetPortalID);
                 if (sageframeuser.CodeForUsername != null)
                 {
                     if (sageframeuser.IsAlreadyUsed)
                     {
                         ShowMessage("", GetSageMessage("PasswordRecovery", "RecoveryCodeAlreadyActivated"), "", SageMessageType.Alert);
                         divRecoverpwd.Visible = false;
                     }
                     else
                     {
                         divRecoverpwd.Visible = true;
                     }
                 }
                 else
                 {
                     divRecoverpwd.Visible = false;
                     ShowMessage("", GetSageMessage("UserManagement", "UserDoesNotExist"), "", SageMessageType.Alert);
                 }
             }
             catch
             {
                 ShowMessage("", GetSageMessage("PasswordRecovery", "InvalidRecoveringCode"), "", SageMessageType.Alert);
                 divRecoverpwd.Visible = false;
             }
         }
         else
         {
             ShowMessage("", GetSageMessage("PasswordRecovery", "RecoveringCodeIsNotAvailable"), "", SageMessageType.Error);
             divRecoverpwd.Visible = false;
         }
         SetValidatorErrorMessage();
     }
 }
        /// <summary>
        /// Connects to database and returns user's name.
        /// </summary>
        /// <param name="Code">Activation code.</param>
        /// <param name="PortalID">Portal ID.</param>
        /// <returns>User's name.</returns>
        public static ForgotPasswordInfo GetUsernameByActivationOrRecoveryCode(string Code, int PortalID)
        {
            try
            {
                SQLHandler SQLH = new SQLHandler();
                List<KeyValuePair<string, object>> ParamCollInput = new List<KeyValuePair<string, object>>();
                ParamCollInput.Add(new KeyValuePair<string, object>("@Code", Code));
                ParamCollInput.Add(new KeyValuePair<string, object>("@PortalID", PortalID));
                List<ForgotPasswordInfo> lstpwdinfo = new List<ForgotPasswordInfo>();
                lstpwdinfo = SQLH.ExecuteAsList<ForgotPasswordInfo>("[dbo].[sp_GetUsernameByActivationOrRecoveryCode]", ParamCollInput);
                ForgotPasswordInfo objInfo = new ForgotPasswordInfo();
                if (lstpwdinfo.Count > 0)
                {
                    return lstpwdinfo[0];
                }
                else
                {
                    objInfo.IsAlreadyUsed = true;
                    return objInfo;
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }

        }
        /// <summary>
        /// Connects to database and returns message template by message template type ID.
        /// </summary>
        /// <param name="MessageTemplateTypeID">Message template type ID.</param>
        /// <param name="PortalID">Portal ID.</param>
        /// <returns>User's password details.</returns>
        public static ForgotPasswordInfo GetMessageTemplateByMessageTemplateTypeID(int MessageTemplateTypeID, int PortalID)
        {
            SqlDataReader reader = null;
            try
            {
                SQLHandler SQLH = new SQLHandler();
                List<KeyValuePair<string, object>> ParamCollInput = new List<KeyValuePair<string, object>>();
                ParamCollInput.Add(new KeyValuePair<string, object>("@MessageTemplateTypeID", MessageTemplateTypeID));
                ParamCollInput.Add(new KeyValuePair<string, object>("@PortalID", PortalID));
                reader = SQLH.ExecuteAsDataReader("[dbo].[sp_MessageTemplateByMessageTemplateTypeID]", ParamCollInput);
                ForgotPasswordInfo objList = new ForgotPasswordInfo();
                while (reader.Read())
                {
                    objList.MessageTemplateID = int.Parse(reader["MessageTemplateID"].ToString());
                    objList.MessageTemplateTypeID = int.Parse(reader["MessageTemplateTypeID"].ToString());
                    objList.Subject = reader["Subject"].ToString();
                    objList.Body = reader["Body"].ToString();
                    objList.MailFrom = reader["MailFrom"].ToString();
                }
                return objList;
            }
            catch (Exception ex)
            {

                throw ex;
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    SageFrameConfig pb = new SageFrameConfig();
                    string ActivationCode = string.Empty;
                    if (Request.QueryString["ActivationCode"] != null)
                    {
                        ActivationCode = Request.QueryString["ActivationCode"].ToString();
                        try
                        {
                            ActivationCode = EncryptionMD5.Decrypt(ActivationCode);
                        }
                        catch
                        {
                            ShowMessage("", GetSageMessage("UserRegistration", "InvalidActivationCode"), "", SageMessageType.Alert);
                            return;
                        }
                        ForgotPasswordInfo sageframeuser = new ForgotPasswordInfo();
                        sageframeuser = UserManagementController.GetUsernameByActivationOrRecoveryCode(ActivationCode, GetPortalID);
                        if (sageframeuser.CodeForUsername != null)
                        {
                            if (!sageframeuser.IsAlreadyUsed)
                            {
                                string UserName = _member.ActivateUser(ActivationCode, GetPortalID);
                                if (!String.IsNullOrEmpty(UserName))
                                {
                                    UserInfo user = _member.GetUserDetails(GetPortalID, UserName);
                                    if (user.UserExists)
                                    {
                                        List<ForgotPasswordInfo> messageTemplates = UserManagementController.GetMessageTemplateListByMessageTemplateTypeID(SystemSetting.ACTIVATION_SUCCESSFUL_EMAIL, GetPortalID);

                                        foreach (ForgotPasswordInfo messageTemplate in messageTemplates)
                                        {
                                            DataTable dtActivationSuccessfulTokenValues = UserManagementController.GetActivationSuccessfulTokenValue(user.UserName, GetPortalID);
                                            string replaceMessageSubject = MessageToken.ReplaceAllMessageToken(messageTemplate.Subject, dtActivationSuccessfulTokenValues);
                                            string replacedMessageTemplate = MessageToken.ReplaceAllMessageToken(messageTemplate.Body, dtActivationSuccessfulTokenValues);
                                            try
                                            {
                                                MailHelper.SendMailNoAttachment(messageTemplate.MailFrom, user.Email, replaceMessageSubject, replacedMessageTemplate, string.Empty, string.Empty);
                                            }
                                            catch (Exception)
                                            {
                                                ShowMessage("", GetSageMessage("UserRegistration", "SecureConnectionUAEmailError"), "", SageMessageType.Alert);
                                                return;
                                            }
                                        }
                                        ForgotPasswordInfo template = UserManagementController.GetMessageTemplateByMessageTemplateTypeID(SystemSetting.ACTIVATION_SUCCESSFUL_INFORMATION, GetPortalID);
                                        if (template != null)
                                        {
                                            ACTIVATION_INFORMATION.Text = template.Body;
                                        };
                                        LogInPublicModeRegistration(user);
                                    }
                                    else
                                    {
                                        ShowMessage("", GetSageMessage("UserManagement", "UserDoesNotExist"), "", SageMessageType.Alert);
                                    }
                                }
                                else
                                {
                                    ForgotPasswordInfo template = UserManagementController.GetMessageTemplateByMessageTemplateTypeID(SystemSetting.ACTIVATION_FAIL_INFORMATION, GetPortalID);
                                    if (template != null)
                                    {
                                        ACTIVATION_INFORMATION.Text = template.Body;
                                    };
                                }
                            }
                            else
                            {
                                ShowMessage("", GetSageMessage("UserRegistration", "ActivationCodeAlreadyUsed"), "", SageMessageType.Alert);
                            }
                        }
                        else
                        {
                            ShowMessage("", GetSageMessage("UserManagement", "UserDoesNotExist"), "", SageMessageType.Alert);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ProcessException(ex);
                }
            }
        }
 protected void wzdPasswordRecover_NextButtonClick(object sender, WizardNavigationEventArgs e)
 {
     try
     {
         if (txtPassword.Text != null && txtRetypePassword.Text != "" && txtRetypePassword.Text == txtPassword.Text)
         {
             if (txtPassword.Text.Length < 4)
             {
                 ShowMessage("", GetSageMessage("PasswordRecovery", "PasswordLength"), "", SageMessageType.Alert);
                 e.Cancel = true;
             }
             else
             {
                 if (hdnRecoveryCode.Value != "")
                 {
                     sageframeuser = UserManagementController.GetUsernameByActivationOrRecoveryCode(hdnRecoveryCode.Value, GetPortalID);
                     if (sageframeuser.CodeForUsername != null)
                     {
                         UserInfo userOld = m.GetUserDetails(GetPortalID, sageframeuser.CodeForUsername);
                         string Password, PasswordSalt;
                         PasswordHelper.EnforcePasswordSecurity(m.PasswordFormat, txtPassword.Text, out Password, out PasswordSalt);
                         UserInfo user = new UserInfo(userOld.UserID, Password, PasswordSalt, m.PasswordFormat);
                         m.ChangePassword(user);
                         List<ForgotPasswordInfo> messageTemplates = UserManagementController.GetMessageTemplateListByMessageTemplateTypeID(SystemSetting.PASSWORD_RECOVERED_SUCCESSFUL_EMAIL, GetPortalID);
                         foreach (ForgotPasswordInfo messageTemplate in messageTemplates)
                         {
                             DataTable dtTokenValues = UserManagementController.GetPasswordRecoverySuccessfulTokenValue(userOld.UserName, GetPortalID);
                             string replacedMessageSubject = MessageToken.ReplaceAllMessageToken(messageTemplate.Subject, dtTokenValues);
                             string replacedMessageTemplate = MessageToken.ReplaceAllMessageToken(messageTemplate.Body, dtTokenValues);
                             try
                             {
                                 MailHelper.SendMailNoAttachment(messageTemplate.MailFrom, userOld.Email, replacedMessageSubject, replacedMessageTemplate, string.Empty, string.Empty);
                             }
                             catch (Exception)
                             {
                                 ShowMessage("", GetSageMessage("PasswordRecovery", "SecureConnectionFPRError"), "", SageMessageType.Alert);
                                 e.Cancel = true;
                                 divRecoverpwd.Visible = false;
                             }
                         }
                         UserManagementController.DeactivateRecoveryCode(userOld.UserName, GetPortalID);
                         ForgotPasswordInfo template = UserManagementController.GetMessageTemplateByMessageTemplateTypeID(SystemSetting.PASSWORD_RECOVERED_SUCESSFUL_INFORMATION, GetPortalID);
                         if (template != null)
                         {
                             ((Literal)WizardStep2.FindControl("litPasswordChangedSuccessful")).Text = template.Body;
                         }
                     }
                     else
                     {
                         e.Cancel = true;
                         ShowMessage("", GetSageMessage("PasswordRecovery", "UnknownErrorPleaseTryAgaing"), "", SageMessageType.Alert);
                     }
                 }
                 else
                 {
                     e.Cancel = true;
                     ShowMessage("", GetSageMessage("PasswordRecovery", "UnknownError"), "", SageMessageType.Alert);
                 }
             }
         }
         else
         {
             ShowMessage("", GetSageMessage("PasswordRecovery", "PleaseEnterAllRequiredFields"), "", SageMessageType.Alert);
             e.Cancel = true;
         }
     }
     catch (Exception ex)
     {
         ProcessException(ex);
     }
 }