Пример #1
0
        protected void btnResetPassword_Click(object sender, EventArgs e)
        {
            // reset password...
            try
            {
                MembershipUser user = UserMembershipHelper.GetMembershipUserById(CurrentUserID.Value);

                if (user != null)
                {
                    // reset the password...
                    user.UnlockUser();
                    string newPassword = user.ResetPassword();

                    // email a notification...
                    YafTemplateEmail passwordRetrieval = new YafTemplateEmail("PASSWORDRETRIEVAL");

                    string subject = this.PageContext.Localization.GetText("RECOVER_PASSWORD", "PASSWORDRETRIEVAL_EMAIL_SUBJECT").FormatWith(this.PageContext.BoardSettings.Name);

                    passwordRetrieval.TemplateParams["{username}"]  = user.UserName;
                    passwordRetrieval.TemplateParams["{password}"]  = newPassword;
                    passwordRetrieval.TemplateParams["{forumname}"] = PageContext.BoardSettings.Name;
                    passwordRetrieval.TemplateParams["{forumlink}"] = "{0}".FormatWith(YafForumInfo.ForumURL);

                    passwordRetrieval.SendEmail(new System.Net.Mail.MailAddress(user.Email, user.UserName), subject, true);

                    PageContext.AddLoadMessage("User Password Reset and Notification Email Sent");
                }
            }
            catch (Exception x)
            {
                PageContext.AddLoadMessage("Exception: " + x.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// The page_ load.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e)
        {
            if (this.Get <HttpRequestBase>().QueryString["t"] == null || !this.PageContext.ForumReadAccess ||
                !this.PageContext.BoardSettings.AllowEmailTopic)
            {
                YafBuildLink.AccessDenied();
            }

            if (!this.IsPostBack)
            {
                if (this.PageContext.Settings.LockedForum == 0)
                {
                    this.PageLinks.AddLink(this.PageContext.BoardSettings.Name, YafBuildLink.GetLink(ForumPages.forum));
                    this.PageLinks.AddLink(
                        this.PageContext.PageCategoryName,
                        YafBuildLink.GetLink(ForumPages.forum, "c={0}", this.PageContext.PageCategoryID));
                }

                this.PageLinks.AddForum(this.PageContext.PageForumID);
                this.PageLinks.AddLink(
                    this.PageContext.PageTopicName, YafBuildLink.GetLink(ForumPages.posts, "t={0}", this.PageContext.PageTopicID));

                this.SendEmail.Text = this.GetText("send");

                this.Subject.Text = this.PageContext.PageTopicName;

                var emailTopic = new YafTemplateEmail();

                emailTopic.TemplateParams["{link}"] = YafBuildLink.GetLinkNotEscaped(
                    ForumPages.posts, true, "t={0}", this.PageContext.PageTopicID);
                emailTopic.TemplateParams["{user}"] = this.PageContext.PageUserName;

                this.Message.Text = emailTopic.ProcessTemplate("EMAILTOPIC");
            }
        }
Пример #3
0
        /// <summary>
        /// The send email verification.
        /// </summary>
        /// <param name="newEmail">
        /// The new email.
        /// </param>
        private void SendEmailVerification([NotNull] string newEmail)
        {
            string hashinput = DateTime.UtcNow + this.Email.Text + Security.CreatePassword(20);
            string hash      = FormsAuthentication.HashPasswordForStoringInConfigFile(hashinput, "md5");

            // Create Email
            var changeEmail = new YafTemplateEmail("CHANGEEMAIL");

            changeEmail.TemplateParams["{user}"] = this.PageContext.PageUserName;
            changeEmail.TemplateParams["{link}"] =
                "{0}\r\n\r\n".FormatWith(YafBuildLink.GetLinkNotEscaped(ForumPages.approve, true, "k={0}", hash));
            changeEmail.TemplateParams["{newemail}"]  = this.Email.Text;
            changeEmail.TemplateParams["{key}"]       = hash;
            changeEmail.TemplateParams["{forumname}"] = this.Get <YafBoardSettings>().Name;
            changeEmail.TemplateParams["{forumlink}"] = YafForumInfo.ForumURL;

            // save a change email reference to the db
            this.GetRepository <CheckEmail>().Save(this.currentUserID, hash, newEmail);

            // send a change email message...
            changeEmail.SendEmail(new MailAddress(newEmail), this.GetText("COMMON", "CHANGEEMAIL_SUBJECT"), true);

            // show a confirmation
            this.PageContext.AddLoadMessage(this.GetText("PROFILE", "mail_sent").FormatWith(this.Email.Text));
        }
Пример #4
0
		protected void Page_Load( object sender, System.EventArgs e )
		{
			if ( Request.QueryString ["t"] == null || !PageContext.ForumReadAccess || !PageContext.BoardSettings.AllowEmailTopic )
				YafBuildLink.AccessDenied();

			if ( !IsPostBack )
			{
				if ( PageContext.Settings.LockedForum == 0 )
				{
					PageLinks.AddLink( PageContext.BoardSettings.Name, YAF.Classes.Utils.YafBuildLink.GetLink( YAF.Classes.Utils.ForumPages.forum ) );
					PageLinks.AddLink( PageContext.PageCategoryName, YAF.Classes.Utils.YafBuildLink.GetLink( YAF.Classes.Utils.ForumPages.forum, "c={0}", PageContext.PageCategoryID ) );
				}

				PageLinks.AddForumLinks( PageContext.PageForumID );
				PageLinks.AddLink( PageContext.PageTopicName, YAF.Classes.Utils.YafBuildLink.GetLink( YAF.Classes.Utils.ForumPages.posts, "t={0}", PageContext.PageTopicID ) );

				SendEmail.Text = GetText( "send" );

				Subject.Text = PageContext.PageTopicName;

				YafTemplateEmail emailTopic = new YafTemplateEmail();

				emailTopic.TemplateParams ["{link}"] = String.Format( "{0}{1}", YAF.Classes.Utils.YafForumInfo.ServerURL, YAF.Classes.Utils.YafBuildLink.GetLinkNotEscaped( YAF.Classes.Utils.ForumPages.posts, "t={0}", PageContext.PageTopicID ) );
				emailTopic.TemplateParams ["{user}"] = PageContext.PageUserName;

				Message.Text = emailTopic.ProcessTemplate( "EMAILTOPIC" );
			}
		}
        /// <summary>
        /// The btn reset password_ click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void btnResetPassword_Click([NotNull] object sender, [NotNull] EventArgs e)
        {
            // reset password...
            try
            {
                MembershipUser user = UserMembershipHelper.GetMembershipUserById(this.CurrentUserID.Value);

                if (user != null)
                {
                    // reset the password...
                    user.UnlockUser();
                    string newPassword = user.ResetPassword();

                    // email a notification...
                    var passwordRetrieval = new YafTemplateEmail("PASSWORDRETRIEVAL");

                    string subject =
                        this.Get <ILocalization>().GetText("RECOVER_PASSWORD", "PASSWORDRETRIEVAL_EMAIL_SUBJECT").FormatWith(
                            this.PageContext.BoardSettings.Name);

                    passwordRetrieval.TemplateParams["{username}"]  = user.UserName;
                    passwordRetrieval.TemplateParams["{password}"]  = newPassword;
                    passwordRetrieval.TemplateParams["{forumname}"] = this.Get <YafBoardSettings>().Name;
                    passwordRetrieval.TemplateParams["{forumlink}"] = "{0}".FormatWith(YafForumInfo.ForumURL);

                    passwordRetrieval.SendEmail(new MailAddress(user.Email, user.UserName), subject, true);

                    this.PageContext.AddLoadMessage(this.Get <ILocalization>().GetText("ADMIN_EDITUSER", "MSG_PASS_RESET"));
                }
            }
            catch (Exception x)
            {
                this.PageContext.AddLoadMessage("Exception: {0}".FormatWith(x.Message));
            }
        }
Пример #6
0
        protected void PasswordRecovery1_SendingMail(object sender, MailMessageEventArgs e)
        {
            // get the username and password from the body
            string body = e.Message.Body;

            // remove first line...
            body = body.Remove(0, body.IndexOf('\n') + 1);
            // remove "Username: "******": ") + 2);
            // get first line which is the username
            string userName = body.Substring(0, body.IndexOf('\n'));

            // delete that same line...
            body = body.Remove(0, body.IndexOf('\n') + 1);
            // remove the "Password: "******": ") + 2);
            // the rest is the password...
            string password = body.Substring(0, body.IndexOf('\n'));

            // get the e-mail ready from the real template.
            YafTemplateEmail passwordRetrieval = new YafTemplateEmail("PASSWORDRETRIEVAL");

            string subject = String.Format(GetText("PASSWORDRETRIEVAL_EMAIL_SUBJECT"), PageContext.BoardSettings.Name);

            passwordRetrieval.TemplateParams["{username}"]  = userName;
            passwordRetrieval.TemplateParams["{password}"]  = password;
            passwordRetrieval.TemplateParams["{forumname}"] = PageContext.BoardSettings.Name;
            passwordRetrieval.TemplateParams["{forumlink}"] = String.Format("{0}", YafForumInfo.ForumURL);

            passwordRetrieval.SendEmail(e.Message.To[0], subject, true);

            // manually set to success...
            e.Cancel = true;
            PasswordRecovery1.TabIndex = 3;
        }
Пример #7
0
        /// <summary>
        /// The send registration notification email.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="userId">The user id.</param>
        private void SendRegistrationNotificationEmail([NotNull] MembershipUser user, int userId)
        {
            string[] emails = this.Get <YafBoardSettings>().NotificationOnUserRegisterEmailList.Split(';');

            var notifyAdmin = new YafTemplateEmail();

            string subject =
                this.GetText("COMMON", "NOTIFICATION_ON_USER_REGISTER_EMAIL_SUBJECT")
                .FormatWith(this.Get <YafBoardSettings>().Name);

            notifyAdmin.TemplateParams["{adminlink}"] = YafBuildLink.GetLinkNotEscaped(
                ForumPages.admin_edituser,
                true,
                "u={0}",
                userId);

            notifyAdmin.TemplateParams["{user}"]      = user.UserName;
            notifyAdmin.TemplateParams["{email}"]     = user.Email;
            notifyAdmin.TemplateParams["{forumname}"] = this.Get <YafBoardSettings>().Name;

            string emailBody = notifyAdmin.ProcessTemplate("NOTIFICATION_ON_USER_REGISTER");

            foreach (string email in emails.Where(email => email.Trim().IsSet()))
            {
                this.GetRepository <Mail>()
                .Create(this.Get <YafBoardSettings>().ForumEmail, email.Trim(), subject, emailBody);
            }
        }
Пример #8
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (Request.QueryString ["t"] == null || !PageContext.ForumReadAccess || !PageContext.BoardSettings.AllowEmailTopic)
            {
                YafBuildLink.AccessDenied();
            }

            if (!IsPostBack)
            {
                if (PageContext.Settings.LockedForum == 0)
                {
                    PageLinks.AddLink(PageContext.BoardSettings.Name, YAF.Classes.Utils.YafBuildLink.GetLink(YAF.Classes.Utils.ForumPages.forum));
                    PageLinks.AddLink(PageContext.PageCategoryName, YAF.Classes.Utils.YafBuildLink.GetLink(YAF.Classes.Utils.ForumPages.forum, "c={0}", PageContext.PageCategoryID));
                }

                PageLinks.AddForumLinks(PageContext.PageForumID);
                PageLinks.AddLink(PageContext.PageTopicName, YAF.Classes.Utils.YafBuildLink.GetLink(YAF.Classes.Utils.ForumPages.posts, "t={0}", PageContext.PageTopicID));

                SendEmail.Text = GetText("send");

                Subject.Text = PageContext.PageTopicName;

                YafTemplateEmail emailTopic = new YafTemplateEmail();

                emailTopic.TemplateParams ["{link}"] = String.Format("{0}{1}", YAF.Classes.Utils.YafForumInfo.ServerURL, YAF.Classes.Utils.YafBuildLink.GetLinkNotEscaped(YAF.Classes.Utils.ForumPages.posts, "t={0}", PageContext.PageTopicID));
                emailTopic.TemplateParams ["{user}"] = PageContext.PageUserName;

                Message.Text = emailTopic.ProcessTemplate("EMAILTOPIC");
            }
        }
Пример #9
0
        /// <summary>
        /// Handles the SendingMail event of the PasswordRecovery1 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="MailMessageEventArgs"/> instance containing the event data.</param>
        protected void PasswordRecovery1_SendingMail([NotNull] object sender, [NotNull] MailMessageEventArgs e)
        {
            // get the username and password from the body
            var body = e.Message.Body;

            // remove first line...
            body = body.Remove(0, body.IndexOf('\n') + 1);

            // remove "Username: "******": ", StringComparison.Ordinal) + 2);

            // get first line which is the username
            var userName = body.Substring(0, body.IndexOf('\n'));

            // delete that same line...
            body = body.Remove(0, body.IndexOf('\n') + 1);

            // remove the "Password: "******": ", StringComparison.Ordinal) + 2);

            // the rest is the password...
            var password = body.Substring(0, body.IndexOf('\n'));

            var subject = this.GetTextFormatted("PASSWORDRETRIEVAL_EMAIL_SUBJECT", this.Get <YafBoardSettings>().Name);
            var logoUrl =
                $"{YafForumInfo.ForumClientFileRoot}{YafBoardFolders.Current.Logos}/{this.PageContext.BoardSettings.ForumLogo}";
            var themeCss =
                $"{this.Get<YafBoardSettings>().BaseUrlMask}{this.Get<ITheme>().BuildThemePath("bootstrap-forum.min.css")}";

            var userIpAddress = this.Get <HttpRequestBase>().GetUserRealIPAddress();

            // get the e-mail ready from the real template.
            var passwordRetrieval = new YafTemplateEmail("PASSWORDRETRIEVAL")
            {
                TemplateParams =
                {
                    ["{username}"]  = userName,
                    ["{password}"]  = password,
                    ["{ipaddress}"] = userIpAddress,
                    ["{forumname}"] = this.Get <YafBoardSettings>().Name,
                    ["{forumlink}"] = $"{YafForumInfo.ForumURL}",
                    ["{themecss}"]  = themeCss,
                    ["{logo}"]      = $"{this.Get<YafBoardSettings>().BaseUrlMask}{logoUrl}"
                }
            };

            passwordRetrieval.SendEmail(e.Message.To[0], subject, true);

            // log password reset attempt
            this.Logger.Log(
                userName,
                $"{userName} Requested a Password Reset",
                $"The user {userName} with the IP address: '{userIpAddress}' requested a password reset.",
                EventLogTypes.Information);

            // manually set to success...
            e.Cancel = true;
            this.PasswordRecovery1.TabIndex = 3;
        }
Пример #10
0
        /// <summary>
        /// Send an Private Message to the Newly Created User with
        /// his Account Info (Pass, Security Question and Answer)
        /// </summary>
        /// <param name="user">
        /// The user.
        /// </param>
        /// <param name="pass">
        /// The pass.
        /// </param>
        /// <param name="securityAnswer">
        /// The security answer.
        /// </param>
        /// <param name="userId">
        /// The user Id.
        /// </param>
        /// <param name="oAuth">
        /// The oAUTH.
        /// </param>
        private static void SendRegistrationMessageToTwitterUser(
            [NotNull] MembershipUser user,
            [NotNull] string pass,
            [NotNull] string securityAnswer,
            [NotNull] int userId,
            OAuthTwitter oAuth)
        {
            var notifyUser = new YafTemplateEmail();

            string subject =
                YafContext.Current.Get <ILocalization>()
                .GetText("COMMON", "NOTIFICATION_ON_NEW_FACEBOOK_USER_SUBJECT")
                .FormatWith(YafContext.Current.Get <YafBoardSettings>().Name);

            notifyUser.TemplateParams["{user}"]      = user.UserName;
            notifyUser.TemplateParams["{email}"]     = user.Email;
            notifyUser.TemplateParams["{pass}"]      = pass;
            notifyUser.TemplateParams["{answer}"]    = securityAnswer;
            notifyUser.TemplateParams["{forumname}"] = YafContext.Current.Get <YafBoardSettings>().Name;

            string emailBody = notifyUser.ProcessTemplate("NOTIFICATION_ON_TWITTER_REGISTER");

            var messageFlags = new MessageFlags {
                IsHtml = false, IsBBCode = true
            };

            // Send Message also as DM to Twitter.
            var tweetApi = new TweetAPI(oAuth);

            var message = "{0}. {1}".FormatWith(
                subject,
                YafContext.Current.Get <ILocalization>().GetText("LOGIN", "TWITTER_DM"));

            if (YafContext.Current.Get <YafBoardSettings>().AllowPrivateMessages)
            {
                LegacyDb.pmessage_save(2, userId, subject, emailBody, messageFlags.BitValue, -1);
            }
            else
            {
                message = YafContext.Current.Get <ILocalization>()
                          .GetTextFormatted(
                    "LOGIN",
                    "TWITTER_DM_ACCOUNT",
                    YafContext.Current.Get <YafBoardSettings>().Name,
                    user.UserName,
                    pass);
            }

            try
            {
                tweetApi.SendDirectMessage(TweetAPI.ResponseFormat.json, user.UserName, message.Truncate(140));
            }
            catch (Exception ex)
            {
                YafContext.Current.Get <ILogger>().Error(ex, "Error while sending Twitter DM Message");
            }
        }
Пример #11
0
        /// <summary>
        /// The btn change password_ click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void btnChangePassword_Click([NotNull] object sender, [NotNull] EventArgs e)
        {
            if (!this.Page.IsValid)
            {
                return;
            }

            // change password...
            try
            {
                var user = UserMembershipHelper.GetMembershipUserById(this.CurrentUserID.Value);

                if (user == null)
                {
                    return;
                }

                // new password...
                var newPass = this.txtNewPassword.Text.Trim();

                // reset the password...
                user.UnlockUser();
                var tempPass = user.ResetPassword();

                // change to new password...
                user.ChangePassword(tempPass, newPass);

                if (this.chkEmailNotify.Checked)
                {
                    // email a notification...
                    var passwordRetrieval = new YafTemplateEmail("PASSWORDRETRIEVAL");

                    var subject = string.Format(
                        this.Get <ILocalization>().GetText("RECOVER_PASSWORD", "PASSWORDRETRIEVAL_EMAIL_SUBJECT"),
                        this.PageContext.BoardSettings.Name);

                    passwordRetrieval.TemplateParams["{username}"]  = user.UserName;
                    passwordRetrieval.TemplateParams["{password}"]  = newPass;
                    passwordRetrieval.TemplateParams["{forumname}"] = this.Get <YafBoardSettings>().Name;
                    passwordRetrieval.TemplateParams["{forumlink}"] = $"{YafForumInfo.ForumURL}";

                    passwordRetrieval.SendEmail(new MailAddress(user.Email, user.UserName), subject, true);

                    this.PageContext.AddLoadMessage(
                        this.Get <ILocalization>().GetText("ADMIN_EDITUSER", "MSG_PASS_CHANGED_NOTI"));
                }
                else
                {
                    this.PageContext.AddLoadMessage(
                        this.Get <ILocalization>().GetText("ADMIN_EDITUSER", "MSG_PASS_CHANGED"));
                }
            }
            catch (Exception x)
            {
                this.PageContext.AddLoadMessage($"Exception: {x.Message}");
            }
        }
Пример #12
0
        /// <summary>
        /// Handles the SendingMail event of the PasswordRecovery1 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="MailMessageEventArgs"/> instance containing the event data.</param>
        protected void PasswordRecovery1_SendingMail([NotNull] object sender, [NotNull] MailMessageEventArgs e)
        {
            // get the username and password from the body
            var body = e.Message.Body;

            // remove first line...
            body = body.Remove(0, body.IndexOf('\n') + 1);

            // remove "Username: "******": ", StringComparison.Ordinal) + 2);

            // get first line which is the username
            var userName = body.Substring(0, body.IndexOf('\n'));

            // delete that same line...
            body = body.Remove(0, body.IndexOf('\n') + 1);

            // remove the "Password: "******": ", StringComparison.Ordinal) + 2);

            // the rest is the password...
            var password = body.Substring(0, body.IndexOf('\n'));

            // get the e-mail ready from the real template.
            var passwordRetrieval = new YafTemplateEmail("PASSWORDRETRIEVAL");

            var subject = this.GetTextFormatted("PASSWORDRETRIEVAL_EMAIL_SUBJECT", this.Get <YafBoardSettings>().Name);

            var userIpAddress = this.Get <HttpRequestBase>().GetUserRealIPAddress();

            passwordRetrieval.TemplateParams["{username}"]  = userName;
            passwordRetrieval.TemplateParams["{password}"]  = password;
            passwordRetrieval.TemplateParams["{ipaddress}"] = userIpAddress;
            passwordRetrieval.TemplateParams["{forumname}"] = this.Get <YafBoardSettings>().Name;
            passwordRetrieval.TemplateParams["{forumlink}"] = "{0}".FormatWith(YafForumInfo.ForumURL);

            passwordRetrieval.SendEmail(e.Message.To[0], subject, true);

            // log password reset attempt
            this.Logger.Log(
                userName,
                "{0} Requested a Password Reset".FormatWith(userName),
                "The user {0} with the IP address: '{1}' requested a password reset.".FormatWith(
                    userName,
                    userIpAddress),
                EventLogTypes.Information);

            // manually set to success...
            e.Cancel = true;
            this.PasswordRecovery1.TabIndex = 3;
        }
        /// <summary>
        /// Reset the User Password
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void btnResetPassword_Click([NotNull] object sender, [NotNull] EventArgs e)
        {
            // reset password...
            try
            {
                var user = UserMembershipHelper.GetMembershipUserById(this.CurrentUserID.Value);

                if (user == null)
                {
                    return;
                }

                // reset the password...
                user.UnlockUser();
                var newPassword = user.ResetPassword();

                var subject = this.GetTextFormatted(
                    "PASSWORDRETRIEVAL_EMAIL_SUBJECT",
                    this.Get <YafBoardSettings>().Name);
                var logoUrl =
                    $"{YafForumInfo.ForumClientFileRoot}{YafBoardFolders.Current.Logos}/{this.PageContext.BoardSettings.ForumLogo}";
                var themeCss =
                    $"{this.Get<YafBoardSettings>().BaseUrlMask}{this.Get<ITheme>().BuildThemePath("bootstrap-forum.min.css")}";

                // email a notification...
                var passwordRetrieval = new YafTemplateEmail("PASSWORDRETRIEVAL_ADMIN")
                {
                    TemplateParams =
                    {
                        ["{username}"]  = user.UserName,
                        ["{password}"]  = newPassword,
                        ["{forumname}"] = this.Get <YafBoardSettings>().Name,
                        ["{forumlink}"] = YafForumInfo.ForumURL,
                        ["{themecss}"]  = themeCss,
                        ["{logo}"]      =
                            $"{this.Get<YafBoardSettings>().BaseUrlMask}{logoUrl}"
                    }
                };

                passwordRetrieval.SendEmail(new MailAddress(user.Email, user.UserName), subject, true);

                this.PageContext.AddLoadMessage(
                    this.Get <ILocalization>().GetText("ADMIN_EDITUSER", "MSG_PASS_RESET"),
                    MessageTypes.success);
            }
            catch (Exception x)
            {
                this.PageContext.AddLoadMessage($"Exception: {x.Message}", MessageTypes.danger);
            }
        }
Пример #14
0
        /// <summary>
        /// Sends a spam bot notification to admins.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="userId">The user id.</param>
        private void SendSpamBotNotificationToAdmins([NotNull] MembershipUser user, int userId)
        {
            // Get Admin Group ID
            var adminGroupID = 1;

            foreach (DataRow dataRow in
                     LegacyDb.group_list(this.PageContext.PageBoardID, null)
                     .Rows.Cast <DataRow>()
                     .Where(
                         dataRow =>
                         !dataRow["Name"].IsNullOrEmptyDBField() && dataRow.Field <string>("Name") == "Administrators")
                     )
            {
                adminGroupID = dataRow["GroupID"].ToType <int>();
                break;
            }

            using (DataTable dt = LegacyDb.user_emails(this.PageContext.PageBoardID, adminGroupID))
            {
                foreach (DataRow row in dt.Rows)
                {
                    var emailAddress = row.Field <string>("Email");

                    if (!emailAddress.IsSet())
                    {
                        continue;
                    }

                    var notifyAdmin = new YafTemplateEmail();

                    string subject =
                        this.GetText("COMMON", "NOTIFICATION_ON_BOT_USER_REGISTER_EMAIL_SUBJECT")
                        .FormatWith(this.Get <YafBoardSettings>().Name);

                    notifyAdmin.TemplateParams["{adminlink}"] = YafBuildLink.GetLinkNotEscaped(
                        ForumPages.admin_edituser,
                        true,
                        "u={0}",
                        userId);
                    notifyAdmin.TemplateParams["{user}"]      = user.UserName;
                    notifyAdmin.TemplateParams["{email}"]     = user.Email;
                    notifyAdmin.TemplateParams["{forumname}"] = this.Get <YafBoardSettings>().Name;

                    string emailBody = notifyAdmin.ProcessTemplate("NOTIFICATION_ON_BOT_USER_REGISTER");

                    this.GetRepository <Mail>()
                    .Create(this.Get <YafBoardSettings>().ForumEmail, emailAddress, subject, emailBody);
                }
            }
        }
Пример #15
0
        protected void Reset_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }

            // reset password...
            try
            {
                MembershipUser user = YAF.Classes.Utils.UserMembershipHelper.GetMembershipUser(CurrentUserID);

                if (user != null)
                {
                    // new password...
                    string newPass = txtNewPassword.Text.Trim();
                    // reset the password...
                    user.UnlockUser();
                    string tempPass = user.ResetPassword();
                    // change to new password...
                    user.ChangePassword(tempPass, newPass);

                    if (chkEmailNotify.Checked)
                    {
                        // email a notification...
                        YafTemplateEmail passwordRetrieval = new YafTemplateEmail("PASSWORDRETRIEVAL");

                        string subject = String.Format(PageContext.Localization.GetText("RECOVER_PASSWORD", "PASSWORDRETRIEVAL_EMAIL_SUBJECT"), PageContext.BoardSettings.Name);

                        passwordRetrieval.TemplateParams ["{username}"]  = user.UserName;
                        passwordRetrieval.TemplateParams ["{password}"]  = newPass;
                        passwordRetrieval.TemplateParams ["{forumname}"] = PageContext.BoardSettings.Name;
                        passwordRetrieval.TemplateParams ["{forumlink}"] = String.Format("{0}", YafForumInfo.ForumURL);

                        passwordRetrieval.SendEmail(new System.Net.Mail.MailAddress(user.Email, user.UserName), subject, true);

                        PageContext.AddLoadMessage("User Password Reset and Notification Email Sent");
                    }
                    else
                    {
                        PageContext.AddLoadMessage("User Password Reset");
                    }
                }
            }
            catch (Exception x)
            {
                PageContext.AddLoadMessage("Exception: " + x.Message);
            }
        }
Пример #16
0
        protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        {
            MembershipUser user = Membership.GetUser(CreateUserWizard1.UserName);

            // setup inital roles (if any) for this user
            RoleMembershipHelper.SetupUserRoles(YafContext.Current.PageBoardID, CreateUserWizard1.UserName);

            // create the user in the YAF DB as well as sync roles...
            int?userID = RoleMembershipHelper.CreateForumUser(user, YafContext.Current.PageBoardID);

            // create empty profile just so they have one
            YafUserProfile userProfile = PageContext.GetProfile(CreateUserWizard1.UserName);

            // setup their inital profile information
            userProfile.Save();

            if (userID == null)
            {
                // something is seriously wrong here -- redirect to failure...
                YafBuildLink.Redirect(ForumPages.info, "i=7");
            }

            // handle e-mail verification if needed
            if (PageContext.BoardSettings.EmailVerification)
            {
                // get the user email
                TextBox emailTextBox = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email");
                string  email        = emailTextBox.Text.Trim();

                string hashinput = DateTime.Now.ToString() + email + Security.CreatePassword(20);
                string hash      = FormsAuthentication.HashPasswordForStoringInConfigFile(hashinput, "md5");

                // save verification record...
                YAF.Classes.Data.DB.checkemail_save(userID, hash, user.Email);

                YafTemplateEmail verifyEmail = new YafTemplateEmail("VERIFYEMAIL");

                string subject = String.Format(GetText("VERIFICATION_EMAIL_SUBJECT"), PageContext.BoardSettings.Name);

                verifyEmail.TemplateParams ["{link}"]      = String.Format("{1}{0}", YafBuildLink.GetLinkNotEscaped(ForumPages.approve, "k={0}", hash), YafForumInfo.ServerURL);
                verifyEmail.TemplateParams ["{key}"]       = hash;
                verifyEmail.TemplateParams ["{forumname}"] = PageContext.BoardSettings.Name;
                verifyEmail.TemplateParams ["{forumlink}"] = String.Format("{0}", YafForumInfo.ForumURL);

                verifyEmail.SendEmail(new System.Net.Mail.MailAddress(email, user.UserName), subject, true);
            }
        }
