Example #1
0
        private void OnRegisterButtonClicked(
            UIRegistrationDetails uiRegistrationDetails)
        {
            var email           = uiRegistrationDetails.Email;
            var password        = uiRegistrationDetails.Password;
            var confirmPassword = uiRegistrationDetails.ConfirmPassword;
            var firstName       = uiRegistrationDetails.FirstName;
            var lastName        = uiRegistrationDetails.LastName;

            if (authenticationValidator.IsEmptyEmailAddress(email, out var message) ||
                authenticationValidator.IsInvalidEmailAddress(email, out message) ||
                authenticationValidator.IsEmptyPassword(password, out message) ||
                authenticationValidator.IsEmptyConfirmPassword(confirmPassword, out message) ||
                authenticationValidator.IsPasswordTooShort(password, out message) ||
                authenticationValidator.IsConfirmPasswordTooShort(confirmPassword, out message) ||
                authenticationValidator.ArePasswordsDoNotMatch(password, confirmPassword, out message) ||
                authenticationValidator.IsFirstNameEmpty(firstName, out message) ||
                authenticationValidator.IsLastNameEmpty(lastName, out message) ||
                authenticationValidator.IsFirstNameTooShort(firstName, out message) ||
                authenticationValidator.IsLastNameTooShort(lastName, out message))
            {
                NoticeUtils.ShowNotice(message);
            }
            else
            {
                registrationView?.DisableInteraction();
                authenticatorInteractor.Register(uiRegistrationDetails);
            }
        }
Example #2
0
        public void OnRegistrationSucceed()
        {
            registrationView?.EnableInteraction();

            HideRegistrationWindow();
            ShowLoginWindow();

            NoticeUtils.ShowNotice(message: NoticeMessages.AuthView.RegistrationSucceed);
        }
Example #3
0
        public async Task <IActionResult> Post(
            int id,
            [FromQuery(Name = "token")] string token)
        {
            ModelResult <UserFollowInfo> result = TokenUtils.CheckToken <UserFollowInfo>(token, _context);

            if (result != null)
            {
                return(BadRequest(result));
            }

            Session sessionResult = await _context.Sessions
                                    .FirstOrDefaultAsync(s => s.SessionToken == token);

            User follower = await _context.Users
                            .FirstOrDefaultAsync(u => u.UserId == sessionResult.SessionUserId);

            UserFollow userFollowResult = await _context.UserFollows
                                          .FirstOrDefaultAsync(uf => uf.FollowingId == id &&
                                                               uf.FollowerId == sessionResult.SessionUserId);

            if (userFollowResult != null)
            {
                result = new ModelResult <UserFollowInfo>(400, null, "User Followed");
                return(BadRequest(result));
            }

            User following = await _context.Users
                             .FirstOrDefaultAsync(u => u.UserId == id);

            if (following == null)
            {
                result = new ModelResult <UserFollowInfo>(404, null, "User Not Exists");
                return(BadRequest(result));
            }

            UserFollow userFollow = new UserFollow
            {
                Follower    = follower,
                FollowerId  = follower.UserId,
                Following   = following,
                FollowingId = following.UserId
            };

            _context.Add(userFollow);
            await _context.SaveChangesAsync();

            await NoticeUtils.CreateFollowNotice(userFollow, _context);

            result = new ModelResult <UserFollowInfo>(201, null, "Add Follow Success");
            return(Ok(result));
        }
Example #4
0
        public void OnCreateCharacterFailed(UICharacterCreationFailed reason)
        {
            switch (reason)
            {
            case UICharacterCreationFailed.Unknown:
            {
                NoticeUtils.ShowNotice(message: NoticeMessages.CharacterView.CreationFailed);
                break;
            }

            case UICharacterCreationFailed.NameAlreadyInUse:
            {
                NoticeUtils.ShowNotice(message: NoticeMessages.CharacterView.NameAlreadyInUse);
                break;
            }
            }
        }
Example #5
0
        private void OnLoginButtonClicked(
            UIAuthenticationDetails uiAuthenticationDetails)
        {
            var email    = uiAuthenticationDetails.Email;
            var password = uiAuthenticationDetails.Password;

            if (authenticationValidator.IsEmptyEmailAddress(email, out var message) ||
                authenticationValidator.IsInvalidEmailAddress(email, out message) ||
                authenticationValidator.IsEmptyPassword(password, out message) ||
                authenticationValidator.IsPasswordTooShort(password, out message))
            {
                NoticeUtils.ShowNotice(message);
            }
            else
            {
                loginView?.DisableInteraction();
                authenticatorInteractor.Login(uiAuthenticationDetails);
            }
        }
        public async Task <IActionResult> Post(
            [FromBody] Article article,
            [FromQuery(Name = "token")] string token)
        {
            ModelResult <ArticleInfo> result = TokenUtils.CheckToken <ArticleInfo>(token, _context);

            if (result != null)
            {
                return(BadRequest(result));
            }

            Session sessionResult = await _context.Sessions
                                    .FirstOrDefaultAsync(s => s.SessionToken == token);

            article.User = await _context.Users
                           .FirstOrDefaultAsync(u => u.UserId == sessionResult.SessionUserId);

            if (article.PublishDate == DateTime.MinValue)
            {
                article.PublishDate = DateTime.Now;
            }

            if (article.ArticleId != 0)
            {
                result = new ModelResult <ArticleInfo>(400, null, "Invalid Article");
                return(BadRequest(result));
            }

            if (article.Title == null ||
                article.Content == null)
            {
                result = new ModelResult <ArticleInfo>(400, null, "Article Need Title or Content");
                return(BadRequest(result));
            }

            _context.Articles.Add(article);
            await _context.SaveChangesAsync();

            await NoticeUtils.CreateArticleNotice(article, _context);

            result = new ModelResult <ArticleInfo>(201, new ArticleInfo(article, _context), "Article Created");
            return(Ok(result));
        }
