Beispiel #1
0
        public async Task <ISpamOperatorResult <Reply> > UpdateModelAsync(ISpamOperatorContext <Reply> context)
        {
            // Perform validation
            var validation = await ValidateModelAsync(context);

            // Create result
            var result = new SpamOperatorResult <Reply>();

            // Not an operator of interest
            if (validation == null)
            {
                return(result.Success(context.Model));
            }

            // If validation succeeded no need to perform further actions
            if (validation.Succeeded)
            {
                return(result.Success(context.Model));
            }

            // Get reply author
            var user = await BuildUserAsync(context.Model);

            if (user == null)
            {
                return(null);
            }

            // Flag user as SPAM?
            if (context.Operation.FlagAsSpam)
            {
                var bot = await _platoUserStore.GetPlatoBotAsync();

                // Mark user as SPAM
                if (!user.IsSpam)
                {
                    user.IsSpam = true;
                    user.IsSpamUpdatedUserId = bot?.Id ?? 0;
                    user.IsSpamUpdatedDate   = DateTimeOffset.UtcNow;
                    await _platoUserStore.UpdateAsync(user);
                }

                // Mark reply as SPAM
                if (!context.Model.IsSpam)
                {
                    context.Model.IsSpam = true;
                    await _replyStore.UpdateAsync(context.Model);
                }
            }

            // Defer notifications for execution after request completes
            _deferredTaskManager.AddTask(async ctx =>
            {
                await NotifyAsync(context);
            });

            // Return failed with our updated model and operation
            // This provides the calling code with the operation error message
            return(result.Failed(context.Model, context.Operation));
        }
Beispiel #2
0
        public async Task <ISpamOperatorResult <User> > ValidateModelAsync(ISpamOperatorContext <User> context)
        {
            // Ensure correct operation provider
            if (!context.Operation.Name.Equals(SpamOperations.Login.Name, StringComparison.Ordinal))
            {
                return(null);
            }

            // Create result
            var result = new SpamOperatorResult <User>();

            // User is OK
            var spamResult = await _spamChecker.CheckAsync(context.Model);

            if (spamResult.Succeeded)
            {
                return(result.Success(context.Model));
            }

            // Return failed with our updated model and operation
            // This provides the calling code with the operation error message
            return(result.Failed(context.Model, context.Operation));
        }
Beispiel #3
0
        public async Task <ISpamOperatorResult <Reply> > ValidateModelAsync(ISpamOperatorContext <Reply> context)
        {
            // Ensure correct operation provider
            if (!context.Operation.Name.Equals(SpamOperations.Reply.Name, StringComparison.Ordinal))
            {
                return(null);
            }

            // Get user for reply
            var user = await BuildUserAsync(context.Model);

            if (user == null)
            {
                return(null);
            }

            // Create result
            var result = new SpamOperatorResult <Reply>();

            // Check if user is already flagged as SPAM within Plato
            if (user.IsSpam)
            {
                return(result.Failed(context.Model, context.Operation));
            }

            // Check StopForumSpam service
            var spamResult = await _spamChecker.CheckAsync(user);

            if (spamResult.Succeeded)
            {
                return(result.Success(context.Model));
            }

            // Return failed with our updated model and operation
            // This provides the calling code with the operation error message
            return(result.Failed(context.Model, context.Operation));
        }