Пример #17
0
        /// <summary>
        /// The password recovery 1_ verifying user.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void PasswordRecovery1_VerifyingUser(object sender, LoginCancelEventArgs e)
        {
            MembershipUser user = PageContext.CurrentMembership.GetUser(this.PasswordRecovery1.UserName, false);

            if (user != null)
            {
                // verify the user is approved, etc...
                if (!user.IsApproved)
                {
                    if (PageContext.BoardSettings.EmailVerification)
                    {
                        // get the hash from the db associated with this user...
                        DataTable dt = DB.checkemail_list(user.Email);

                        if (dt.Rows.Count > 0)
                        {
                            string hash = dt.Rows[0]["hash"].ToString();

                            // re-send verification email instead of lost password...
                            var verifyEmail = new YafTemplateEmail("VERIFYEMAIL");

                            string subject = GetTextFormatted("VERIFICATION_EMAIL_SUBJECT", PageContext.BoardSettings.Name);

                            verifyEmail.TemplateParams["{link}"]      = YafBuildLink.GetLinkNotEscaped(ForumPages.approve, true, "k={0}", hash);
                            verifyEmail.TemplateParams["{key}"]       = hash;
                            verifyEmail.TemplateParams["{forumname}"] = PageContext.BoardSettings.Name;
                            verifyEmail.TemplateParams["{forumlink}"] = "{0}".FormatWith(YafForumInfo.ForumURL);

                            verifyEmail.SendEmail(new MailAddress(user.Email, user.UserName), subject, true);

                            PageContext.LoadMessage.AddSession(PageContext.Localization.GetTextFormatted("ACCOUNT_NOT_APPROVED_VERIFICATION", user.Email));
                        }
                    }
                    else
                    {
                        // explain they are not approved yet...
                        PageContext.LoadMessage.AddSession(PageContext.Localization.GetText("ACCOUNT_NOT_APPROVED"));
                    }

                    // just in case cancel the verification...
                    e.Cancel = true;

                    // nothing they can do here... redirect to login...
                    YafBuildLink.Redirect(ForumPages.login);
                }
            }
        }