Example #7
0
        public void OnRegistrationFailed(string reason)
        {
            registrationView?.EnableInteraction();

            NoticeUtils.ShowNotice(message: reason);
        }
Example #8
0
        public void OnLoginFailed(string reason)
        {
            loginView?.EnableInteraction();

            NoticeUtils.ShowNotice(message: reason);
        }
        public async Task <IActionResult> Post(
            string type,
            int id,
            [FromBody] Comment comment,
            [FromQuery(Name = "token")] string token)
        {
            // 先评论是否有正文
            // 再检查Token是否有效
            // 再检查评论类型
            // 再检查文章/评论是否存在
            int     replyCommentId = 0;
            Comment commentResult  = null;

            ModelResult <CommentInfo> result = TokenUtils.CheckToken <CommentInfo>(token, _context);

            if (result != null)
            {
                return(BadRequest(result));
            }

            if (comment.Content == null || comment.CommentId != 0)
            {
                result = new ModelResult <CommentInfo>(400, new CommentInfo(comment), "Invalid Comment");
                return(BadRequest(result));
            }

            comment.PublishDate = DateTime.Now;

            if (type == "article" || type == "reply")
            {
                Article articleResult;
                if (type == "article")
                {
                    if (comment.ArticleId == 0)
                    {
                        comment.ArticleId = id;
                    }
                    if (id == 0)
                    {
                        id = comment.ArticleId;
                    }

                    articleResult = await _context.Articles
                                    .FirstOrDefaultAsync(a => a.ArticleId == id);
                }
                else // if (type == "reply")
                {
                    commentResult = await _context.Comments
                                    .FirstOrDefaultAsync(c => c.CommentId == id);

                    if (commentResult == null)
                    {
                        result = new ModelResult <CommentInfo>(404, null, "Comment to Reply Not Exists");
                        return(BadRequest(result));
                    }

                    replyCommentId = commentResult.CommentId;
                    articleResult  = await _context.Articles
                                     .FirstOrDefaultAsync(a => a.ArticleId == commentResult.ArticleId);

                    comment.ArticleId = articleResult.ArticleId;
                }

                Session sessionResult = await _context.Sessions
                                        .FirstOrDefaultAsync(s => s.SessionToken == token);

                if (articleResult == null)
                {
                    result = new ModelResult <CommentInfo>(404, null, "Article Not Exists");
                    return(BadRequest(result));
                }

                comment.UserId = sessionResult.SessionUserId;
                comment.User   = await _context.Users
                                 .FirstOrDefaultAsync(u => u.UserId == comment.UserId);

                comment.ArticleId = id;
                comment.Article   = articleResult;

                await _context.AddAsync(comment);

                await _context.SaveChangesAsync();

                result = new ModelResult <CommentInfo>(201, new CommentInfo(comment), "Commented");
            }
            else
            {
                result = new ModelResult <CommentInfo>(405, null, "Undefined Comment Type");
                return(BadRequest(result));
            }

            if (type == "reply" && replyCommentId != 0)
            {
                await _context.AddAsync(new CommentReply
                {
                    CommentId        = comment.CommentId,
                    RepliedCommentId = replyCommentId
                });

                await _context.SaveChangesAsync();

                result.Message = "Replied";
            }

            int noticeUserId = 0;

            if (type == "article")
            {
                noticeUserId = comment.UserId;
            }
            else
            {
                if (commentResult != null)
                {
                    noticeUserId = commentResult.UserId;
                }
            }

            await NoticeUtils.CreateCommentNotice(comment, _context, noticeUserId, type);

            return(Ok(result));
        }
Example #10
0
 public void OnCharacterDeletionFailed()
 {
     NoticeUtils.ShowNotice(message: NoticeMessages.CharacterView.DeletionFailed);
 }
Example #11
0
 public void OnCharacterUnvalidated()
 {
     NoticeUtils.ShowNotice(message: NoticeMessages.CharacterView.ValidationFailed);
 }