当前位置: 首页>>代码示例>>C#>>正文


C# YafTemplateEmail.SendEmail方法代码示例

本文整理汇总了C#中YAF.Core.Services.YafTemplateEmail.SendEmail方法的典型用法代码示例。如果您正苦于以下问题:C# YafTemplateEmail.SendEmail方法的具体用法?C# YafTemplateEmail.SendEmail怎么用?C# YafTemplateEmail.SendEmail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在YAF.Core.Services.YafTemplateEmail的用法示例。


在下文中一共展示了YafTemplateEmail.SendEmail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendVerificationEmail

        /// <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);
        }
开发者ID:RH-Code,项目名称:YAFNET,代码行数:31,代码来源:EmailHelper.cs

示例2: PasswordRecovery1_VerifyingUser

        /// <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);
        }
开发者ID:JP58,项目名称:YAFNET,代码行数:92,代码来源:recoverpassword.ascx.cs

示例3: PasswordRecovery1_SendingMail

        /// <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: "
            body = body.Remove(0, body.IndexOf(": ", 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: " part
            body = body.Remove(0, body.IndexOf(": ", 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;
        }
开发者ID:JP58,项目名称:YAFNET,代码行数:56,代码来源:recoverpassword.ascx.cs

示例4: PasswordRecovery1_SendingMail

        /// <summary>
        /// The password recovery 1_ sending mail.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void PasswordRecovery1_SendingMail([NotNull] object sender, [NotNull] 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: "
            body = body.Remove(0, body.IndexOf(": ") + 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: " part
            body = body.Remove(0, body.IndexOf(": ") + 2);

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

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

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

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

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

            // manually set to success...
            e.Cancel = true;
            this.PasswordRecovery1.TabIndex = 3;
        }
开发者ID:umityildiz,项目名称:YAFNET,代码行数:48,代码来源:recoverpassword.ascx.cs

示例5: btnResetPassword_Click

    /// <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));
      }
    }
开发者ID:bugjohnyang,项目名称:YAFNET,代码行数:44,代码来源:EditUsersResetPass.ascx.cs

示例6: SendEmailVerification

        /// <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));
        }
开发者ID:umityildiz,项目名称:YAFNET,代码行数:31,代码来源:EditUsersProfile.ascx.cs

示例7: ToUserWithNewMedal

        /// <summary>
        /// Sends notification that the User was awarded with a Medal
        /// </summary>
        /// <param name="toUserId">To user id.</param>
        /// <param name="medalName">Name of the medal.</param>
        public void ToUserWithNewMedal([NotNull] int toUserId, [NotNull] string medalName)
        {
            var userList = LegacyDb.UserList(YafContext.Current.PageBoardID, toUserId, true, null, null, null).ToList();

            TypedUserList toUser;

            if (userList.Any())
            {
                toUser = userList.First();
            }
            else
            {
                return;
            }

            var languageFile = UserHelper.GetUserLanguageFile(toUser.UserID.ToType<int>());

            var notifyUser = new YafTemplateEmail("NOTIFICATION_ON_MEDAL_AWARDED")
                                 {
                                     TemplateLanguageFile = languageFile
                                 };

            var subject =
                this.Get<ILocalization>()
                    .GetText("COMMON", "NOTIFICATION_ON_MEDAL_AWARDED_SUBJECT", languageFile)
                    .FormatWith(this.BoardSettings.Name);

            notifyUser.TemplateParams["{user}"] = this.BoardSettings.EnableDisplayName
                                                      ? toUser.DisplayName
                                                      : toUser.Name;
            notifyUser.TemplateParams["{medalname}"] = medalName;
            notifyUser.TemplateParams["{forumname}"] = this.BoardSettings.Name;

            notifyUser.SendEmail(
                new MailAddress(toUser.Email, this.BoardSettings.EnableDisplayName ? toUser.DisplayName : toUser.Name),
                subject,
                true);
        }