Пример #18
0
        /// <summary>
        /// The send verification email.
        /// </summary>
        /// <param name="user">
        /// The user.
        /// </param>
        /// <param name="userID">
        /// The user id.
        /// </param>
        private void SendVerificationEmail(MembershipUser user, int?userID)
        {
            var    emailTextBox = (TextBox)this.CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email");
            string email        = emailTextBox.Text.Trim();

            string hashinput = DateTime.UtcNow + email + Security.CreatePassword(20);
            string hash      = FormsAuthentication.HashPasswordForStoringInConfigFile(hashinput, "md5");

            // save verification record...
            DB.checkemail_save(userID, hash, user.Email);

            var verifyEmail = new YafTemplateEmail("VERIFYEMAIL");

            string subject = this.GetTextFormatted("VERIFICATION_EMAIL_SUBJECT", this.PageContext.BoardSettings.Name);

            verifyEmail.TemplateParams["{link}"]      = YafBuildLink.GetLinkNotEscaped(ForumPages.approve, true, "k={0}", hash);
            verifyEmail.TemplateParams["{key}"]       = hash;
            verifyEmail.TemplateParams["{forumname}"] = this.PageContext.BoardSettings.Name;
            verifyEmail.TemplateParams["{forumlink}"] = "{0}".FormatWith(YafForumInfo.ForumURL);
            verifyEmail.TemplateParams["{username}"]  = user.UserName;

            verifyEmail.SendEmail(new MailAddress(email, user.UserName), subject, true);
        }
Пример #19
0
        /// <summary>
        /// The send verification email.
        /// </summary>
        /// <param name="haveServiceLocator">
        /// The have service locator.
        /// </param>
        /// <param name="user"></param>
        public static void SendVerificationEmail(
            [NotNull] this IHaveServiceLocator haveServiceLocator, [NotNull] MembershipUser user, [NotNull] string email, int?userID, string newUsername = null)
        {
            CodeContracts.VerifyNotNull(email, "email");
            CodeContracts.VerifyNotNull(user, "user");
            CodeContracts.VerifyNotNull(haveServiceLocator, "haveServiceLocator");

            string hashinput = DateTime.UtcNow + email + Security.CreatePassword(20);
            string hash      = FormsAuthentication.HashPasswordForStoringInConfigFile(hashinput, "md5");

            // save verification record...
            haveServiceLocator.GetRepository <CheckEmail>().Save(userID, hash, user.Email);

            var verifyEmail = new YafTemplateEmail("VERIFYEMAIL");

            string subject = haveServiceLocator.Get <ILocalization>().GetTextFormatted("VERIFICATION_EMAIL_SUBJECT", haveServiceLocator.Get <YafBoardSettings>().Name);

            verifyEmail.TemplateParams["{link}"]      = YafBuildLink.GetLinkNotEscaped(ForumPages.approve, true, "k={0}", hash);
            verifyEmail.TemplateParams["{key}"]       = hash;
            verifyEmail.TemplateParams["{forumname}"] = haveServiceLocator.Get <YafBoardSettings>().Name;
            verifyEmail.TemplateParams["{forumlink}"] = "{0}".FormatWith(YafForumInfo.ForumURL);

            verifyEmail.SendEmail(new MailAddress(email, newUsername ?? user.UserName), subject, true);
        }
Пример #20
0
        /// <summary>
        /// The send registration notification email.
        /// </summary>
        /// <param name="user">
        /// The user.
        /// </param>
        private void SendRegistrationNotificationEmail(MembershipUser user)
        {
            string[] emails = this.PageContext.BoardSettings.NotificationOnUserRegisterEmailList.Split(';');

            var notifyAdmin = new YafTemplateEmail();

            string subject =
                this.PageContext.Localization.GetText("COMMON", "NOTIFICATION_ON_USER_REGISTER_EMAIL_SUBJECT").FormatWith(this.PageContext.BoardSettings.Name);

            notifyAdmin.TemplateParams["{adminlink}"] = YafBuildLink.GetLinkNotEscaped(ForumPages.admin_admin, true);
            notifyAdmin.TemplateParams["{user}"]      = user.UserName;
            notifyAdmin.TemplateParams["{email}"]     = user.Email;
            notifyAdmin.TemplateParams["{forumname}"] = this.PageContext.BoardSettings.Name;

            string emailBody = notifyAdmin.ProcessTemplate("NOTIFICATION_ON_USER_REGISTER");

            foreach (string email in emails)
            {
                if (email.Trim().IsSet())
                {
                    this.Get <YafSendMail>().Queue(this.PageContext.BoardSettings.ForumEmail, email.Trim(), subject, emailBody);
                }
            }
        }
