/// <summary>
        /// Records the and send request.
        /// </summary>
        /// <param name="userId">The user id.</param>
        /// <param name="username">The username.</param>
        /// <param name="email">The email.</param>
        private void RecordAndSendRequest(UserInfo user)
        {
            double ExpiryTime = 2;

            if (Settings["ExpiryTime"] != null)
            {
                ExpiryTime = Convert.ToDouble(Settings["ExpiryTime"]);
            }

            var myRequest = new PasswordResetRequest
            {
                PortalId       = PortalId,
                UserId         = user.UserID,
                ExpirationDate = DateTime.Now.AddHours(ExpiryTime),
                RecoveryCode   = Guid.NewGuid().ToString()
            };

            myRequest = PasswordRecoveryController.InsertRequest(myRequest);
            var notificationEmail = new StringBuilder(Localization.GetString("ResetEmail", LocalResourceFile));

            notificationEmail.Replace("[PORTALNAME]", PortalSettings.PortalName);
            notificationEmail.Replace("[FIRSTNAME]", !string.IsNullOrEmpty(user.FirstName) ? user.FirstName : user.Username);
            notificationEmail.Replace("[LASTNAME]", !string.IsNullOrEmpty(user.LastName) ? user.LastName : string.Empty);
            notificationEmail.Replace("[DISPLAYNAME]", !string.IsNullOrEmpty(user.DisplayName) ? user.DisplayName : user.Username);

            notificationEmail.Replace("[USERNAME]", user.Username);
            var url = UrlUtility.GenerateResetUrl(TabId, myRequest.RecoveryCode);

            if (!url.ToLower().StartsWith("http"))
            {
                url = "http://" + PortalSettings.PortalAlias.HTTPAlias + url;
            }


            notificationEmail.Replace("[RESETLINK]", url);
            notificationEmail.Replace("[CODE]", myRequest.RecoveryCode);


            url = UrlUtility.GetPortalUrl(PortalSettings.HomeTabId);
            notificationEmail.Replace("[PORTALURL]", url);


            try
            {
                Mail.SendMail(PortalSettings.Email, user.Email, string.Empty,
                              Localization.GetString("ResetEmailSubject", LocalResourceFile),
                              notificationEmail.ToString(), string.Empty, "HTML", string.Empty, string.Empty,
                              string.Empty, string.Empty);
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
            }
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    var oConfig = new SettingsManager(Settings);
                    if (oConfig.IsConfigured)
                    {
                        if (!oConfig.CaptchaEnabled)
                        {
                            divCaptchaRequest.Visible = false;
                            divCaptchaReset.Visible   = false;
                        }
                        if (Request.QueryString["mode"] != null)
                        {
                            //Toggle view and pre-load code if needed
                            pnlPerformReset.Visible         = true;
                            pnlRequestPasswordReset.Visible = false;

                            if (Request.QueryString["code"] != null)
                            {
                                txtResetCode.Text = Request.QueryString["code"];
                            }
                        }
                        else
                        {
                            //Localize the single display item needed
                            litAlreadyReceived.Text =
                                Localization.GetString("AlreadyReceived", LocalResourceFile).Replace("[RESETURL]",
                                                                                                     UrlUtility.
                                                                                                     GenerateResetUrl
                                                                                                     (
                                                                                                         TabId));
                        }
                    }
                    else
                    {
                        pnlRequestPasswordReset.Visible = false;
                        Skin.AddModuleMessage(this, "Not Configured",
                                              ModuleMessage.ModuleMessageType.YellowWarning);
                    }
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }