async Task <User> GetUserToValidateAsync(IEntityReply reply) { // Get author var user = await _platoUserStore.GetByIdAsync(reply.CreatedUserId); // Ensure we found the user if (user == null) { return(null); } // Use IP information from reply if (!string.IsNullOrEmpty(reply.IpV4Address)) { if (!reply.IpV4Address.Equals(user.IpV4Address, StringComparison.OrdinalIgnoreCase)) { user.IpV4Address = reply.IpV4Address; } } if (!string.IsNullOrEmpty(reply.IpV6Address)) { if (!reply.IpV6Address.Equals(user.IpV6Address, StringComparison.OrdinalIgnoreCase)) { user.IpV6Address = reply.IpV6Address; } } return(user); }
public async Task <IViewComponentResult> InvokeAsync(IEntity entity, IEntityReply reply) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } return(View(new EntityFilesViewModel() { Results = await _entityAttachmentStore.GetByEntityIdAsync(entity.Id) })); }
async Task <User> BuildUserAsync(IEntityReply reply) { var user = await _platoUserStore.GetByIdAsync(reply.CreatedUserId); if (user == null) { return(null); } // Ensure we check against the IP address being used at the time of the post user.IpV4Address = reply.IpV4Address; user.IpV6Address = reply.IpV6Address; return(user); }
public static bool IsHidden(this IEntityReply reply) { if (reply.IsHidden) { return(true); } if (reply.IsDeleted) { return(true); } if (reply.IsSpam) { return(true); } return(false); }
// ----------------- // Index // Displays a summary from StopForumSpam. // ----------------- public async Task <IActionResult> Index(EntityOptions opts) { if (opts == null) { opts = new EntityOptions(); } // We always need an entity Id if (opts.Id <= 0) { throw new ArgumentOutOfRangeException(nameof(opts.Id)); } // We always need an entity var entity = await _entityStore.GetByIdAsync(opts.Id); if (entity == null) { return(NotFound()); } // Ensure we have permission if (!await _authorizationService.AuthorizeAsync(User, entity.CategoryId, Permissions.ViewStopForumSpam)) { return(Unauthorized()); } // Get reply IEntityReply reply = null; if (opts.ReplyId > 0) { reply = await _entityReplyStore.GetByIdAsync(opts.ReplyId); if (reply == null) { return(NotFound()); } } // Get user to validate var user = reply != null ? await GetUserToValidateAsync(reply) : await GetUserToValidateAsync(entity); // Ensure we found the user if (user == null) { return(NotFound()); } // Build view model var viewModel = new StopForumSpamViewModel() { Options = opts, Checker = await _spamChecker.CheckAsync(user) }; // Return view return(View(viewModel)); }
// ----------------- // AddSpammer // ----------------- public async Task <IActionResult> AddSpammer(EntityOptions opts) { // Disable functionality within demo mode if (_platoOpts.DemoMode) { return(Unauthorized()); } // Empty options if (opts == null) { opts = new EntityOptions(); } // Validate if (opts.Id <= 0) { throw new ArgumentOutOfRangeException(nameof(opts.Id)); } // Get entity var entity = await _entityStore.GetByIdAsync(opts.Id); // Ensure the topic exists if (entity == null) { return(NotFound()); } // Ensure we have permission if (!await _authorizationService.AuthorizeAsync(User, entity.CategoryId, Permissions.AddToStopForumSpam)) { return(Unauthorized()); } // Get reply IEntityReply reply = null; if (opts.ReplyId > 0) { reply = await _entityReplyStore.GetByIdAsync(opts.ReplyId); } // Get user for reply or entity var user = reply != null ? await GetUserToValidateAsync(reply) : await GetUserToValidateAsync(entity); // Ensure we found the user if (user == null) { return(NotFound()); } // Add spammer for reply or entity var result = await AddSpammerAsync(user); // Confirmation if (result.Success) { _alerter.Success(T["Spammer Added Successfully"]); } else { _alerter.Danger(!string.IsNullOrEmpty(result.Error) ? T[result.Error] : T["An unknown error occurred adding the user to the StopForumSpam database."]); } // Redirect back to reply if (reply != null) { return(Redirect(_contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = "Plato.Docs", ["controller"] = "Home", ["action"] = "Reply", ["opts.id"] = entity.Id, ["opts.alias"] = entity.Alias, ["opts.replyId"] = reply.Id }))); } // Redirect back to entity return(Redirect(_contextFacade.GetRouteUrl(new RouteValueDictionary() { ["area"] = "Plato.Docs", ["controller"] = "Home", ["action"] = "Display", ["opts.id"] = entity.Id, ["opts.alias"] = entity.Alias }))); }