Пример #21
0
        /// <summary>
        /// Sends notification about new PM in user's inbox.
        /// </summary>
        /// <param name="toUserID">User supposed to receive notification about new PM.</param>
        /// <param name="subject">Subject of PM user is notified about.</param>
        private void SendPMNotification(int toUserID, string subject)
        {
            /// TODO : add email to email queue?

            try
            {
                // user's PM notification setting
                bool pmNotificationAllowed;
                // user's email
                string toEMail;

                // read user's info from DB
                using (DataTable dt = DB.user_list(PageContext.PageBoardID, toUserID, true))
                {
                    pmNotificationAllowed = ( bool )dt.Rows [0] ["PMNotification"];
                    toEMail = ( string )dt.Rows [0] ["EMail"];
                }

                if (pmNotificationAllowed)
                {
                    // user has PM notification set on

                    int userPMessageID;
                    //string senderEmail;

                    // get the PM ID
                    // Ederon : 11/21/2007 - PageBoardID as parameter of DB.pmessage_list?
                    // using (DataTable dt = DB.pmessage_list(toUserID, PageContext.PageBoardID, null))
                    using (DataTable dt = DB.pmessage_list(toUserID, null, null))
                        userPMessageID = ( int )dt.Rows [0] ["UserPMessageID"];

                    // get the sender e-mail -- DISABLED: too much information...
                    //using ( DataTable dt = YAF.Classes.Data.DB.user_list( PageContext.PageBoardID, PageContext.PageUserID, true ) )
                    //	senderEmail = ( string ) dt.Rows [0] ["Email"];

                    // send this user a PM notification e-mail
                    YafTemplateEmail pmNotification = new YafTemplateEmail("PMNOTIFICATION");

                    pmNotification.TemplateLanguageFile = UserHelper.GetUserLanguageFile(toUserID);

                    // fill the template with relevant info
                    pmNotification.TemplateParams ["{fromuser}"]  = PageContext.PageUserName;
                    pmNotification.TemplateParams ["{link}"]      = String.Format("{1}{0}\r\n\r\n", YafBuildLink.GetLinkNotEscaped(ForumPages.cp_message, "pm={0}", userPMessageID), YafForumInfo.ServerURL);
                    pmNotification.TemplateParams ["{forumname}"] = PageContext.BoardSettings.Name;
                    pmNotification.TemplateParams ["{subject}"]   = subject;

                    // create notification email subject
                    string emailSubject = string.Format(GetText("COMMON", "PM_NOTIFICATION_SUBJECT"), PageContext.PageUserName, PageContext.BoardSettings.Name, subject);

                    // send email
                    pmNotification.SendEmail(new System.Net.Mail.MailAddress(toEMail), subject, true);
                }
            }
            catch (Exception x)
            {
                // report exception to the forum's event log
                DB.eventlog_create(PageContext.PageUserID, this, x);
                // tell user about failure
                PageContext.AddLoadMessage(String.Format(GetText("failed"), x.Message));
            }
        }
Пример #22
0
		/// <summary>
		/// Sends notification about new PM in user's inbox.
		/// </summary>
		/// <param name="toUserID">User supposed to receive notification about new PM.</param>
		/// <param name="subject">Subject of PM user is notified about.</param>
		private void SendPMNotification( int toUserID, string subject )
		{
			/// TODO : add email to email queue?

			try
			{
				// user's PM notification setting
				bool pmNotificationAllowed;
				// user's email
				string toEMail;

				// read user's info from DB
				using ( DataTable dt = DB.user_list( PageContext.PageBoardID, toUserID, true ) )
				{
					pmNotificationAllowed = ( bool )dt.Rows [0] ["PMNotification"];
					toEMail = ( string )dt.Rows [0] ["EMail"];
				}

				if ( pmNotificationAllowed )
				{
					// user has PM notification set on

					int userPMessageID;
					//string senderEmail;

					// get the PM ID
					// Ederon : 11/21/2007 - PageBoardID as parameter of DB.pmessage_list?
					// using (DataTable dt = DB.pmessage_list(toUserID, PageContext.PageBoardID, null))
					using ( DataTable dt = DB.pmessage_list( toUserID, null, null ) )
						userPMessageID = ( int )dt.Rows [0] ["UserPMessageID"];

					// get the sender e-mail -- DISABLED: too much information...
					//using ( DataTable dt = YAF.Classes.Data.DB.user_list( PageContext.PageBoardID, PageContext.PageUserID, true ) )
					//	senderEmail = ( string ) dt.Rows [0] ["Email"];

					// send this user a PM notification e-mail
					YafTemplateEmail pmNotification = new YafTemplateEmail( "PMNOTIFICATION" );

					pmNotification.TemplateLanguageFile = UserHelper.GetUserLanguageFile( toUserID );

					// fill the template with relevant info
					pmNotification.TemplateParams ["{fromuser}"] = PageContext.PageUserName;
					pmNotification.TemplateParams ["{link}"] = String.Format( "{1}{0}\r\n\r\n", YafBuildLink.GetLinkNotEscaped( ForumPages.cp_message, "pm={0}", userPMessageID ), YafForumInfo.ServerURL );
					pmNotification.TemplateParams ["{forumname}"] = PageContext.BoardSettings.Name;
					pmNotification.TemplateParams ["{subject}"] = subject;

					// create notification email subject
					string emailSubject = string.Format( GetText( "COMMON", "PM_NOTIFICATION_SUBJECT" ), PageContext.PageUserName, PageContext.BoardSettings.Name, subject );

					// send email
					pmNotification.SendEmail( new System.Net.Mail.MailAddress( toEMail ), subject, true );
				}
			}
			catch ( Exception x )
			{
				// report exception to the forum's event log
				DB.eventlog_create( PageContext.PageUserID, this, x );
				// tell user about failure
				PageContext.AddLoadMessage( String.Format( GetText( "failed" ), x.Message ) );
			}
		}
Пример #23
0
		protected void ForumRegister_Click( object sender, System.EventArgs e )
		{
			if ( Page.IsValid )
			{
				string newEmail = Email.Text.Trim();
				string newUsername = UserName.Text.Trim();

				if ( !General.IsValidEmail( newEmail ) )
				{
					PageContext.AddLoadMessage( "You have entered an illegal e-mail address." );
					return;
				}

				if ( UserMembershipHelper.UserExists( UserName.Text.Trim(), newEmail ) )
				{
					PageContext.AddLoadMessage( "Username or email are already registered." );
					return;
				}

				string hashinput = DateTime.Now.ToString() + newEmail + Security.CreatePassword( 20 );
				string hash = FormsAuthentication.HashPasswordForStoringInConfigFile( hashinput, "md5" );

				MembershipCreateStatus status;
				MembershipUser user = Membership.CreateUser( newUsername, Password.Text.Trim(), newEmail, Question.Text.Trim(), Answer.Text.Trim(), !PageContext.BoardSettings.EmailVerification, out status);

				if (status != MembershipCreateStatus.Success)
				{
					// error of some kind
					PageContext.AddLoadMessage( "Membership Error Creating User: "******"VERIFYEMAIL" );

					verifyEmail.TemplateParams ["{link}"] = String.Format( "{1}{0}", YAF.Classes.Utils.YafBuildLink.GetLink( YAF.Classes.Utils.ForumPages.approve, "k={0}", hash ), YAF.Classes.Utils.YafForumInfo.ServerURL );
					verifyEmail.TemplateParams ["{key}"] = hash;
					verifyEmail.TemplateParams ["{forumname}"] = PageContext.BoardSettings.Name;
					verifyEmail.TemplateParams ["{forumlink}"] = String.Format( "{0}", ForumURL );

					string subject = String.Format( PageContext.Localization.GetText( "COMMON", "EMAILVERIFICATION_SUBJECT" ), PageContext.BoardSettings.Name );

					verifyEmail.SendEmail( new System.Net.Mail.MailAddress( newEmail, newUsername ), subject, true);
				}

				// success
				PageContext.AddLoadMessage( string.Format( "User {0} Created Successfully.", UserName.Text.Trim() ) );
				YAF.Classes.Utils.YafBuildLink.Redirect( YAF.Classes.Utils.ForumPages.admin_reguser );
			}
		}
