Exemplo n.º 1
0
        public async Task <IActionResult> ClientActiveTokensData(Guid id, int skip, int take)
        {
            var integrationUid = id;

            if (integrationUid.IsEmptyGuid())
            {
                return(Forbid());
            }

            var request = new IntegrationClientActiveTokenReadListRequest(CurrentUser.Id, integrationUid);

            SetPaging(skip, take, request);

            var response = await _integrationService.GetActiveTokensOfIntegrationClient(request);

            if (response.Status.IsNotSuccess)
            {
                return(NotFound());
            }

            var result = new DataResult();

            result.AddHeaders("access_token", "ip", "created_at", "expires_at", "");

            for (var i = 0; i < response.Items.Count; i++)
            {
                var item          = response.Items[i];
                var stringBuilder = new StringBuilder();
                stringBuilder.Append($"{item.Uid}{DataResult.SEPARATOR}");
                stringBuilder.Append($"{item.AccessToken}{DataResult.SEPARATOR}");
                stringBuilder.Append($"{item.IP}{DataResult.SEPARATOR}");
                stringBuilder.Append($"{GetDateTimeAsString(item.ExpiresAt)}{DataResult.SEPARATOR}");
                stringBuilder.Append($"{GetDateTimeAsString(item.CreatedAt)}{DataResult.SEPARATOR}");

                result.Data.Add(stringBuilder.ToString());
            }

            result.PagingInfo      = response.PagingInfo;
            result.PagingInfo.Type = PagingInfo.PAGE_NUMBERS;

            return(Json(result));
        }
Exemplo n.º 2
0
        public async Task <IntegrationClientActiveTokenReadListResponse> GetActiveTokensOfIntegrationClient(IntegrationClientActiveTokenReadListRequest request)
        {
            var response = new IntegrationClientActiveTokenReadListResponse();

            var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId);

            var now      = DateTime.UtcNow;
            var entities = await _tokenRepository.SelectMany(x => x.IntegrationClientUid == request.IntegrationClientUid &&
                                                             x.OrganizationId == currentUser.OrganizationId &&
                                                             x.ExpiresAt > now, request.PagingInfo.Skip, request.PagingInfo.Take, x => x.Id, request.PagingInfo.IsAscending);

            if (entities != null)
            {
                for (var i = 0; i < entities.Count; i++)
                {
                    var entity = entities[i];
                    var dto    = _tokenFactory.CreateDtoFromEntity(entity);
                    response.Items.Add(dto);
                }
            }

            response.Status = ResponseStatus.Success;
            return(response);
        }