コード例 #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log, ExecutionContext context)
        {
            var formContents = await FormContentsFactory.Create(req);

            var comment  = CommentFactory.Create(formContents);
            var settings = SettingsFactory.Create(formContents.Options.Origin, log);

            var reCaptcha         = new ReCaptchaService(settings.ReCaptchaSecretKey, log);
            var reCaptchaResponse = await reCaptcha.Validate(formContents.Options.Recaptcha.Token);

            var akismetService  = new AkismetService(settings, log);
            var akismetResponse = await akismetService.IsSpam(req, comment, formContents);

            var gitHubService = new GitHubService(settings.GitHubOwner, settings.GitHubRepository, settings.GitHubBranch,
                                                  settings.GitHubCommentPath, settings.GitHubToken);
            var knownCommenterResponse = await gitHubService.IsKnownCommenter(comment.Name, comment.Email);

            var analyzer       = new ModerationAnalyzer(settings, log);
            var analysisReport = analyzer.NeedsModeration(comment, reCaptchaResponse, akismetResponse, knownCommenterResponse);

            await gitHubService.AddComment(comment, analysisReport, knownCommenterResponse);

            return(new OkResult());
        }
コード例 #2
0
ファイル: CommentService.cs プロジェクト: uzambara/pizza
        public async Task <CommentModel> CreateCommentAsync(AddCommentRequest request)
        {
            var user = await _userService.GetUserByPhoneAsync(request.Phone);

            if (user == null)
            {
                user = _userEntityFactory.Create(
                    request.Name,
                    null,
                    request.Phone,
                    null,
                    CreateUserPlace.FromComment);
                _userRepository.Add(user);
            }

            var comment = _commentFactory.Create(user, request.Text, request.Stars);

            _commentRepository.Add(comment);
            await _commentRepository.SaveChangesAsync();

            return(_mapper.Map <CommentModel>(comment));
        }