Example #1
0
        public string GetToken(IClaim credentialClaim)
        {
            var token = new JwtSecurityToken
                            (issuer: "http://www.example.com"
                            , audience: "MyAudience"
                            , claims: credentialClaim.GetClaims()
                            , notBefore: DateTime.UtcNow
                            , expires: DateTime.UtcNow.AddHours(24)
                            , signingCredentials: CreateSigningCredentials());

            var    tokenHandler = new JwtSecurityTokenHandler();
            string tokenString  = tokenHandler.WriteToken(token);

            return(tokenString);
        }
Example #2
0
        public async Task <IActionResult> LikeArticle(Guid UserUniqueIdentity, Guid ArticleUniqueId, [FromBody] LikeActionRequest likeStatus)
        {
            var claim = _clame.GetClaims(User);

            if (UserUniqueIdentity.ToString() != claim)
            {
                return(Unauthorized("Invalid user Access"));
            }
            var articleLiked = await _repo.GetArticleAsync(ArticleUniqueId);

            var user = await _userRepo.GetUserAsync(UserUniqueIdentity);

            if (articleLiked == null)
            {
                return(NotFound("Article not Found"));
            }

            var like = new Like
            {
                LikerUniqueId   = user.UserUniqueIdentity,
                LikeStatus      = likeStatus.ArticleLiked,
                ArticleUniqueId = articleLiked.ArticleUniqueIdentifier,
                UserId          = user.Id,
                User            = user
            };


            var response = await _likeRepo.AddAsync(like);

            var actionupdate = likeStatus.ArticleLiked ? "Article liked":"Article unliked";


            if (response)
            {
                return(Ok(actionupdate));
            }

            var actionupdateBadRequest = likeStatus.ArticleLiked ? "You already liked this article" : "You already unliked this article";

            return(BadRequest(actionupdateBadRequest));
        }