/// <summary> /// The send registration notification email. /// </summary> /// <param name="user">The Membership User.</param> /// <param name="userID">The user identifier.</param> public static void SendRegistrationNotificationEmail([NotNull] MembershipUser user, [NotNull] int userID) { var emails = YafContext.Current.Get <YafBoardSettings>().NotificationOnUserRegisterEmailList.Split(';'); var notifyAdmin = new YafTemplateEmail(); var subject = YafContext.Current.Get <ILocalization>() .GetText("COMMON", "NOTIFICATION_ON_USER_REGISTER_EMAIL_SUBJECT") .FormatWith(YafContext.Current.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}"] = YafContext.Current.Get <YafBoardSettings>().Name; string emailBody = notifyAdmin.ProcessTemplate("NOTIFICATION_ON_USER_REGISTER"); foreach (string email in emails.Where(email => email.Trim().IsSet())) { YafContext.Current.GetRepository <Mail>() .Create(YafContext.Current.Get <YafBoardSettings>().ForumEmail, email.Trim(), subject, emailBody); } }
/// <summary> /// Sends the user welcome notification. /// </summary> /// <param name="user">The user.</param> /// <param name="userId">The user identifier.</param> public void SendUserWelcomeNotification([NotNull] SitecoreMembershipUser user, int?userId) { if (this.Get <YafBoardSettings>().SendWelcomeNotificationAfterRegister.Equals(0)) { return; } var notifyUser = new YafTemplateEmail(); var subject = this.Get <ILocalization>() .GetText("COMMON", "NOTIFICATION_ON_WELCOME_USER_SUBJECT") .FormatWith(YafContext.Current.Get <YafBoardSettings>().Name); notifyUser.TemplateParams["{user}"] = user.UserName; notifyUser.TemplateParams["{forumname}"] = this.BoardSettings.Name; notifyUser.TemplateParams["{forumurl}"] = YafForumInfo.ForumURL; var emailBody = notifyUser.ProcessTemplate("NOTIFICATION_ON_WELCOME_USER"); var messageFlags = new MessageFlags { IsHtml = false, IsBBCode = true }; if (this.Get <YafBoardSettings>().AllowPrivateMessages && this.Get <YafBoardSettings>().SendWelcomeNotificationAfterRegister.Equals(2)) { LegacyDb.pmessage_save(2, userId, subject, emailBody, messageFlags.BitValue, -1); } else { this.GetRepository <Mail>().Create(this.BoardSettings.ForumEmail, user.Email, subject, emailBody); } }
/// <summary> /// The send registration notification email. /// </summary> /// <param name="user">The Membership User.</param> /// <param name="userID">The user identifier.</param> public static void SendRegistrationNotificationEmail([NotNull] MembershipUser user, [NotNull] int userID) { var emails = YafContext.Current.Get<YafBoardSettings>().NotificationOnUserRegisterEmailList.Split(';'); var notifyAdmin = new YafTemplateEmail(); var subject = YafContext.Current.Get<ILocalization>() .GetText("COMMON", "NOTIFICATION_ON_USER_REGISTER_EMAIL_SUBJECT") .FormatWith(YafContext.Current.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}"] = YafContext.Current.Get<YafBoardSettings>().Name; string emailBody = notifyAdmin.ProcessTemplate("NOTIFICATION_ON_USER_REGISTER"); foreach (string email in emails.Where(email => email.Trim().IsSet())) { YafContext.Current.GetRepository<Mail>() .Create(YafContext.Current.Get<YafBoardSettings>().ForumEmail, email.Trim(), subject, emailBody); } }
/// <summary> /// Sends the verification email. /// </summary> /// <param name="user">The user.</param> /// <param name="email">The email.</param> /// <param name="userID">The user identifier.</param> /// <param name="newUsername">The new username.</param> public void SendVerificationEmail( [NotNull] MembershipUser user, [NotNull] string email, int?userID, string newUsername = null) { CodeContracts.VerifyNotNull(email, "email"); CodeContracts.VerifyNotNull(user, "user"); var hashinput = string.Format("{0}{1}{2}", DateTime.UtcNow, email, Security.CreatePassword(20)); var hash = FormsAuthentication.HashPasswordForStoringInConfigFile(hashinput, "md5"); // save verification record... this.GetRepository <CheckEmail>().Save(userID, hash, user.Email); var verifyEmail = new YafTemplateEmail("VERIFYEMAIL"); var subject = this.Get <ILocalization>() .GetTextFormatted("VERIFICATION_EMAIL_SUBJECT", this.BoardSettings.Name); verifyEmail.TemplateParams["{link}"] = YafBuildLink.GetLinkNotEscaped( ForumPages.approve, true, "k={0}", hash); verifyEmail.TemplateParams["{key}"] = hash; verifyEmail.TemplateParams["{forumname}"] = this.BoardSettings.Name; verifyEmail.TemplateParams["{forumlink}"] = "{0}".FormatWith(YafForumInfo.ForumURL); verifyEmail.SendEmail(new MailAddress(email, newUsername ?? user.UserName), subject, true); }
/// <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.AddForumLinks(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"); } }
/// <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); 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); }
/// <summary> /// Send an Email 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="templateName"> /// The template Name. /// </param> public void SendRegistrationNotificationToUser( [NotNull] MembershipUser user, [NotNull] string pass, [NotNull] string securityAnswer, string templateName) { var notifyUser = new YafTemplateEmail(); var subject = this.Get <ILocalization>() .GetText("COMMON", "NOTIFICATION_ON_NEW_FACEBOOK_USER_SUBJECT") .FormatWith(this.BoardSettings.Name); notifyUser.TemplateParams["{user}"] = user.UserName; notifyUser.TemplateParams["{email}"] = user.Email; notifyUser.TemplateParams["{pass}"] = pass; notifyUser.TemplateParams["{answer}"] = securityAnswer; notifyUser.TemplateParams["{forumname}"] = this.BoardSettings.Name; var emailBody = notifyUser.ProcessTemplate(templateName); this.GetRepository <Mail>() .Create( user.Email, user.UserName, subject, emailBody); }
/// <summary> /// Sends a new user notification email to all emails in the NotificationOnUserRegisterEmailList /// Setting /// </summary> /// <param name="user">The user.</param> /// <param name="userId">The user id.</param> public void SendRegistrationNotificationEmail([NotNull] MembershipUser user, int userId) { var emails = this.BoardSettings.NotificationOnUserRegisterEmailList.Split(';'); var notifyAdmin = new YafTemplateEmail(); var subject = this.Get <ILocalization>().GetTextFormatted( "NOTIFICATION_ON_USER_REGISTER_EMAIL_SUBJECT", this.BoardSettings.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.BoardSettings.Name; var emailBody = notifyAdmin.ProcessTemplate("NOTIFICATION_ON_USER_REGISTER"); emails.Where(email => email.Trim().IsSet()).ForEach( email => this.GetRepository <Mail>().Create(email.Trim(), null, subject, emailBody)); }
/// <summary> /// Sends the user a suspension notification. /// </summary> /// <param name="suspendedUntil">The suspended until.</param> /// <param name="suspendReason">The suspend reason.</param> /// <param name="email">The email.</param> /// <param name="userName">Name of the user.</param> public void SendUserSuspensionNotification( [NotNull] DateTime suspendedUntil, [NotNull] string suspendReason, [NotNull] string email, [NotNull] string userName) { var notifyUser = new YafTemplateEmail(); var subject = this.Get <ILocalization>() .GetText("COMMON", "NOTIFICATION_ON_SUSPENDING_USER_SUBJECT") .FormatWith(this.BoardSettings.Name); notifyUser.TemplateParams["{user}"] = userName; notifyUser.TemplateParams["{suspendReason}"] = suspendReason; notifyUser.TemplateParams["{suspendedUntil}"] = suspendedUntil.ToString(CultureInfo.InvariantCulture); notifyUser.TemplateParams["{forumname}"] = this.BoardSettings.Name; notifyUser.TemplateParams["{forumurl}"] = YafForumInfo.ForumURL; var emailBody = notifyUser.ProcessTemplate("NOTIFICATION_ON_SUSPENDING_USER"); this.GetRepository <Mail>() .Create( email, userName, subject, emailBody); }
/// <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.Get <YafBoardSettings>().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.Get <YafBoardSettings>().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)); } }
/// <summary> /// Sends the user welcome notification. /// </summary> /// <param name="user">The user.</param> /// <param name="userId">The user identifier.</param> public void SendUserWelcomeNotification([NotNull] MembershipUser user, int?userId) { if (this.BoardSettings.SendWelcomeNotificationAfterRegister.Equals(0)) { return; } var notifyUser = new YafTemplateEmail(); var subject = this.Get <ILocalization>() .GetText("COMMON", "NOTIFICATION_ON_WELCOME_USER_SUBJECT") .FormatWith(this.BoardSettings.Name); notifyUser.TemplateParams["{user}"] = user.UserName; notifyUser.TemplateParams["{forumname}"] = this.BoardSettings.Name; notifyUser.TemplateParams["{forumurl}"] = YafForumInfo.ForumURL; var emailBody = notifyUser.ProcessTemplate("NOTIFICATION_ON_WELCOME_USER"); var messageFlags = new MessageFlags { IsHtml = false, IsBBCode = true }; if (this.BoardSettings.AllowPrivateMessages && this.BoardSettings.SendWelcomeNotificationAfterRegister.Equals(2)) { var users = this.GetRepository <User>().UserList( YafContext.Current.PageBoardID, null, true, null, null, null).ToList(); var hostUser = users.FirstOrDefault(u => u.IsHostAdmin > 0); YafContext.Current.GetRepository <PMessage>().SendMessage( hostUser.UserID.Value, userId.Value, subject, emailBody, messageFlags.BitValue, -1); } else { this.GetRepository <Mail>() .Create( user.Email, user.UserName, subject, emailBody); } }
/// <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="spamApproved">if set to <c>true</c> [spam approved].</param> public void ToModeratorsThatMessageNeedsApproval(int forumId, int newMessageId, bool spamApproved) { 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", spamApproved ? "NOTIFICATION_ON_MODERATOR_MESSAGE_APPROVAL" : "NOTIFICATION_ON_MODERATOR_SPAMMESSAGE_APPROVAL", languageFile) .FormatWith(this.Get <YafBoardSettings>().Name); var notifyModerators = new YafTemplateEmail( spamApproved ? "NOTIFICATION_ON_MODERATOR_MESSAGE_APPROVAL" : "NOTIFICATION_ON_MODERATOR_SPAMMESSAGE_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); } }
/// <summary> /// Sends a spam bot notification to admins. /// </summary> /// <param name="user">The user.</param> /// <param name="userId">The user id.</param> public void SendSpamBotNotificationToAdmins([NotNull] MembershipUser user, int userId) { // Get Admin Group ID var adminGroupID = this.GetRepository <Group>() .ListTyped(boardId: YafContext.Current.PageBoardID) .Where(@group => @group.Name.Contains("Admin")) .Select(@group => @group.ID) .FirstOrDefault(); if (adminGroupID <= 0) { return; } using (DataTable dt = LegacyDb.user_emails(YafContext.Current.PageBoardID, adminGroupID)) { foreach (DataRow row in dt.Rows) { var emailAddress = row.Field <string>("Email"); if (!emailAddress.IsSet()) { continue; } var notifyAdmin = new YafTemplateEmail(); var subject = this.Get <ILocalization>() .GetText("COMMON", "NOTIFICATION_ON_BOT_USER_REGISTER_EMAIL_SUBJECT") .FormatWith(this.BoardSettings.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.BoardSettings.Name; var emailBody = notifyAdmin.ProcessTemplate("NOTIFICATION_ON_BOT_USER_REGISTER"); this.GetRepository <Mail>() .Create( emailAddress, null, subject, emailBody); } } }
/// <summary> /// Sends a spam bot notification to admins. /// </summary> /// <param name="user">The user.</param> /// <param name="userId">The user id.</param> public static void SendSpamBotNotificationToAdmins([NotNull] MembershipUser user, int userId) { // Get Admin Group ID var adminGroupID = 1; foreach (DataRow dataRow in LegacyDb.group_list(YafContext.Current.Get <YafBoardSettings>().BoardID, 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(YafContext.Current.Get <YafBoardSettings>().BoardID, adminGroupID)) { foreach (DataRow row in dt.Rows) { var emailAddress = row.Field <string>("Email"); if (!emailAddress.IsSet()) { continue; } var notifyAdmin = new YafTemplateEmail(); string subject = YafContext.Current.Get <ILocalization>() .GetText("COMMON", "NOTIFICATION_ON_BOT_USER_REGISTER_EMAIL_SUBJECT") .FormatWith(YafContext.Current.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}"] = YafContext.Current.Get <YafBoardSettings>().Name; string emailBody = notifyAdmin.ProcessTemplate("NOTIFICATION_ON_BOT_USER_REGISTER"); YafContext.Current.GetRepository <Mail>() .Create(YafContext.Current.Get <YafBoardSettings>().ForumEmail, emailAddress, subject, emailBody); } } }
/// <summary> /// Sends a spam bot notification to admins. /// </summary> /// <param name="user">The user.</param> /// <param name="userId">The user id.</param> public void SendSpamBotNotificationToAdmins([NotNull] MembershipUser user, int userId) { // Get Admin Group ID var adminGroupId = this.GetRepository <Group>().List(boardId: YafContext.Current.PageBoardID) .Where(group => group.Name.Contains("Admin")).Select(group => group.ID).FirstOrDefault(); if (adminGroupId <= 0) { return; } using (var dt = this.GetRepository <User>().EmailsAsDataTable(YafContext.Current.PageBoardID, adminGroupId)) { dt.Rows.Cast <DataRow>().ForEach( row => { var emailAddress = row.Field <string>("Email"); if (emailAddress.IsNotSet()) { return; } var subject = this.Get <ILocalization>().GetTextFormatted( "COMMON", "NOTIFICATION_ON_BOT_USER_REGISTER_EMAIL_SUBJECT", this.BoardSettings.Name); var notifyAdmin = new YafTemplateEmail { TemplateParams = { ["{adminlink}"] = YafBuildLink.GetLinkNotEscaped( ForumPages.admin_edituser, true, "u={0}", userId), ["{user}"] = user.UserName, ["{email}"] = user.Email, ["{forumname}"] = this.BoardSettings.Name } }; var emailBody = notifyAdmin.ProcessTemplate("NOTIFICATION_ON_BOT_USER_REGISTER"); this.GetRepository <Mail>().Create(emailAddress, null, subject, emailBody); }); } }
/// <summary> /// Sends the role assignment notification. /// </summary> /// <param name="user">The user.</param> /// <param name="addedRoles">The added roles.</param> public void SendRoleAssignmentNotification([NotNull] MembershipUser user, List <string> addedRoles) { var templateEmail = new YafTemplateEmail(); var subject = this.Get <ILocalization>().GetTextFormatted( "NOTIFICATION_ROLE_ASSIGNMENT_SUBJECT", this.BoardSettings.Name); templateEmail.TemplateParams["{user}"] = user.UserName; templateEmail.TemplateParams["{roles}"] = string.Join(", ", addedRoles.ToArray()); templateEmail.TemplateParams["{forumname}"] = this.BoardSettings.Name; templateEmail.TemplateParams["{forumurl}"] = YafForumInfo.ForumURL; var emailBody = templateEmail.ProcessTemplate("NOTIFICATION_ROLE_ASSIGNMENT"); this.GetRepository <Mail>().Create(user.Email, user.UserName, subject, emailBody); }
/// <summary> /// Sends the verification email. /// </summary> /// <param name="user">The user.</param> /// <param name="email">The email.</param> /// <param name="userId">The user identifier.</param> /// <param name="newUsername">The new username.</param> public void SendVerificationEmail( [NotNull] MembershipUser user, [NotNull] string email, int?userId, string newUsername = null) { CodeContracts.VerifyNotNull(email, "email"); CodeContracts.VerifyNotNull(user, "user"); var hashInput = $"{DateTime.UtcNow}{email}{Security.CreatePassword(20)}"; var hash = FormsAuthentication.HashPasswordForStoringInConfigFile(hashInput, "md5"); // save verification record... this.GetRepository <CheckEmail>().Save(userId, hash, user.Email); var subject = this.Get <ILocalization>().GetTextFormatted( "VERIFICATION_EMAIL_SUBJECT", this.BoardSettings.Name); var logoUrl = $"{YafForumInfo.ForumClientFileRoot}{YafBoardFolders.Current.Logos}/{this.BoardSettings.ForumLogo}"; var themeCss = $"{this.Get<YafBoardSettings>().BaseUrlMask}{this.Get<ITheme>().BuildThemePath("bootstrap-forum.min.css")}"; var verifyEmail = new YafTemplateEmail("VERIFYEMAIL") { TemplateParams = { ["{link}"] = YafBuildLink.GetLinkNotEscaped( ForumPages.approve, true, "k={0}", hash), ["{key}"] = hash, ["{forumname}"] = this.BoardSettings.Name, ["{forumlink}"] = $"{YafForumInfo.ForumURL}", ["{username}"] = user.UserName, ["{themecss}"] = themeCss, ["{logo}"] = $"{this.Get<YafBoardSettings>().BaseUrlMask}{logoUrl}" } }; verifyEmail.SendEmail(new MailAddress(email, newUsername ?? user.UserName), subject, true); }
/// <summary> /// Sends the user a suspension notification. /// </summary> /// <param name="email">The email.</param> /// <param name="userName">Name of the user.</param> public void SendUserSuspensionEndedNotification([NotNull] string email, [NotNull] string userName) { var subject = this.Get <ILocalization>().GetTextFormatted( "NOTIFICATION_ON_SUSPENDING_USER_SUBJECT", this.BoardSettings.Name); var notifyUser = new YafTemplateEmail { TemplateParams = { ["{user}"] = userName, ["{forumname}"] = this.BoardSettings.Name, ["{forumurl}"] = YafForumInfo.ForumURL } }; var emailBody = notifyUser.ProcessTemplate("NOTIFICATION_ON_SUSPENDING_ENDED_USER"); this.GetRepository <Mail>().Create(email, userName, subject, emailBody); }
/// <summary> /// Send Email Verification to changed Email Address /// </summary> /// <param name="newEmail"> /// The new email. /// </param> /// <param name="userId"> /// The user Id. /// </param> /// <param name="userName"> /// The user Name. /// </param> public void SendEmailChangeVerification([NotNull] string newEmail, [NotNull] int userId, string userName) { var hashInput = $"{DateTime.UtcNow}{newEmail}{Security.CreatePassword(20)}"; var hash = FormsAuthentication.HashPasswordForStoringInConfigFile(hashInput, "md5"); var logoUrl = $"{YafForumInfo.ForumClientFileRoot}{YafBoardFolders.Current.Logos}/{YafContext.Current.BoardSettings.ForumLogo}"; var themeCss = $"{this.Get<YafBoardSettings>().BaseUrlMask}{this.Get<ITheme>().BuildThemePath("bootstrap-forum.min.css")}"; // Create Email var changeEmail = new YafTemplateEmail("CHANGEEMAIL") { TemplateParams = { ["{user}"] = userName, ["{link}"] = $"{YafBuildLink.GetLinkNotEscaped(ForumPages.approve, true, "k={0}", hash)}\r\n\r\n", ["{newemail}"] = newEmail, ["{key}"] = hash, ["{forumname}"] = this.Get <YafBoardSettings>().Name, ["{forumlink}"] = YafForumInfo.ForumURL, ["{themecss}"] = themeCss, ["{logo}"] = $"{this.Get<YafBoardSettings>().BaseUrlMask}{logoUrl}" } }; // save a change email reference to the db this.GetRepository <CheckEmail>().Save(userId, hash, newEmail); // send a change email message... changeEmail.SendEmail( new MailAddress(newEmail), this.Get <ILocalization>().GetText("COMMON", "CHANGEEMAIL_SUBJECT"), true); // show a confirmation YafContext.Current.AddLoadMessage( string.Format(this.Get <ILocalization>().GetText("PROFILE", "mail_sent"), newEmail), MessageTypes.info); }
/// <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); }
/// <summary> /// The send registration notification email. /// </summary> /// <param name="user"> /// The user. /// </param> private void SendRegistrationNotificationEmail([NotNull] MembershipUser user) { 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_admin, true); 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.Get<ISendMail>().Queue(this.Get<YafBoardSettings>().ForumEmail, email.Trim(), subject, emailBody); } }
/// <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.ProviderUserKey); 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); } }
/// <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)); } }
/// <summary> /// Sends the user a suspension notification. /// </summary> /// <param name="email">The email.</param> /// <param name="userName">Name of the user.</param> public void SendUserSuspensionEndedNotification([NotNull] string email, [NotNull] string userName) { var notifyUser = new YafTemplateEmail(); var subject = this.Get<ILocalization>() .GetText("COMMON", "NOTIFICATION_ON_SUSPENDING_USER_SUBJECT") .FormatWith(this.BoardSettings.Name); notifyUser.TemplateParams["{user}"] = userName; notifyUser.TemplateParams["{forumname}"] = this.BoardSettings.Name; notifyUser.TemplateParams["{forumurl}"] = YafForumInfo.ForumURL; var emailBody = notifyUser.ProcessTemplate("NOTIFICATION_ON_SUSPENDING_ENDED_USER"); this.GetRepository<Mail>() .Create( email, userName, subject, emailBody); }
/// <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)); }
/// <summary> /// Sends a spam bot notification to admins. /// </summary> /// <param name="user">The user.</param> /// <param name="userId">The user id.</param> public void SendSpamBotNotificationToAdmins([NotNull] MembershipUser user, int userId) { // Get Admin Group ID var adminGroupID = this.GetRepository<Group>() .ListTyped(boardId: YafContext.Current.PageBoardID) .Where(@group => @group.Name.Contains("Admin")) .Select(@group => @group.ID) .FirstOrDefault(); if (adminGroupID <= 0) { return; } using (DataTable dt = LegacyDb.user_emails(YafContext.Current.PageBoardID, adminGroupID)) { foreach (DataRow row in dt.Rows) { var emailAddress = row.Field<string>("Email"); if (!emailAddress.IsSet()) { continue; } var notifyAdmin = new YafTemplateEmail(); var subject = this.Get<ILocalization>() .GetText("COMMON", "NOTIFICATION_ON_BOT_USER_REGISTER_EMAIL_SUBJECT") .FormatWith(this.BoardSettings.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.BoardSettings.Name; var emailBody = notifyAdmin.ProcessTemplate("NOTIFICATION_ON_BOT_USER_REGISTER"); this.GetRepository<Mail>() .Create( emailAddress, null, subject, emailBody); } } }
/// <summary> /// Sends the user welcome notification. /// </summary> /// <param name="user">The user.</param> /// <param name="userId">The user identifier.</param> public void SendUserWelcomeNotification([NotNull] MembershipUser user, int? userId) { if (this.BoardSettings.SendWelcomeNotificationAfterRegister.Equals(0)) { return; } var notifyUser = new YafTemplateEmail(); var subject = this.Get<ILocalization>() .GetText("COMMON", "NOTIFICATION_ON_WELCOME_USER_SUBJECT") .FormatWith(this.BoardSettings.Name); notifyUser.TemplateParams["{user}"] = user.UserName; notifyUser.TemplateParams["{forumname}"] = this.BoardSettings.Name; notifyUser.TemplateParams["{forumurl}"] = YafForumInfo.ForumURL; var emailBody = notifyUser.ProcessTemplate("NOTIFICATION_ON_WELCOME_USER"); var messageFlags = new MessageFlags { IsHtml = false, IsBBCode = true }; if (this.BoardSettings.AllowPrivateMessages && this.BoardSettings.SendWelcomeNotificationAfterRegister.Equals(2)) { var users = LegacyDb.UserList(YafContext.Current.PageBoardID, null, true, null, null, null).ToList(); var hostUser = users.FirstOrDefault(u => u.IsHostAdmin > 0); LegacyDb.pmessage_save(hostUser.UserID.Value, userId, subject, emailBody, messageFlags.BitValue, -1); } else { this.GetRepository<Mail>() .Create( user.Email, user.UserName, subject, emailBody); } }
/// <summary> /// Send an Email 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="templateName"> /// The template Name. /// </param> public void SendRegistrationNotificationToUser( [NotNull] MembershipUser user, [NotNull] string pass, [NotNull] string securityAnswer, string templateName) { var notifyUser = new YafTemplateEmail(); var subject = this.Get<ILocalization>() .GetText("COMMON", "NOTIFICATION_ON_NEW_FACEBOOK_USER_SUBJECT") .FormatWith(this.BoardSettings.Name); notifyUser.TemplateParams["{user}"] = user.UserName; notifyUser.TemplateParams["{email}"] = user.Email; notifyUser.TemplateParams["{pass}"] = pass; notifyUser.TemplateParams["{answer}"] = securityAnswer; notifyUser.TemplateParams["{forumname}"] = this.BoardSettings.Name; var emailBody = notifyUser.ProcessTemplate(templateName); this.GetRepository<Mail>() .Create( user.Email, user.UserName, subject, emailBody); }
/// <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); }
/// <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); } }
/// <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); } }
/// <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); } } }
/// <summary> /// The forum register_ click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void ForumRegister_Click([NotNull] object sender, [NotNull] EventArgs e) { if (!this.Page.IsValid) { return; } string newEmail = this.Email.Text.Trim(); string newUsername = this.UserName.Text.Trim(); if (!ValidationHelper.IsValidEmail(newEmail)) { this.PageContext.AddLoadMessage(this.GetText("ADMIN_REGUSER", "MSG_INVALID_MAIL")); 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); }
/// <summary> /// The to watching users. /// </summary> /// <param name="newMessageId"> /// The new message id. /// </param> public void ToWatchingUsers(int newMessageId) { // Always send watch mails with boards default language var languageFile = this.BoardSettings.Language; var boardName = this.BoardSettings.Name; var forumEmail = this.BoardSettings.ForumEmail; var message = this.GetRepository <Message>().MessageList(newMessageId).FirstOrDefault(); var messageAuthorUserID = message.UserID ?? 0; var watchEmail = new YafTemplateEmail("TOPICPOST") { TemplateLanguageFile = languageFile }; // cleaned body as text... var bodyText = this.Get <IBadWordReplace>() .Replace(BBCodeHelper.StripBBCode(HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString(message.Message)))) .RemoveMultipleWhitespace(); // Send track mails var subject = string.Format( this.Get <ILocalization>().GetText("COMMON", "TOPIC_NOTIFICATION_SUBJECT", languageFile), boardName); var logoUrl = $"{YafForumInfo.ForumClientFileRoot}{YafBoardFolders.Current.Logos}/{this.BoardSettings.ForumLogo}"; var themeCss = $"{this.Get<YafBoardSettings>().BaseUrlMask}{this.Get<ITheme>().BuildThemePath("bootstrap-forum.min.css")}"; watchEmail.TemplateParams["{forumname}"] = boardName; watchEmail.TemplateParams["{topic}"] = HttpUtility.HtmlDecode(this.Get <IBadWordReplace>().Replace(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.TemplateParams["{subscriptionlink}"] = YafBuildLink.GetLinkNotEscaped(ForumPages.cp_subscriptions, true); watchEmail.TemplateParams["{forumname}"] = this.BoardSettings.Name; watchEmail.TemplateParams["{forumlink}"] = $"{YafForumInfo.ForumURL}"; watchEmail.TemplateParams["{themecss}"] = themeCss; watchEmail.TemplateParams["{logo}"] = $"{this.Get<YafBoardSettings>().BaseUrlMask}{logoUrl}"; watchEmail.CreateWatch( message.TopicID ?? 0, messageAuthorUserID, new MailAddress(forumEmail, boardName), subject); if (!this.BoardSettings.AllowNotificationAllPostsAllTopics) { return; } var usersWithAll = this.GetRepository <User>().FindUserTyped( false, notificationType: UserNotificationSetting.AllTopics.ToInt()); // create individual watch emails for all users who have All Posts on... usersWithAll.Where(x => x.ID != messageAuthorUserID && x.ProviderUserKey != null).ForEach( user => { if (user.Email.IsNotSet()) { return; } watchEmail.TemplateLanguageFile = user.LanguageFile.IsSet() ? user.LanguageFile : this.Get <ILocalization>().LanguageFileName; watchEmail.SendEmail( new MailAddress(forumEmail, boardName), new MailAddress( user.Email, this.BoardSettings.EnableDisplayName ? user.DisplayName : user.Name), subject, true); }); }
/// <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.BoardSettings.AllowNotificationAllPostsAllTopics) { // TODO: validate permissions! usersWithAll = LegacyDb.UserFind( 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 string languageFile = this.BoardSettings.Language; string boardName = this.BoardSettings.Name; string forumEmail = this.BoardSettings.ForumEmail; foreach (var message in LegacyDb.MessageList(newMessageId)) { int userId = 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(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(forumEmail, boardName), 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 == null || !membershipUser.Email.IsSet()) { continue; } watchEmail.TemplateLanguageFile = !string.IsNullOrEmpty(user.LanguageFile) ? user.LanguageFile : this.Get <ILocalization>().LanguageFileName; watchEmail.SendEmail( new MailAddress(forumEmail, boardName), new MailAddress(membershipUser.Email, membershipUser.UserName), subject, true); } } }
/// <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 toUser = this.GetRepository <User>().UserList( YafContext.Current.PageBoardID, toUserId, true, null, null, null).FirstOrDefault(); if (toUser != null) { privateMessageNotificationEnabled = toUser.PMNotification ?? false; toEMail = toUser.Email; } if (!privateMessageNotificationEnabled) { return; } // get the PM ID var userPMessageId = this.GetRepository <PMessage>().ListAsDataTable(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}"] = $"{YafBuildLink.GetLinkNotEscaped(ForumPages.cp_message, true, "pm={0}", userPMessageId)}\r\n\r\n"; notificationTemplate.TemplateParams["{forumname}"] = this.BoardSettings.Name; notificationTemplate.TemplateParams["{subject}"] = subject; notificationTemplate.TemplateParams["{username}"] = this.BoardSettings.EnableDisplayName ? toUser.DisplayName : toUser.Name; var logoUrl = $"{YafForumInfo.ForumClientFileRoot}{YafBoardFolders.Current.Logos}/{this.BoardSettings.ForumLogo}"; var themeCss = $"{this.Get<YafBoardSettings>().BaseUrlMask}{this.Get<ITheme>().BuildThemePath("bootstrap-forum.min.css")}"; notificationTemplate.TemplateParams["{forumlink}"] = $"{YafForumInfo.ForumURL}"; notificationTemplate.TemplateParams["{themecss}"] = themeCss; notificationTemplate.TemplateParams["{logo}"] = $"{this.Get<YafBoardSettings>().BaseUrlMask}{logoUrl}"; // create notification email subject var emailSubject = string.Format( this.Get <ILocalization>().GetText("COMMON", "PM_NOTIFICATION_SUBJECT", languageFile), 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 {YafContext.Current.PageUserID}"); // tell user about failure YafContext.Current.AddLoadMessage( this.Get <ILocalization>().GetTextFormatted("Failed", x.Message), MessageTypes.danger); } }
/// <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 o Auth. /// </param> private static void SendRegistrationMessageToUser([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_FACEBOOK_REGISTER"); var messageFlags = new MessageFlags { IsHtml = false, IsBBCode = true }; // Send Message also as DM to Twitter. var tweetApi = new TweetAPI(oAuth); if (YafContext.Current.Get<YafBoardSettings>().AllowPrivateMessages) { LegacyDb.pmessage_save(2, userId, subject, emailBody, messageFlags.BitValue); string message = "{0}. {1}".FormatWith( subject, YafContext.Current.Get<ILocalization>().GetText("LOGIN", "TWITTER_DM")); tweetApi.SendDirectMessage(TweetAPI.ResponseFormat.json, user.UserName, message.Truncate(140)); } else { string message = YafContext.Current.Get<ILocalization>().GetTextFormatted( "LOGIN", "TWITTER_DM", YafContext.Current.Get<YafBoardSettings>().Name, user.UserName, pass); tweetApi.SendDirectMessage(TweetAPI.ResponseFormat.json, user.UserName, message.Truncate(140)); } }
/// <summary> /// Send an Email 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> private static void SendRegistrationNotificationToUser( [NotNull] MembershipUser user, [NotNull] string pass, [NotNull] string securityAnswer) { 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_FACEBOOK_REGISTER"); YafContext.Current.Get<ISendMail>().Queue(YafContext.Current.Get<YafBoardSettings>().ForumEmail, user.Email, subject, emailBody); }
/// <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 bool privateMessageNotificationEnabled = false; // user's email var toEMail = string.Empty; var userList = LegacyDb.UserList(YafContext.Current.PageBoardID, toUserId, true, null, null, null); 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)) int 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.Get <YafBoardSettings>().Name; notificationTemplate.TemplateParams["{subject}"] = subject; // create notification email subject var emailSubject = this.Get <ILocalization>() .GetText("COMMON", "PM_NOTIFICATION_SUBJECT", languageFile) .FormatWith(displayName, this.Get <YafBoardSettings>().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); } }
/// <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: "******": ") + 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. 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; }
/// <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)); } }
/// <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> /// 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; } }
/// <summary> /// The send verification email. /// </summary> /// <param name="user"> /// The user. /// </param> /// <param name="userID"> /// The user id. /// </param> private void SendVerificationEmail([NotNull] 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... LegacyDb.checkemail_save(userID, hash, user.Email); 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}", hash); verifyEmail.TemplateParams["{key}"] = hash; verifyEmail.TemplateParams["{forumname}"] = this.Get<YafBoardSettings>().Name; verifyEmail.TemplateParams["{forumlink}"] = "{0}".FormatWith(YafForumInfo.ForumURL); verifyEmail.SendEmail(new MailAddress(email, user.UserName), subject, true); }
/// <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); } } }
/// <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); } }
/// <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); }
/// <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)); } }