开发者ID:viniciustodesco,项目名称:YAFNET,代码行数:43,代码来源:YafSendNotification.cs

示例8: ToWatchingUsers

        /// <summary>
        /// The to watching users.
        /// </summary>
        /// <param name="newMessageId">
        /// The new message id.
        /// </param>
        public void ToWatchingUsers(int newMessageId)
        {
            IList<User> usersWithAll = new List<User>();

            if (this.BoardSettings.AllowNotificationAllPostsAllTopics)
            {
                usersWithAll = this.GetRepository<User>()
                    .FindUserTyped(filter: false, notificationType: UserNotificationSetting.AllTopics.ToInt());
            }

            // TODO : Rewrite Watch Topic code to allow watch mails in the users language, as workaround send all messages in the default board language
            var languageFile = this.BoardSettings.Language;
            var boardName = this.BoardSettings.Name;
            var forumEmail = this.BoardSettings.ForumEmail;

            var message = LegacyDb.MessageList(newMessageId).FirstOrDefault();

            var messageAuthorUserID = message.UserID ?? 0;

            var watchEmail = new YafTemplateEmail("TOPICPOST") { TemplateLanguageFile = languageFile };

            // cleaned body as text...
            var bodyText =
                BBCodeHelper.StripBBCode(HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString(message.Message)))
                    .RemoveMultipleWhitespace();

            // Send track mails
            var subject =
                this.Get<ILocalization>()
                    .GetText("COMMON", "TOPIC_NOTIFICATION_SUBJECT", languageFile)
                    .FormatWith(boardName);

            watchEmail.TemplateParams["{forumname}"] = boardName;
            watchEmail.TemplateParams["{topic}"] = HttpUtility.HtmlDecode(message.Topic);
            watchEmail.TemplateParams["{postedby}"] = UserMembershipHelper.GetDisplayNameFromID(messageAuthorUserID);
            watchEmail.TemplateParams["{body}"] = bodyText;
            watchEmail.TemplateParams["{bodytruncated}"] = bodyText.Truncate(160);
            watchEmail.TemplateParams["{link}"] = YafBuildLink.GetLinkNotEscaped(
                ForumPages.posts,
                true,
                "m={0}#post{0}",
                newMessageId);

            watchEmail.CreateWatch(
                message.TopicID ?? 0,
                messageAuthorUserID,
                new MailAddress(forumEmail, boardName),
                subject);

            // create individual watch emails for all users who have All Posts on...
            foreach (var user in usersWithAll.Where(x => x.UserID != messageAuthorUserID && x.ProviderUserKey != null))
            {
                var membershipUser = UserMembershipHelper.GetUser(user.Name);

                if (membershipUser == null || membershipUser.Email.IsNotSet())
                {
                    continue;
                }

                watchEmail.TemplateLanguageFile = user.LanguageFile.IsSet()
                                                      ? user.LanguageFile
                                                      : this.Get<ILocalization>().LanguageFileName;
                watchEmail.SendEmail(
                    new MailAddress(forumEmail, boardName),
                    new MailAddress(membershipUser.Email, membershipUser.UserName),
                    subject,
                    true);
            }
        }
开发者ID:viniciustodesco,项目名称:YAFNET,代码行数:75,代码来源:YafSendNotification.cs

示例9: ToPrivateMessageRecipient

        /// <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>
        public void ToPrivateMessageRecipient(int toUserId, [NotNull] string subject)
        {
            try
            {
                // user's PM notification setting
                var privateMessageNotificationEnabled = false;

                // user's email
                var toEMail = string.Empty;

                var userList =
                    LegacyDb.UserList(YafContext.Current.PageBoardID, toUserId, true, null, null, null).ToList();

                if (userList.Any())
                {
                    privateMessageNotificationEnabled = userList.First().PMNotification ?? false;
                    toEMail = userList.First().Email;
                }

                if (!privateMessageNotificationEnabled)
                {
                    return;
                }

                // 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))
                var userPMessageId =
                    LegacyDb.pmessage_list(toUserId, null, null).GetFirstRow().Field<int>("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"];*/

                var languageFile = UserHelper.GetUserLanguageFile(toUserId);

                // send this user a PM notification e-mail
                var notificationTemplate = new YafTemplateEmail("PMNOTIFICATION")
                                               {
                                                   TemplateLanguageFile = languageFile
                                               };

                var displayName = this.Get<IUserDisplayName>().GetName(YafContext.Current.PageUserID);

                // fill the template with relevant info
                notificationTemplate.TemplateParams["{fromuser}"] = displayName;

                notificationTemplate.TemplateParams["{link}"] =
                    "{0}\r\n\r\n".FormatWith(
                        YafBuildLink.GetLinkNotEscaped(ForumPages.cp_message, true, "pm={0}", userPMessageId));
                notificationTemplate.TemplateParams["{forumname}"] = this.BoardSettings.Name;
                notificationTemplate.TemplateParams["{subject}"] = subject;

                // create notification email subject
                var emailSubject =
                    this.Get<ILocalization>()
                        .GetText("COMMON", "PM_NOTIFICATION_SUBJECT", languageFile)
                        .FormatWith(displayName, this.BoardSettings.Name, subject);

                // send email
                notificationTemplate.SendEmail(new MailAddress(toEMail), emailSubject, true);
            }
            catch (Exception x)
            {
                // report exception to the forum's event log
                this.Get<ILogger>()
                    .Error(x, "Send PM Notification Error for UserID {0}".FormatWith(YafContext.Current.PageUserID));

                // tell user about failure
                YafContext.Current.AddLoadMessage(
                    this.Get<ILocalization>().GetTextFormatted("Failed", x.Message),
                    MessageTypes.Error);
            }
        }
开发者ID:viniciustodesco,项目名称:YAFNET,代码行数:83,代码来源:YafSendNotification.cs

示例10: ToModeratorsThatMessageWasReported

        /// <summary>
        /// Sends Notifications to Moderators that a Message was Reported
        /// </summary>
        /// <param name="pageForumID">
        /// The page Forum ID.
        /// </param>
        /// <param name="reportedMessageId">
        /// The reported message id.
        /// </param>
        /// <param name="reporter">
        /// The reporter.
        /// </param>
        /// <param name="reportText">
        /// The report Text.
        /// </param>
        public void ToModeratorsThatMessageWasReported(
            int pageForumID,
            int reportedMessageId,
            int reporter,
            string reportText)
        {
            try
            {
                var moderatorsFiltered =
                    this.Get<YafDbBroker>().GetAllModerators().Where(f => f.ForumID.Equals(pageForumID));
                var moderatorUserNames = new List<string>();

                foreach (var moderator in moderatorsFiltered)
                {
                    if (moderator.IsGroup)
                    {
                        moderatorUserNames.AddRange(this.Get<RoleProvider>().GetUsersInRole(moderator.Name));
                    }
                    else
                    {
                        moderatorUserNames.Add(moderator.Name);
                    }
                }

                // send each message...
                foreach (var userName in moderatorUserNames.Distinct())
                {
                    // add each member of the group
                    var membershipUser = UserMembershipHelper.GetUser(userName);
                    var userId = UserMembershipHelper.GetUserIDFromProviderUserKey(membershipUser.ProviderUserKey);

                    var languageFile = UserHelper.GetUserLanguageFile(userId);

                    var subject =
                        this.Get<ILocalization>()
                            .GetText("COMMON", "NOTIFICATION_ON_MODERATOR_REPORTED_MESSAGE", languageFile)
                            .FormatWith(this.BoardSettings.Name);

                    var notifyModerators = new YafTemplateEmail("NOTIFICATION_ON_MODERATOR_REPORTED_MESSAGE")
                                               {
                                                   // get the user localization...
                                                   TemplateLanguageFile
                                                       =
                                                       languageFile
                                               };

                    notifyModerators.TemplateParams["{reason}"] = reportText;
                    notifyModerators.TemplateParams["{reporter}"] = this.Get<IUserDisplayName>().GetName(reporter);
                    notifyModerators.TemplateParams["{adminlink}"] =
                        YafBuildLink.GetLinkNotEscaped(ForumPages.moderate_reportedposts, true, "f={0}", pageForumID);
                    notifyModerators.TemplateParams["{forumname}"] = this.BoardSettings.Name;

                    notifyModerators.SendEmail(
                        new MailAddress(membershipUser.Email, membershipUser.UserName),
                        subject,
                        true);
                }
            }
            catch (Exception x)
            {
                // report exception to the forum's event log
                this.Get<ILogger>()
                    .Error(
                        x,
                        "Send Message Report Notification Error for UserID {0}".FormatWith(
                            YafContext.Current.PageUserID));
            }
        }
开发者ID:viniciustodesco,项目名称:YAFNET,代码行数:83,代码来源:YafSendNotification.cs

示例11: ToModeratorsThatMessageNeedsApproval

        /// <summary>
        /// Sends Notifications to Moderators that Message Needs Approval
        /// </summary>
        /// <param name="forumId">The forum id.</param>
        /// <param name="newMessageId">The new message id.</param>
        /// <param name="isSpamMessage">if set to <c>true</c> [is spam message].</param>
        public void ToModeratorsThatMessageNeedsApproval(int forumId, int newMessageId, bool isSpamMessage)
        {
            var moderatorsFiltered = this.Get<YafDbBroker>().GetAllModerators().Where(f => f.ForumID.Equals(forumId));
            var moderatorUserNames = new List<string>();

            foreach (var moderator in moderatorsFiltered)
            {
                if (moderator.IsGroup)
                {
                    moderatorUserNames.AddRange(this.Get<RoleProvider>().GetUsersInRole(moderator.Name));
                }
                else
                {
                    moderatorUserNames.Add(moderator.Name);
                }
            }

            // send each message...
            foreach (var userName in moderatorUserNames.Distinct())
            {
                // add each member of the group
                var membershipUser = UserMembershipHelper.GetUser(userName);
                var userId = UserMembershipHelper.GetUserIDFromProviderUserKey(membershipUser.ProviderUserKey);

                var languageFile = UserHelper.GetUserLanguageFile(userId);

                var subject =
                    this.Get<ILocalization>()
                        .GetText(
                            "COMMON",
                            isSpamMessage
                                ? "NOTIFICATION_ON_MODERATOR_SPAMMESSAGE_APPROVAL"
                                : "NOTIFICATION_ON_MODERATOR_MESSAGE_APPROVAL",
                            languageFile)
                        .FormatWith(this.BoardSettings.Name);

                var notifyModerators =
                    new YafTemplateEmail(
                        isSpamMessage
                            ? "NOTIFICATION_ON_MODERATOR_SPAMMESSAGE_APPROVAL"
                            : "NOTIFICATION_ON_MODERATOR_MESSAGE_APPROVAL")
                        {
                            // get the user localization...
                            TemplateLanguageFile = languageFile
                        };

                notifyModerators.TemplateParams["{adminlink}"] =
                    YafBuildLink.GetLinkNotEscaped(ForumPages.moderate_unapprovedposts, true, "f={0}", forumId);
                notifyModerators.TemplateParams["{forumname}"] = this.BoardSettings.Name;

                notifyModerators.SendEmail(
                    new MailAddress(membershipUser.Email, membershipUser.UserName),
                    subject,
                    true);
            }
        }
开发者ID:viniciustodesco,项目名称:YAFNET,代码行数:62,代码来源:YafSendNotification.cs

示例12: UserList_ItemCommand

        /// <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 UserList_ItemCommand([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>());
                    }

                    LegacyDb.user_delete(e.CommandArgument);
                    this.Get<ILogger>()
                        .Log(
                            this.PageContext.PageUserID,
                            "YAF.Pages.Admin.admin",
                            "User {0} was deleted by {1}.".FormatWith(e.CommandArgument.ToType<int>(), this.PageContext.PageUserID),
                            EventLogTypes.UserDeleted);
                    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>()));
                    }

                    LegacyDb.user_deleteold(this.PageContext.PageBoardID, daysValueAll.ToType<int>());
                    this.BindData();
                    break;
                case "approveall":
                    UserMembershipHelper.ApproveAll();

                    // vzrus: Should delete users from send email list
                    LegacyDb.user_approveall(this.PageContext.PageBoardID);
                    this.BindData();
                    break;
//.........这里部分代码省略.........
开发者ID:Pathfinder-Fr,项目名称:YAFNET,代码行数:101,代码来源:admin.ascx.cs

示例13: ToWatchingUsers

        /// <summary>
        /// The to watching users.
        /// </summary>
        /// <param name="newMessageId">
        /// The new message id.
        /// </param>
        public void ToWatchingUsers(int newMessageId)
        {
            IEnumerable<TypedUserFind> usersWithAll = new List<TypedUserFind>();

            if (this.Get<YafBoardSettings>().AllowNotificationAllPostsAllTopics)
            {
                // TODO: validate permissions!
                usersWithAll = CommonDb.UserFind(YafContext.Current.PageModuleID, YafContext.Current.PageBoardID,
                    false,
                    null,
                    null,
                    null,
                    UserNotificationSetting.AllTopics.ToInt(),
                    null);
            }

            // TODO : Rewrite Watch Topic code to allow watch mails in the users language, as workaround send all messages in the default board language
            var languageFile =  this.Get<YafBoardSettings>().Language;

            foreach (var message in CommonDb.MessageList(YafContext.Current.PageModuleID, newMessageId))
            {
                int userId = message.UserID ?? 0;

                var watchEmail = new YafTemplateEmail("TOPICPOST") { TemplateLanguageFile = languageFile };

                // cleaned body as text...
                var bodyText =
                    StringExtensions.RemoveMultipleWhitespace(
                        BBCodeHelper.StripBBCode(HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString(message.Message))));

                // Send track mails
                var subject =
                    this.Get<ILocalization>().GetText("COMMON", "TOPIC_NOTIFICATION_SUBJECT", languageFile).FormatWith(
                        this.Get<YafBoardSettings>().Name);

                watchEmail.TemplateParams["{forumname}"] = this.Get<YafBoardSettings>().Name;
                watchEmail.TemplateParams["{topic}"] = HttpUtility.HtmlDecode(message.Topic);
                watchEmail.TemplateParams["{postedby}"] = UserMembershipHelper.GetDisplayNameFromID(userId);
                watchEmail.TemplateParams["{body}"] = bodyText;
                watchEmail.TemplateParams["{bodytruncated}"] = bodyText.Truncate(160);
                watchEmail.TemplateParams["{link}"] = YafBuildLink.GetLinkNotEscaped(
                    ForumPages.posts, true, "m={0}#post{0}", newMessageId);

                watchEmail.CreateWatch(
                    message.TopicID ?? 0,
                    userId,
                    new MailAddress(this.Get<YafBoardSettings>().ForumEmail, this.Get<YafBoardSettings>().Name),
                    subject);

                // create individual watch emails for all users who have All Posts on...
                foreach (var user in usersWithAll.Where(x => x.UserID.HasValue && x.UserID.Value != userId))
                {
                    // Make sure its not a guest
                    if (user.ProviderUserKey == null)
                    {
                        continue;
                    }

                    var membershipUser = UserMembershipHelper.GetUser(user.ProviderUserKey);

                    if (!membershipUser.Email.IsSet())
                    {
                        continue;
                    }

                    watchEmail.TemplateLanguageFile = !string.IsNullOrEmpty(user.LanguageFile)
                                                          ? user.LanguageFile
                                                          : this.Get<ILocalization>().LanguageFileName;
                    watchEmail.SendEmail(
                        new MailAddress(this.Get<YafBoardSettings>().ForumEmail, this.Get<YafBoardSettings>().Name),
                        new MailAddress(membershipUser.Email, membershipUser.UserName),
                        subject,
                        true);
                }
            }
        }
