/// <summary> /// Handles find users button click event. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void FindUsers_Click([NotNull] object sender, [NotNull] EventArgs e) { // try to find users by user name var users = LegacyDb.UserFind(this.PageContext.PageBoardID, true, this.UserName.Text, null, this.UserName.Text, null, null); if (!users.Any()) { return; } // we found a user(s) this.UserNameList.DataSource = users; this.UserNameList.DataValueField = "UserID"; this.UserNameList.DataTextField = "Name"; this.UserNameList.DataBind(); // hide To text box and show To drop down this.UserNameList.Visible = true; this.UserName.Visible = false; // find is no more needed this.FindUsers.Visible = false; // we need clear button displayed now this.Clear.Visible = true; }
public IDictionary<int, string> Find([NotNull] string contains) { IEnumerable<TypedUserFind> found; if (YafContext.Current.Get<YafBoardSettings>().EnableDisplayName) { found = LegacyDb.UserFind(YafContext.Current.PageBoardID, true, null, null, contains, null, null); return found.ToDictionary(k => k.UserID ?? 0, v => v.DisplayName); } found = LegacyDb.UserFind(YafContext.Current.PageBoardID, true, contains, null, null, null, null); return found.ToDictionary(k => k.UserID ?? 0, v => v.Name); }
/// <summary> /// Get the userid from the user name. /// </summary> /// <param name="name">The name.</param> /// <returns> /// The get id. /// </returns> public int? GetId([NotNull] string name) { int? userId = null; if (name.IsNotSet()) { return userId; } var keyValue = this.UserDisplayNameCollection .ToList() .FirstOrDefault(x => x.Value.IsSet() && x.Value.Equals(name, StringComparison.CurrentCultureIgnoreCase)); if (keyValue.IsNotDefault()) { userId = keyValue.Key; } else { // find the username... if (YafContext.Current.Get<YafBoardSettings>().EnableDisplayName) { var user = LegacyDb.UserFind(YafContext.Current.PageBoardID, false, null, null, name, null, null).FirstOrDefault(); if (user != null) { userId = user.UserID ?? 0; this.UserDisplayNameCollection.AddOrUpdate(userId.Value, k => user.DisplayName, (k, v) => user.DisplayName); } } else { var user = LegacyDb.UserFind(YafContext.Current.PageBoardID, false, name, null, null, null, null).FirstOrDefault(); if (user != null) { userId = user.UserID ?? 0; this.UserDisplayNameCollection.AddOrUpdate(userId.Value, k => user.DisplayName, (k, v) => user.DisplayName); } } } return userId; }
/// <summary> /// The send digest. /// </summary> private void SendDigest() { try { var boardIds = this.GetRepository <Board>().ListTyped().Select(b => b.ID); foreach (var boardId in boardIds) { var boardSettings = new YafLoadBoardSettings(boardId); if (!IsTimeToSendDigestForBoard(boardSettings)) { continue; } if (Config.BaseUrlMask.IsNotSet()) { // fail... this.Logger.Error( "DigestSendTask: Failed to send digest because BaseUrlMask value is not set in your appSettings."); return; } // get users with digest enabled... var usersWithDigest = LegacyDb.UserFind(boardId, false, null, null, null, null, true) .Where(x => !x.IsGuest && (x.IsApproved ?? false)); var typedUserFinds = usersWithDigest as IList <TypedUserFind> ?? usersWithDigest.ToList(); if (typedUserFinds.Any()) { // start sending... this.SendDigestToUsers(typedUserFinds, boardId, boardSettings); } } } catch (Exception ex) { this.Logger.Error(ex, "Error In {0} Task".FormatWith(TaskName)); } }
/// <summary> /// Handles click on save user button. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void AddUserSave_Click([NotNull] object sender, [NotNull] EventArgs e) { // test if there is specified unsername/user id if (this.UserID.Text.IsNotSet() && this.UserNameList.SelectedValue.IsNotSet() && this.UserName.Text.IsNotSet()) { // no username, nor userID specified this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITMEDAL", "MSG_VALID_USER"), MessageTypes.Warning); return; } if (this.UserNameList.SelectedValue.IsNotSet() && this.UserID.Text.IsNotSet()) { // only username is specified, we must find id for it var users = LegacyDb.UserFind(this.PageContext.PageBoardID, true, this.UserName.Text, null, this.UserName.Text, null, null); if (users.Count() > 1) { // more than one user is avalilable for this username this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITMEDAL", "MSG_AMBIGOUS_USER"), MessageTypes.Warning); return; } if (!users.Any()) { // no user found this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITMEDAL", "MSG_VALID_USER"), MessageTypes.Warning); return; } // save id to the control this.UserID.Text = (users.First().UserID ?? 0).ToString(); } else if (this.UserID.Text.IsNotSet()) { // user is selected in dropdown, we must get id to UserID control this.UserID.Text = this.UserNameList.SelectedValue; } // save user, if there is no message specified, pass null LegacyDb.user_medal_save( this.UserID.Text, this.Request.QueryString.GetFirstOrDefault("m"), this.UserMessage.Text.IsNotSet() ? null : this.UserMessage.Text, this.UserHide.Checked, this.UserOnlyRibbon.Checked, this.UserSortOrder.Text, null); if (this.Get <YafBoardSettings>().EmailUserOnMedalAward) { this.Get <ISendNotification>().ToUserWithNewMedal( this.UserID.Text.ToType <int>(), this.Name.Text); } // disable/hide edit controls this.AddUserCancel_Click(sender, e); // clear cache... this.RemoveUserFromCache(this.UserID.Text.ToType <int>()); // re-bind data this.BindData(); }
/// <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); } } }