Пример #24
0
        /// <summary>
        /// The password recovery 1_ verifying user.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void PasswordRecovery1_VerifyingUser([NotNull] object sender, [NotNull] LoginCancelEventArgs e)
        {
            MembershipUser user = null;

            if (this.PasswordRecovery1.UserName.Contains("@") && this.Get <MembershipProvider>().RequiresUniqueEmail)
            {
                // Email Login
                var username = this.Get <MembershipProvider>().GetUserNameByEmail(this.PasswordRecovery1.UserName);
                if (username != null)
                {
                    user = this.Get <MembershipProvider>().GetUser(username, false);

                    // update the username
                    this.PasswordRecovery1.UserName = username;
                }
            }
            else
            {
                // Standard user name login
                if (this.Get <YafBoardSettings>().EnableDisplayName)
                {
                    // Display name login
                    var id = this.Get <IUserDisplayName>().GetId(this.PasswordRecovery1.UserName);

                    if (id.HasValue)
                    {
                        // get the username associated with this id...
                        var username = UserMembershipHelper.GetUserNameFromID(id.Value);

                        // update the username
                        this.PasswordRecovery1.UserName = username;
                    }

                    user = this.Get <MembershipProvider>().GetUser(this.PasswordRecovery1.UserName, false);
                }
            }

            if (user == null)
            {
                return;
            }

            // verify the user is approved, etc...
            if (user.IsApproved)
            {
                return;
            }

            if (this.Get <YafBoardSettings>().EmailVerification)
            {
                // get the hash from the db associated with this user...
                var checkTyped = this.GetRepository <CheckEmail>().ListTyped(user.Email).FirstOrDefault();

                if (checkTyped != null)
                {
                    // re-send verification email instead of lost password...
                    var verifyEmail = new YafTemplateEmail("VERIFYEMAIL");

                    string subject = this.GetTextFormatted("VERIFICATION_EMAIL_SUBJECT", this.Get <YafBoardSettings>().Name);

                    verifyEmail.TemplateParams["{link}"]      = YafBuildLink.GetLinkNotEscaped(ForumPages.approve, true, "k={0}", checkTyped.Hash);
                    verifyEmail.TemplateParams["{key}"]       = checkTyped.Hash;
                    verifyEmail.TemplateParams["{forumname}"] = this.Get <YafBoardSettings>().Name;
                    verifyEmail.TemplateParams["{forumlink}"] = "{0}".FormatWith(YafForumInfo.ForumURL);

                    verifyEmail.SendEmail(new MailAddress(user.Email, user.UserName), subject, true);

                    this.PageContext.LoadMessage.AddSession(
                        this.GetTextFormatted("ACCOUNT_NOT_APPROVED_VERIFICATION", user.Email), MessageTypes.Warning);
                }
            }
            else
            {
                // explain they are not approved yet...
                this.PageContext.LoadMessage.AddSession(this.GetText("ACCOUNT_NOT_APPROVED"), MessageTypes.Warning);
            }

            // just in case cancel the verification...
            e.Cancel = true;

            // nothing they can do here... redirect to login...
            YafBuildLink.Redirect(ForumPages.login);
        }
		protected void Reset_Click( object sender, EventArgs e )
		{
			if ( !Page.IsValid )
			{
				return;
			}

			// reset password...
			try
			{
				MembershipUser user = YAF.Classes.Utils.UserMembershipHelper.GetMembershipUser( CurrentUserID );

				if ( user != null )
				{
					// new password...
					string newPass = txtNewPassword.Text.Trim();
					// reset the password...
					user.UnlockUser();
					string tempPass = user.ResetPassword();
					// change to new password...
					user.ChangePassword( tempPass, newPass );

					if ( chkEmailNotify.Checked )
					{
						// email a notification...
						YafTemplateEmail passwordRetrieval = new YafTemplateEmail( "PASSWORDRETRIEVAL" );

						string subject = String.Format( PageContext.Localization.GetText( "RECOVER_PASSWORD", "PASSWORDRETRIEVAL_EMAIL_SUBJECT" ), PageContext.BoardSettings.Name );

						passwordRetrieval.TemplateParams ["{username}"] = user.UserName;
						passwordRetrieval.TemplateParams ["{password}"] = newPass;
						passwordRetrieval.TemplateParams ["{forumname}"] = PageContext.BoardSettings.Name;
						passwordRetrieval.TemplateParams ["{forumlink}"] = String.Format( "{0}", YafForumInfo.ForumURL );

						passwordRetrieval.SendEmail( new System.Net.Mail.MailAddress( user.Email, user.UserName ), subject, true );

						PageContext.AddLoadMessage( "User Password Reset and Notification Email Sent" );
					}
					else
					{
						PageContext.AddLoadMessage( "User Password Reset" );
					}
				}
			}
			catch ( Exception x )
			{
				PageContext.AddLoadMessage( "Exception: " + x.Message );
			}
		}
        protected void UpdateProfile_Click(object sender, System.EventArgs e)
        {
            if (HomePage.Text.Length > 0 && !HomePage.Text.StartsWith("http://"))
            {
                HomePage.Text = "http://" + HomePage.Text;
            }

            if (MSN.Text.Length > 0 && !General.IsValidEmail(MSN.Text))
            {
                PageContext.AddLoadMessage(PageContext.Localization.GetText("PROFILE", "BAD_MSN"));
                return;
            }
            if (HomePage.Text.Length > 0 && !General.IsValidURL(HomePage.Text))
            {
                PageContext.AddLoadMessage(PageContext.Localization.GetText("PROFILE", "BAD_HOME"));
                return;
            }
            if (Weblog.Text.Length > 0 && !General.IsValidURL(Weblog.Text))
            {
                PageContext.AddLoadMessage(PageContext.Localization.GetText("PROFILE", "BAD_WEBLOG"));
                return;
            }
            if (ICQ.Text.Length > 0 && !General.IsValidInt(ICQ.Text))
            {
                PageContext.AddLoadMessage(PageContext.Localization.GetText("PROFILE", "BAD_ICQ"));
                return;
            }

            if (UpdateEmailFlag)
            {
                string newEmail = Email.Text.Trim();

                if (!General.IsValidEmail(newEmail))
                {
                    PageContext.AddLoadMessage(PageContext.Localization.GetText("PROFILE", "BAD_EMAIL"));
                    return;
                }

                if (PageContext.BoardSettings.EmailVerification)
                {
                    string hashinput = DateTime.Now.ToString() + Email.Text + Security.CreatePassword(20);
                    string hash      = FormsAuthentication.HashPasswordForStoringInConfigFile(hashinput, "md5");

                    // Create Email
                    YafTemplateEmail changeEmail = new YafTemplateEmail("CHANGEEMAIL");

                    changeEmail.TemplateParams ["{user}"]      = PageContext.PageUserName;
                    changeEmail.TemplateParams ["{link}"]      = String.Format("{1}{0}\r\n\r\n", YAF.Classes.Utils.YafBuildLink.GetLinkNotEscaped(YAF.Classes.Utils.ForumPages.approve, "k={0}", hash), YafForumInfo.ServerURL);
                    changeEmail.TemplateParams ["{newemail}"]  = Email.Text;
                    changeEmail.TemplateParams ["{key}"]       = hash;
                    changeEmail.TemplateParams ["{forumname}"] = PageContext.BoardSettings.Name;
                    changeEmail.TemplateParams ["{forumlink}"] = YafForumInfo.ForumURL;

                    // save a change email reference to the db
                    YAF.Classes.Data.DB.checkemail_save(CurrentUserID, hash, newEmail);

                    //  send a change email message...
                    changeEmail.SendEmail(new System.Net.Mail.MailAddress(newEmail), PageContext.Localization.GetText("COMMON", "CHANGEEMAIL_SUBJECT"), true);

                    // show a confirmation
                    PageContext.AddLoadMessage(String.Format(PageContext.Localization.GetText("PROFILE", "mail_sent"), Email.Text));
                }
                else
                {
                    // just update the e-mail...
                    UserMembershipHelper.UpdateEmail(CurrentUserID, Email.Text.Trim());
                }
            }

            string userName = UserMembershipHelper.GetUserNameFromID(CurrentUserID);

            YafUserProfile userProfile = PageContext.GetProfile(userName);

            userProfile.Location            = Location.Text.Trim();
            userProfile.Homepage            = HomePage.Text.Trim();
            userProfile.MSN                 = MSN.Text.Trim();
            userProfile.YIM                 = YIM.Text.Trim();
            userProfile.AIM                 = AIM.Text.Trim();
            userProfile.ICQ                 = ICQ.Text.Trim();
            userProfile.Skype               = Skype.Text.Trim();
            userProfile.RealName            = Realname.Text.Trim();
            userProfile.Occupation          = Occupation.Text.Trim();
            userProfile.Interests           = Interests.Text.Trim();
            userProfile.Gender              = Gender.SelectedIndex;
            userProfile.Blog                = Weblog.Text.Trim();
            userProfile.BlogServiceUrl      = WeblogUrl.Text.Trim();
            userProfile.BlogServiceUsername = WeblogUsername.Text.Trim();
            userProfile.BlogServicePassword = WeblogID.Text.Trim();

            userProfile.Save();

            // save remaining settings to the DB
            YAF.Classes.Data.DB.user_save(CurrentUserID, PageContext.PageBoardID, null, null,
                                          Convert.ToInt32(TimeZones.SelectedValue), Language.SelectedValue, Theme.SelectedValue, OverrideDefaultThemes.Checked, null, PMNotificationEnabled.Checked);

            if (!AdminEditMode)
            {
                YAF.Classes.Utils.YafBuildLink.Redirect(YAF.Classes.Utils.ForumPages.cp_profile);
            }
            else
            {
                BindData();
            }
        }
		protected void PasswordRecovery1_VerifyingUser( object sender, LoginCancelEventArgs e )
		{			
			MembershipUser user = Membership.GetUser( PasswordRecovery1.UserName );

			if ( user != null )
			{
				// verify the user is approved, etc...
				if ( !user.IsApproved )
				{
					if ( PageContext.BoardSettings.EmailVerification )
					{						
						// get the hash from the db associated with this user...
						DataTable dt = DB.checkemail_list( user.Email );

						if ( dt.Rows.Count > 0 )
						{
							string hash = dt.Rows [0] ["hash"].ToString();

							// re-send verification email instead of lost password...
							YafTemplateEmail verifyEmail = new YafTemplateEmail( "VERIFYEMAIL" );

							string subject = String.Format( GetText( "VERIFICATION_EMAIL_SUBJECT" ), PageContext.BoardSettings.Name );

							verifyEmail.TemplateParams ["{link}"] = String.Format( "{1}{0}", YafBuildLink.GetLinkNotEscaped( ForumPages.approve, "k={0}", hash ), YafForumInfo.ServerURL );
							verifyEmail.TemplateParams ["{key}"] = hash;
							verifyEmail.TemplateParams ["{forumname}"] = PageContext.BoardSettings.Name;
							verifyEmail.TemplateParams ["{forumlink}"] = String.Format( "{0}", YafForumInfo.ForumURL );

							verifyEmail.SendEmail( new System.Net.Mail.MailAddress( user.Email, user.UserName ), subject, true );

							PageContext.AddLoadMessageSession( String.Format( PageContext.Localization.GetText( "ACCOUNT_NOT_APPROVED_VERIFICATION" ), user.Email ) );
						}
					}
					else
					{
						// explain they are not approved yet...
						PageContext.AddLoadMessageSession( PageContext.Localization.GetText( "ACCOUNT_NOT_APPROVED" ) );
					}

					// just in case cancel the verification...
					e.Cancel = true;

					// nothing they can do here... redirect to login...
					YafBuildLink.Redirect( ForumPages.login );
				}
			}
		}
