예제 #1
0
        public async Task <ActionResult> Logout()
        {
            try
            {
                string token = HttpContext.Request.Headers["authorization"].Single().Split(" ")[1];
                if (!(await _repository.ValidateToken(token)))
                {
                    return(Unauthorized());
                }

                InvalidToken  invalidToken = new InvalidToken();
                var           identity     = HttpContext.User.Identity as ClaimsIdentity;
                IList <Claim> claim        = identity.Claims.ToList();

                DateTime expirationDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
                expirationDate = expirationDate.AddSeconds(Double.Parse(claim[3].Value)).ToLocalTime();

                invalidToken.userId         = Int32.Parse(claim[0].Value);
                invalidToken.expirationDate = expirationDate;
                invalidToken.token          = token;

                await _repository.CreateInvalidToken(invalidToken);

                await _repository.SaveChanges();

                return(Ok());
            }
            catch (Exception)
            {
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }
        }
예제 #2
0
        public async Task <ActionResult <IEnumerable <UserTaskReadDTO> > > GettUserTasks()
        {
            try
            {
                string token = HttpContext.Request.Headers["authorization"].Single().Split(" ")[1];
                if (!await _repository.ValidateToken(token))
                {
                    return(Unauthorized());
                }

                int loggedUserId = Int32.Parse(User.FindFirst(ClaimTypes.NameIdentifier)?.Value);

                var taskItems = await _repository.GetUserTasks(loggedUserId);

                return(Ok(_mapper.Map <IEnumerable <UserTaskReadDTO> >(taskItems)));
            }
            catch (Exception)
            {
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }
        }