开发者ID:vzrus,项目名称:VZF,代码行数:82,代码来源:YafSendNotification.cs

示例14: ForumRegister_Click


//.........这里部分代码省略.........
            return;
            }

            if (UserMembershipHelper.UserExists(this.UserName.Text.Trim(), newEmail))
            {
            this.PageContext.AddLoadMessage(this.GetText("ADMIN_REGUSER", "MSG_NAME_EXISTS"));
            return;
            }

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

            MembershipCreateStatus status;
            MembershipUser user = this.Get<MembershipProvider>().CreateUser(
            newUsername,
            this.Password.Text.Trim(),
            newEmail,
            this.Question.Text.Trim(),
            this.Answer.Text.Trim(),
            !this.Get<YafBoardSettings>().EmailVerification,
            null,
            out status);

            if (status != MembershipCreateStatus.Success)
            {
            // error of some kind
            this.PageContext.AddLoadMessage(this.GetText("ADMIN_REGUSER", "MSG_ERROR_CREATE").FormatWith(status));
            return;
            }

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

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

            // create profile
            YafUserProfile userProfile = YafUserProfile.GetProfile(newUsername);

            // setup their inital profile information
            userProfile.Location = this.Location.Text.Trim();
            userProfile.Homepage = this.HomePage.Text.Trim();
            userProfile.Save();

            // save the time zone...
            LegacyDb.user_save(
            UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey),
            this.PageContext.PageBoardID,
            null,
            null,
            null,
            this.TimeZones.SelectedValue.ToType<int>(),
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null);

            if (this.Get<YafBoardSettings>().EmailVerification)
            {
            // save verification record...
            LegacyDb.checkemail_save(userID, hash, user.Email);

            // send template email
            var verifyEmail = new YafTemplateEmail("VERIFYEMAIL");

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

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

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

            bool autoWatchTopicsEnabled =
            this.Get<YafBoardSettings>().DefaultNotificationSetting.Equals(
                UserNotificationSetting.TopicsIPostToOrSubscribeTo);

            LegacyDb.user_savenotification(
            UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey),
            true,
            autoWatchTopicsEnabled,
            this.Get<YafBoardSettings>().DefaultNotificationSetting,
            this.Get<YafBoardSettings>().DefaultSendDigestEmail);

            // success
            this.PageContext.AddLoadMessage(this.GetText("ADMIN_REGUSER", "MSG_CREATED").FormatWith(this.UserName.Text.Trim()));
            YafBuildLink.Redirect(ForumPages.admin_reguser);
        }
开发者ID:mukhtiarlander,项目名称:git_demo_torit,代码行数:101,代码来源:reguser.ascx.cs

示例15: btnChangePassword_Click

    /// <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
      {
        SitecoreMembershipUser user = UserMembershipHelper.GetMembershipUserById(this.CurrentUserID.Value);

        if (user != null)
        {
          // new password...
          string newPass = this.txtNewPassword.Text.Trim();

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

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

          if (this.chkEmailNotify.Checked)
          {
            // 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}"] = newPass;
            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_CHANGED_NOTI"));
          }
          else
          {
            this.PageContext.AddLoadMessage(this.Get<ILocalization>().GetText("ADMIN_EDITUSER", "MSG_PASS_CHANGED"));
          }
        }
      }
      catch (Exception x)
      {
        this.PageContext.AddLoadMessage("Exception: {0}".FormatWith(x.Message));
      }
    }
开发者ID:unstab1e,项目名称:sitecoreyaf8,代码行数:62,代码来源:EditUsersResetPass.ascx.cs


注:本文中的YAF.Core.Services.YafTemplateEmail.SendEmail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。