Пример #28
0
		protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
		{
			MembershipUser user = Membership.GetUser(CreateUserWizard1.UserName);

			// setup inital roles (if any) for this user
			RoleMembershipHelper.SetupUserRoles(YafContext.Current.PageBoardID, CreateUserWizard1.UserName);

			// create the user in the YAF DB as well as sync roles...
			int? userID = RoleMembershipHelper.CreateForumUser(user, YafContext.Current.PageBoardID);

			// create empty profile just so they have one
			YafUserProfile userProfile = PageContext.GetProfile(CreateUserWizard1.UserName);
			// setup their inital profile information
			userProfile.Save();

			if (userID == null)
			{
				// something is seriously wrong here -- redirect to failure...
				YafBuildLink.Redirect(ForumPages.info, "i=7");
			}

			// handle e-mail verification if needed
			if (PageContext.BoardSettings.EmailVerification)
			{
				// get the user email
				TextBox emailTextBox = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email");
				string email = emailTextBox.Text.Trim();

				string hashinput = DateTime.Now.ToString() + email + Security.CreatePassword(20);
				string hash = FormsAuthentication.HashPasswordForStoringInConfigFile(hashinput, "md5");

				// save verification record...
				YAF.Classes.Data.DB.checkemail_save(userID, hash, user.Email);

				YafTemplateEmail verifyEmail = new YafTemplateEmail( "VERIFYEMAIL" );

				string subject = String.Format(GetText("VERIFICATION_EMAIL_SUBJECT"), PageContext.BoardSettings.Name);

				verifyEmail.TemplateParams ["{link}"] = String.Format( "{1}{0}", YafBuildLink.GetLinkNotEscaped( ForumPages.approve, "k={0}", hash ), YafForumInfo.ServerURL );
				verifyEmail.TemplateParams ["{key}"] = hash;
				verifyEmail.TemplateParams ["{forumname}"] = PageContext.BoardSettings.Name;
				verifyEmail.TemplateParams ["{forumlink}"] = String.Format("{0}", YafForumInfo.ForumURL);

				verifyEmail.SendEmail( new System.Net.Mail.MailAddress( email, user.UserName ), subject, true );
			}
		}
Пример #29
0
        /// <summary>
        /// Send an Private Message to the Newly Created User with
        /// his Account Info (Pass, Security Question and Answer)
        /// </summary>
        /// <param name="user">
        /// The user.
        /// </param>
        /// <param name="pass">
        /// The pass.
        /// </param>
        /// <param name="securityAnswer">
        /// The security answer.
        /// </param>
        /// <param name="userId">
        /// The user Id.
        /// </param>
        /// <param name="oAuth">
        /// The oAUTH.
        /// </param>
        private static void SendRegistrationMessageToTwitterUser(
            [NotNull] MembershipUser user, 
            [NotNull] string pass, 
            [NotNull] string securityAnswer, 
            [NotNull] int userId, 
            OAuthTwitter oAuth)
        {
            var notifyUser = new YafTemplateEmail();

            var subject =
                YafContext.Current.Get<ILocalization>()
                    .GetText("COMMON", "NOTIFICATION_ON_NEW_FACEBOOK_USER_SUBJECT")
                    .FormatWith(YafContext.Current.Get<YafBoardSettings>().Name);

            notifyUser.TemplateParams["{user}"] = user.UserName;
            notifyUser.TemplateParams["{email}"] = user.Email;
            notifyUser.TemplateParams["{pass}"] = pass;
            notifyUser.TemplateParams["{answer}"] = securityAnswer;
            notifyUser.TemplateParams["{forumname}"] = YafContext.Current.Get<YafBoardSettings>().Name;

            var emailBody = notifyUser.ProcessTemplate("NOTIFICATION_ON_TWITTER_REGISTER");

            var messageFlags = new MessageFlags { IsHtml = false, IsBBCode = true };

            // Send Message also as DM to Twitter.
            var tweetApi = new TweetAPI(oAuth);

            var message = "{0}. {1}".FormatWith(
                subject, 
                YafContext.Current.Get<ILocalization>().GetText("LOGIN", "TWITTER_DM"));

            if (YafContext.Current.Get<YafBoardSettings>().AllowPrivateMessages)
            {
                LegacyDb.pmessage_save(2, userId, subject, emailBody, messageFlags.BitValue, -1);
            }
            else
            {
                message = YafContext.Current.Get<ILocalization>()
                    .GetTextFormatted(
                        "LOGIN", 
                        "TWITTER_DM_ACCOUNT", 
                        YafContext.Current.Get<YafBoardSettings>().Name, 
                        user.UserName, 
                        pass);
            }

            try
            {
                tweetApi.SendDirectMessage(TweetAPI.ResponseFormat.json, user.UserName, message.Truncate(140));
            }
            catch (Exception ex)
            {
                YafContext.Current.Get<ILogger>().Error(ex, "Error while sending Twitter DM Message");
            }
        }
		protected void UpdateProfile_Click( object sender, System.EventArgs e )
		{
			if ( HomePage.Text.Length > 0 && !HomePage.Text.StartsWith( "http://" ) )
				HomePage.Text = "http://" + HomePage.Text;

			if ( MSN.Text.Length > 0 && !General.IsValidEmail( MSN.Text ) )
			{
				PageContext.AddLoadMessage( PageContext.Localization.GetText( "PROFILE", "BAD_MSN" ) );
				return;
			}
			if ( HomePage.Text.Length > 0 && !General.IsValidURL( HomePage.Text ) )
			{
				PageContext.AddLoadMessage( PageContext.Localization.GetText( "PROFILE", "BAD_HOME" ) );
				return;
			}
			if ( Weblog.Text.Length > 0 && !General.IsValidURL( Weblog.Text ) )
			{
				PageContext.AddLoadMessage( PageContext.Localization.GetText( "PROFILE", "BAD_WEBLOG" ) );
				return;
			}
			if ( ICQ.Text.Length > 0 && !General.IsValidInt( ICQ.Text ) )
			{
				PageContext.AddLoadMessage( PageContext.Localization.GetText( "PROFILE", "BAD_ICQ" ) );
				return;
			}

			if ( UpdateEmailFlag )
			{
				string newEmail = Email.Text.Trim();

				if ( !General.IsValidEmail( newEmail ) )
				{
					PageContext.AddLoadMessage( PageContext.Localization.GetText( "PROFILE", "BAD_EMAIL" ) );
					return;
				}

				if ( PageContext.BoardSettings.EmailVerification )
				{
					string hashinput = DateTime.Now.ToString() + Email.Text + Security.CreatePassword( 20 );
					string hash = FormsAuthentication.HashPasswordForStoringInConfigFile( hashinput, "md5" );

					// Create Email
					YafTemplateEmail changeEmail = new YafTemplateEmail( "CHANGEEMAIL" );

					changeEmail.TemplateParams ["{user}"] = PageContext.PageUserName;
					changeEmail.TemplateParams ["{link}"] = String.Format( "{1}{0}\r\n\r\n", YAF.Classes.Utils.YafBuildLink.GetLinkNotEscaped( YAF.Classes.Utils.ForumPages.approve, "k={0}", hash ), YafForumInfo.ServerURL );
					changeEmail.TemplateParams ["{newemail}"] = Email.Text;
					changeEmail.TemplateParams ["{key}"] = hash;
					changeEmail.TemplateParams ["{forumname}"] = PageContext.BoardSettings.Name;
					changeEmail.TemplateParams ["{forumlink}"] = YafForumInfo.ForumURL;

					// save a change email reference to the db
					YAF.Classes.Data.DB.checkemail_save( CurrentUserID, hash, newEmail );

					//  send a change email message...
					changeEmail.SendEmail( new System.Net.Mail.MailAddress( newEmail ), PageContext.Localization.GetText( "COMMON", "CHANGEEMAIL_SUBJECT" ), true );

					// show a confirmation
					PageContext.AddLoadMessage( String.Format( PageContext.Localization.GetText( "PROFILE", "mail_sent" ), Email.Text ) );
				}
				else
				{
					// just update the e-mail...
					UserMembershipHelper.UpdateEmail( CurrentUserID, Email.Text.Trim() );
				}
			}

			string userName = UserMembershipHelper.GetUserNameFromID( CurrentUserID );

			YafUserProfile userProfile = PageContext.GetProfile( userName );

			userProfile.Location = Location.Text.Trim();
			userProfile.Homepage = HomePage.Text.Trim();
			userProfile.MSN = MSN.Text.Trim();
			userProfile.YIM = YIM.Text.Trim();
			userProfile.AIM = AIM.Text.Trim();
			userProfile.ICQ = ICQ.Text.Trim();
			userProfile.Skype = Skype.Text.Trim();
			userProfile.RealName = Realname.Text.Trim();
			userProfile.Occupation = Occupation.Text.Trim();
			userProfile.Interests = Interests.Text.Trim();
			userProfile.Gender = Gender.SelectedIndex;
			userProfile.Blog = Weblog.Text.Trim();
			userProfile.BlogServiceUrl = WeblogUrl.Text.Trim();
			userProfile.BlogServiceUsername = WeblogUsername.Text.Trim();
			userProfile.BlogServicePassword = WeblogID.Text.Trim();

			userProfile.Save();

			// save remaining settings to the DB
			YAF.Classes.Data.DB.user_save( CurrentUserID, PageContext.PageBoardID, null, null,
				Convert.ToInt32( TimeZones.SelectedValue ), Language.SelectedValue, Theme.SelectedValue, OverrideDefaultThemes.Checked, null, PMNotificationEnabled.Checked );

			if ( !AdminEditMode )
			{
				YAF.Classes.Utils.YafBuildLink.Redirect( YAF.Classes.Utils.ForumPages.cp_profile );
			}
			else
			{
				BindData();
			}
		}
