예제 #1
0
    public void OnClick()
    {
        GetComponent <AudioSource>().clip = clickBtn;
        GetComponent <AudioSource>().Play();

        if (!passText.Text.ToString().Equals(""))
        {
            HTTP.Client.Instance.Configure(new HTTP.Settings(TriviaService.GetHostAddress()).Protocol(HTTP.Protocol.HTTP));

            new HTTP.Request(TriviaService.GetHttpFolderPath() + "update_pass.php?user_id=" + GameConstant.UserId + "&user_pass="******"Pass not valid.";
            invalidText.IsVisible = true;
        }
    }
예제 #2
0
        public async Task UpdateAsync(UpdateReply command)
        {
            await _updateValidator.ValidateCommandAsync(command);

            var reply = await _dbContext.Posts
                        .FirstOrDefaultAsync(x =>
                                             x.Id == command.Id &&
                                             x.TopicId == command.TopicId &&
                                             x.Topic.ForumId == command.ForumId &&
                                             x.Topic.Forum.Category.SiteId == command.SiteId &&
                                             x.Status != PostStatusType.Deleted);

            if (reply == null)
            {
                throw new DataException($"Reply with Id {command.Id} not found.");
            }

            reply.UpdateDetails(command.UserId, command.Content, command.Status);

            _dbContext.Events.Add(new Event(command.SiteId,
                                            command.UserId,
                                            EventType.Updated,
                                            typeof(Post),
                                            command.Id,
                                            new
            {
                command.Content,
                command.Status
            }));

            await _dbContext.SaveChangesAsync();
        }
예제 #3
0
        public async Task <Comment> UpdateAsync(Comment comment)
        {
            UpdateReply c = await serviceClient.UpdateAsync(new UpdateRequest { Id = comment.Id, Subject = comment.Subject, Body = comment.Body });

            return(new Comment {
                Id = c.Id, PhotoId = c.PhotoId, UserName = c.UserName, Subject = c.Subject, Body = c.Body, SubmittedOn = c.SubmittedOn.ToDateTime()
            });
        }
예제 #4
0
        public async Task <Comment> UpdateAsync(Comment comment, string tokenValue)
        {
            Grpc.Core.Metadata headers = new Grpc.Core.Metadata();
            headers.Add("Authorization", $"Bearer {tokenValue}");

            UpdateReply c = await commentsThingClient.UpdateAsync(comment.ToUpdateRequest(), headers);

            return(c.ToComment());
        }
예제 #5
0
        public async Task <Photo> UpdateAsync(Photo photo, string tokenValue)
        {
            Grpc.Core.Metadata headers = new Grpc.Core.Metadata();
            headers.Add("Authorization", $"Bearer {tokenValue}");

            UpdateReply p = await photosThingClient.UpdateAsync(photo.ToUpdateRequest(), headers);

            return(p.ToPhoto());
        }
예제 #6
0
        public async Task <ActionResult> UpdateReply(TopicPageModel model)
        {
            var site = await _contextService.CurrentSiteAsync();

            var user = await _contextService.CurrentUserAsync();

            var command = new UpdateReply
            {
                Id      = model.Post.Id.Value,
                ForumId = model.Forum.Id,
                TopicId = model.Topic.Id,
                Content = model.Post.Content,
                Status  = PostStatusType.Published,
                SiteId  = site.Id,
                UserId  = user.Id
            };

            var replyUserId = await _dbContext.Posts
                              .Where(x =>
                                     x.Id == command.Id &&
                                     x.TopicId == command.TopicId &&
                                     x.Topic.ForumId == command.ForumId &&
                                     x.Topic.Forum.Category.SiteId == command.SiteId &&
                                     x.Status != PostStatusType.Deleted)
                              .Select(x => x.CreatedBy)
                              .FirstOrDefaultAsync();

            var permissions = await _permissionModelBuilder.BuildPermissionModelsByForumId(site.Id, model.Forum.Id);

            var canEdit     = _securityService.HasPermission(PermissionType.Edit, permissions);
            var canModerate = _securityService.HasPermission(PermissionType.Moderate, permissions);
            var authorized  = (canEdit && replyUserId == user.Id || canModerate) && !user.IsSuspended;

            if (!authorized)
            {
                _logger.LogWarning("Unauthorized access to update reply.", new
                {
                    SiteId  = site.Id,
                    ForumId = model.Forum?.Id,
                    TopicId = model.Topic?.Id,
                    ReplyId = model.Post?.Id,
                    User    = User.Identity.Name
                });

                return(Unauthorized());
            }

            await _replyService.UpdateAsync(command);

            return(Ok());
        }
예제 #7
0
        public void Map_UpdateToReply_MapsExpectedProperties()
        {
            var yesterday = DateTime.Today.AddDays(-1);
            var update    = new UpdateReply
            {
                Content = "Updated content"
            };
            var oldReply = new Reply
            {
                Content   = "Old reply",
                UpdatedAt = yesterday
            };

            var reply = Mapper.Map(update, oldReply);

            Assert.Equal(update.Content, reply.Content);
            Assert.True(yesterday < reply.UpdatedAt, "updated at was not updated");
        }
예제 #8
0
        public async Task <Reply> Update(int id, UpdateReply update)
        {
            var oldReply = await _replyRepository.Read(id);

            if (oldReply == null)
            {
                _logger.LogWarning($"Reply {id} not found");
                return(null);
            }
            if (!_userService.Is(oldReply.UserId))
            {
                _logger.LogWarning("User is authorized");
                return(null);
            }
            var reply = _mapper.Map(update, oldReply);

            await _replyRepository.Update(reply);

            return(reply);
        }
예제 #9
0
        public async Task Update_UserDoesNotOwnReply_DoesNotAttemptUpdate()
        {
            var oldReply = new Reply {
                Id = 1
            };
            var update = new UpdateReply();
            var reply  = new Reply
            {
                Id      = 1,
                Content = "hello"
            };

            A.CallTo(() => ReplyRepository.Read(1)).Returns(oldReply);
            A.CallTo(() => Mapper.Map(update, oldReply)).Returns(reply);
            A.CallTo(() => User.Is(oldReply.UserId)).Returns(false);

            await ReplyService.Update(oldReply.Id, update);

            A.CallTo(() => ReplyRepository.Update(A <Reply> .Ignored))
            .MustNotHaveHappened();
        }
예제 #10
0
        public async Task <Comment> UpdateAsync(Comment comment)
        {
            var tokenResult = await tokenProvider.RequestAccessToken(new AccessTokenRequestOptions()
            {
                Scopes = new string[] { "commentsgrpc" }
            });

            if (tokenResult.TryGetToken(out var token))
            {
                GrpCore.Metadata headers = new GrpCore.Metadata();
                headers.Add("Authorization", $"Bearer {token.Value}");

                UpdateReply c = await serviceClient.UpdateAsync(new UpdateRequest { Id = comment.Id, Subject = comment.Subject, Body = comment.Body }, headers);

                return(new Comment {
                    Id = c.Id, PhotoId = c.PhotoId, UserName = c.UserName, Subject = c.Subject, Body = c.Body, SubmittedOn = c.SubmittedOn.ToDateTime()
                });
            }
            else
            {
                throw new UnauthorizedEditAttemptException <Comment>();
            }
        }
예제 #11
0
        public async Task Update_EverythingOk_UpdatesReply()
        {
            var oldReply = new Reply {
                Id = 1
            };
            var update = new UpdateReply();
            var reply  = new Reply
            {
                Id      = 1,
                Content = "hello"
            };

            A.CallTo(() => ReplyRepository.Read(1)).Returns(oldReply);
            A.CallTo(() => Mapper.Map(update, oldReply)).Returns(reply);
            A.CallTo(() => User.Is(oldReply.UserId)).Returns(true);

            await ReplyService.Update(oldReply.Id, update);

            A.CallTo(() => ReplyRepository.Update(A <Reply> .That.Matches(r =>
                                                                          r.Id == reply.Id &&
                                                                          r.Content == reply.Content
                                                                          ))).MustHaveHappenedOnceExactly();
        }
 public static Comment ToComment(this UpdateReply c) => new Comment(c.Id, c.PhotoId, c.UserName, c.Subject, c.Body, c.SubmittedOn.ToDateTime());
예제 #13
0
        public async Task <ActionResult <ReplyResponse> > Update(int postId, int replyId, UpdateReply update)
        {
            var reply = await _replyService.Update(replyId, update);

            if (reply == null)
            {
                return(NotFound());
            }

            var response = _mapper.Map <ReplyResponse>(reply);

            response.Author = _userService.Auth().Username;

            return(Ok(response));
        }
예제 #14
0
 public static Photo ToPhoto(this UpdateReply p) => new Photo(p.Id, p.Title, p.PhotoFile.ToArray(), p.ImageMimeType, p.Description, p.CreatedDate.ToDateTime(), p.UserName, null);