/// <summary> /// Removes suspension from a user. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void RemoveSuspension_Click([NotNull] object sender, [NotNull] EventArgs e) { // un-suspend user LegacyDb.user_suspend(this.CurrentUserID, null); var usr = LegacyDb.UserList(this.PageContext.PageBoardID, (int?)this.CurrentUserID, null, null, null, false).ToList(); if (usr.Any()) { this.Get <ILogger>() .Log( this.PageContext.PageUserID, "YAF.Controls.EditUsersSuspend", "User {0} was unsuspended by {1}.".FormatWith( this.Get <YafBoardSettings>().EnableDisplayName ? usr.First().DisplayName : usr.First().Name, this.Get <YafBoardSettings>().EnableDisplayName ? this.PageContext.CurrentUserData.DisplayName : this.PageContext.CurrentUserData.UserName), EventLogTypes.UserUnsuspended); } this.Get <IRaiseEvent>().Raise(new UpdateUserEvent(this.CurrentUserID.ToType <int>())); // re-bind data this.BindData(); }
/// <summary> /// Binds the data. /// </summary> private void BindData() { this.ViewPostsLink.NavigateUrl = YafBuildLink.GetLinkNotEscaped( ForumPages.search, "postedby={0}", !this.CurrentUserDataHelper.IsGuest ? (this.Get <YafBoardSettings>().EnableDisplayName ? this.CurrentUserDataHelper.DisplayName : this.CurrentUserDataHelper.UserName) : UserMembershipHelper.GuestUserName); this.Kill.Text = this.GetText("ADMIN_EDITUSER", "HEAD_KILL_USER"); ControlHelper.AddOnClickConfirmDialog(this.Kill, this.GetText("ADMIN_EDITUSER", "KILL_USER_CONFIRM")); this.ReportUserRow.Visible = this.Get <YafBoardSettings>().StopForumSpamApiKey.IsSet(); // load ip address history for user... foreach (var ipAddress in this.IPAddresses) { this.IpAddresses.Text += "<a href=\"{0}\" target=\"_blank\" title=\"{1}\">{2}</a><br />".FormatWith( this.Get <YafBoardSettings>().IPInfoPageURL.FormatWith(ipAddress), this.GetText("COMMON", "TT_IPDETAILS"), ipAddress); } // if no ip disable BanIp checkbox if (this.IPAddresses.Any()) { this.BanIps.Checked = false; this.BanIps.Enabled = false; this.ReportUserRow.Visible = false; } // show post count... this.PostCount.Text = this.AllPostsByUser.Rows.Count.ToString(); // get user's info this.CurrentUser = LegacyDb.UserList( this.PageContext.PageBoardID, this.CurrentUserID.ToType <int?>(), null, null, null, false).FirstOrDefault(); // there is no such user if (this.CurrentUser != null && this.CurrentUser.Suspended.HasValue) { this.SuspendedTo.Visible = true; // is user suspended? this.SuspendedTo.Text = "({0} {1})".FormatWith( this.GetText("PROFILE", "ENDS"), this.Get <IDateTime>().FormatDateTime(this.CurrentUser.Suspended)); } this.DataBind(); }
/// <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> /// Bans the user IP Addresses. /// </summary> private void BanUserIps() { var usr = LegacyDb.UserList( this.PageContext.PageBoardID, this.CurrentUserID.ToType <int?>(), null, null, null, false).FirstOrDefault(); if (usr != null) { this.Logger .Log( this.PageContext.PageUserID, "YAF.Controls.EditUsersKill", "User {0} was killed by {1}".FormatWith( this.Get <YafBoardSettings>().EnableDisplayName ? usr.DisplayName : usr.Name, this.Get <YafBoardSettings>().EnableDisplayName ? this.PageContext.CurrentUserData.DisplayName : this.PageContext.CurrentUserData.UserName), EventLogTypes.UserSuspended); } var allIps = this.GetRepository <BannedIP>().ListTyped().Select(x => x.Mask).ToList(); // ban user ips... string name = UserMembershipHelper.GetDisplayNameFromID( this.CurrentUserID == null ? -1 : this.CurrentUserID.ToType <int>()); if (name.IsNotSet()) { name = UserMembershipHelper.GetUserNameFromID( this.CurrentUserID == null ? -1 : this.CurrentUserID.ToType <int>()); } foreach (var ip in this.IPAddresses.Except(allIps).ToList()) { string linkUserBan = this.Get <ILocalization>() .GetText("ADMIN_EDITUSER", "LINK_USER_BAN") .FormatWith( this.CurrentUserID, YafBuildLink.GetLink(ForumPages.profile, "u={0}&name={1}", this.CurrentUserID, name), this.HtmlEncode(name)); this.GetRepository <BannedIP>().Save(null, ip, linkUserBan, this.PageContext.PageUserID); } if (this.SuspendUser.Checked && this.CurrentUserID > 0) { LegacyDb.user_suspend(this.CurrentUserID, DateTime.UtcNow.AddYears(5)); } }
/// <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> /// 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> /// Suspends a user when clicked. /// </summary> /// <param name="sender"> /// The object sender inherit from Page. /// </param> /// <param name="e"> /// The System.EventArgs inherit from Page. /// </param> protected void Suspend_Click([NotNull] object sender, [NotNull] EventArgs e) { // Admins can suspend anyone not admins // Forum Moderators can suspend anyone not admin or forum moderator using (DataTable dt = LegacyDb.user_list(this.PageContext.PageBoardID, this.CurrentUserID, null)) { foreach (DataRow row in dt.Rows) { // is user to be suspended admin? if (row["IsAdmin"] != DBNull.Value && row["IsAdmin"].ToType <int>() > 0) { // tell user he can't suspend admin this.PageContext.AddLoadMessage(this.GetText("PROFILE", "ERROR_ADMINISTRATORS"), MessageTypes.Error); return; } // is user to be suspended forum moderator, while user suspending him is not admin? if (!this.PageContext.IsAdmin && int.Parse(row["IsForumModerator"].ToString()) > 0) { // tell user he can't suspend forum moderator when he's not admin this.PageContext.AddLoadMessage(this.GetText("PROFILE", "ERROR_FORUMMODERATORS"), MessageTypes.Error); return; } object isGuest = row["IsGuest"]; // verify the user isn't guest... if (isGuest != DBNull.Value && isGuest.ToType <int>() > 0) { this.PageContext.AddLoadMessage(this.GetText("PROFILE", "ERROR_GUESTACCOUNT"), MessageTypes.Error); return; } } } // time until when user is suspended DateTime suspend = DateTime.UtcNow; // number inserted by suspending user int count = int.Parse(this.SuspendCount.Text); // what time units are used for suspending switch (this.SuspendUnit.SelectedValue) { // days case "1": // add user inserted suspension time to current time suspend += new TimeSpan(count, 0, 0, 0); break; // hours case "2": // add user inserted suspension time to current time suspend += new TimeSpan(0, count, 0, 0); break; // minutes case "3": // add user inserted suspension time to current time suspend += new TimeSpan(0, 0, count, 0); break; } // suspend user by calling appropriate method LegacyDb.user_suspend(this.CurrentUserID, suspend); var usr = LegacyDb.UserList(this.PageContext.PageBoardID, this.CurrentUserID.ToType <int?>(), null, null, null, false).ToList(); if (usr.Any()) { this.Get <ILogger>() .Log( this.PageContext.PageUserID, "YAF.Controls.EditUsersSuspend", "User {0} was suspended by {1} until: {2} (UTC)".FormatWith( this.Get <YafBoardSettings>().EnableDisplayName ? usr.First().DisplayName : usr.First().Name, this.Get <YafBoardSettings>().EnableDisplayName ? this.PageContext.CurrentUserData.DisplayName : this.PageContext.CurrentUserData.UserName, suspend), EventLogTypes.UserSuspended); } this.Get <IRaiseEvent>().Raise(new UpdateUserEvent(this.CurrentUserID.ToType <int>())); // re-bind data this.BindData(); }