Пример #31
0
        protected void ForumRegister_Click(object sender, System.EventArgs e)
        {
            if (Page.IsValid)
            {
                string newEmail    = Email.Text.Trim();
                string newUsername = UserName.Text.Trim();

                if (!General.IsValidEmail(newEmail))
                {
                    PageContext.AddLoadMessage("You have entered an illegal e-mail address.");
                    return;
                }

                if (UserMembershipHelper.UserExists(UserName.Text.Trim(), newEmail))
                {
                    PageContext.AddLoadMessage("Username or email are already registered.");
                    return;
                }

                string hashinput = DateTime.Now.ToString() + newEmail + Security.CreatePassword(20);
                string hash      = FormsAuthentication.HashPasswordForStoringInConfigFile(hashinput, "md5");

                MembershipCreateStatus status;
                MembershipUser         user = Membership.CreateUser(newUsername, Password.Text.Trim(), newEmail, Question.Text.Trim(), Answer.Text.Trim(), !PageContext.BoardSettings.EmailVerification, out status);

                if (status != MembershipCreateStatus.Success)
                {
                    // error of some kind
                    PageContext.AddLoadMessage("Membership Error Creating User: "******"VERIFYEMAIL");

                    verifyEmail.TemplateParams ["{link}"]      = String.Format("{1}{0}", YAF.Classes.Utils.YafBuildLink.GetLink(YAF.Classes.Utils.ForumPages.approve, "k={0}", hash), YAF.Classes.Utils.YafForumInfo.ServerURL);
                    verifyEmail.TemplateParams ["{key}"]       = hash;
                    verifyEmail.TemplateParams ["{forumname}"] = PageContext.BoardSettings.Name;
                    verifyEmail.TemplateParams ["{forumlink}"] = String.Format("{0}", ForumURL);

                    string subject = String.Format(PageContext.Localization.GetText("COMMON", "EMAILVERIFICATION_SUBJECT"), PageContext.BoardSettings.Name);

                    verifyEmail.SendEmail(new System.Net.Mail.MailAddress(newEmail, newUsername), subject, true);
                }

                // success
                PageContext.AddLoadMessage(string.Format("User {0} Created Successfully.", UserName.Text.Trim()));
                YAF.Classes.Utils.YafBuildLink.Redirect(YAF.Classes.Utils.ForumPages.admin_reguser);
            }
        }
Пример #32
0
        /// <summary>
        /// Handles the ItemCommand event of the UserList control.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterCommandEventArgs"/> instance containing the event data.</param>
        public void UserListItemCommand([NotNull] object source, [NotNull] RepeaterCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "edit":
                YafBuildLink.Redirect(ForumPages.admin_edituser, "u={0}", e.CommandArgument);
                break;

            case "resendEmail":
                var commandArgument = e.CommandArgument.ToString().Split(';');

                var checkMail = this.GetRepository <CheckEmail>().ListTyped(commandArgument[0]).FirstOrDefault();

                if (checkMail != null)
                {
                    var verifyEmail = new YafTemplateEmail("VERIFYEMAIL");

                    var subject = this.Get <ILocalization>()
                                  .GetTextFormatted("VERIFICATION_EMAIL_SUBJECT", this.Get <YafBoardSettings>().Name);

                    verifyEmail.TemplateParams["{link}"] = YafBuildLink.GetLinkNotEscaped(
                        ForumPages.approve,
                        true,
                        "k={0}",
                        checkMail.Hash);
                    verifyEmail.TemplateParams["{key}"]       = checkMail.Hash;
                    verifyEmail.TemplateParams["{forumname}"] = this.Get <YafBoardSettings>().Name;
                    verifyEmail.TemplateParams["{forumlink}"] = YafForumInfo.ForumURL;

                    verifyEmail.SendEmail(new MailAddress(checkMail.Email, commandArgument[1]), subject, true);

                    this.PageContext.AddLoadMessage(this.GetText("ADMIN_ADMIN", "MSG_MESSAGE_SEND"));
                }
                else
                {
                    var userFound = this.Get <IUserDisplayName>().Find(commandArgument[1]).FirstOrDefault();

                    var user = this.Get <MembershipProvider>().GetUser(userFound.Value, false);

                    this.Get <ISendNotification>().SendVerificationEmail(user, commandArgument[0], userFound.Key);
                }

                break;

            case "delete":
                var daysValue =
                    this.PageContext.CurrentForumPage.FindControlRecursiveAs <TextBox>("DaysOld").Text.Trim();
                if (!ValidationHelper.IsValidInt(daysValue))
                {
                    this.PageContext.AddLoadMessage(this.GetText("ADMIN_ADMIN", "MSG_VALID_DAYS"));
                    return;
                }

                if (!Config.IsAnyPortal)
                {
                    UserMembershipHelper.DeleteUser(e.CommandArgument.ToType <int>());
                }

                this.GetRepository <User>().Delete(e.CommandArgument.ToType <int>());

                this.BindData();
                break;

            case "approve":
                UserMembershipHelper.ApproveUser(e.CommandArgument.ToType <int>());
                this.BindData();
                break;

            case "deleteall":

                // vzrus: Should not delete the whole providers portal data? Under investigation.
                var daysValueAll =
                    this.PageContext.CurrentForumPage.FindControlRecursiveAs <TextBox>("DaysOld").Text.Trim();
                if (!ValidationHelper.IsValidInt(daysValueAll))
                {
                    this.PageContext.AddLoadMessage(this.GetText("ADMIN_ADMIN", "MSG_VALID_DAYS"));
                    return;
                }

                if (!Config.IsAnyPortal)
                {
                    UserMembershipHelper.DeleteAllUnapproved(DateTime.UtcNow.AddDays(-daysValueAll.ToType <int>()));
                }

                this.GetRepository <User>().DeleteOld(this.PageContext.PageBoardID, daysValueAll.ToType <int>());
                this.BindData();
                break;

            case "approveall":
                UserMembershipHelper.ApproveAll();

                // vzrus: Should delete users from send email list
                this.GetRepository <User>().ApproveAll(this.PageContext.PageBoardID);
                this.BindData();
                break;
            }
        }
    protected void PasswordRecovery1_SendingMail( object sender, MailMessageEventArgs e )
    {
      // get the username and password from the body
      string body = e.Message.Body;

      // remove first line...
      body = body.Remove( 0, body.IndexOf( '\n' ) + 1 );
      // remove "Username: "******": " ) + 2 );
      // get first line which is the username
      string userName = body.Substring( 0, body.IndexOf( '\n' ) );
      // delete that same line...
      body = body.Remove( 0, body.IndexOf( '\n' ) + 1 );
      // remove the "Password: "******": " ) + 2 );
      // the rest is the password...
      string password = body.Substring( 0, body.IndexOf( '\n' ) );
      
      // get the e-mail ready from the real template.
			YafTemplateEmail passwordRetrieval = new YafTemplateEmail( "PASSWORDRETRIEVAL" );

      string subject = String.Format( GetText( "PASSWORDRETRIEVAL_EMAIL_SUBJECT" ), PageContext.BoardSettings.Name );

      passwordRetrieval.TemplateParams["{username}"] = userName;
      passwordRetrieval.TemplateParams["{password}"] = password;
      passwordRetrieval.TemplateParams["{forumname}"] = PageContext.BoardSettings.Name;
      passwordRetrieval.TemplateParams["{forumlink}"] = String.Format( "{0}", YafForumInfo.ForumURL );

			passwordRetrieval.SendEmail( e.Message.To[0], subject, true );

			// manually set to success...
			e.Cancel = true;
			PasswordRecovery1.TabIndex = 3;
    }