예제 #1
0
        public async Task <TokenCreateResponse> CreateToken(TokenCreateRequest request)
        {
            var response = new TokenCreateResponse();

            var integrationClient = await _integrationClientRepository.Select(x => x.ClientId == request.ClientId && x.ClientSecret == request.ClientSecret);

            if (integrationClient.IsNotExist())
            {
                response.SetInvalidBecauseEntityNotFound();
                return(response);
            }

            if (await _organizationRepository.Any(x => x.Id == integrationClient.OrganizationId && !x.IsActive) ||
                await _integrationRepository.Any(x => x.Id == integrationClient.IntegrationId && !x.IsActive))
            {
                response.SetInvalidBecauseParentNotActive();
                return(response);
            }

            var token = _tokenFactory.CreateEntityFromRequest(request, integrationClient);
            var id    = await _tokenRepository.Insert(integrationClient.Id, token);

            if (id > 0)
            {
                response.Item   = _tokenFactory.CreateDtoFromEntity(token);
                response.Status = ResponseStatus.Success;
                return(response);
            }

            response.SetFailed();
            return(response);
        }
예제 #2
0
        public async Task <TokenCreateResponse> CreateToken(TokenGetRequest request)
        {
            var response = new TokenCreateResponse();

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

            if (currentUser == null)
            {
                response.SetInvalid();
                return(response);
            }

            var integrationClient = await _integrationClientRepository.Select(x => x.OrganizationId == currentUser.OrganizationId && x.IsActive);

            if (integrationClient.IsNotExist())
            {
                response.SetInvalid();
                response.ErrorMessages.Add("integration_not_found");
                return(response);
            }

            if (await _organizationRepository.Any(x => x.Id == integrationClient.OrganizationId && !x.IsActive) ||
                await _integrationRepository.Any(x => x.Id == integrationClient.IntegrationId && !x.IsActive))
            {
                response.SetInvalid();
                response.ErrorMessages.Add("integration_client_not_found");
                return(response);
            }

            var token = _tokenFactory.CreateEntity(integrationClient);
            var id    = await _tokenRepository.Insert(integrationClient.Id, token);

            if (id > 0)
            {
                response.Item   = _tokenFactory.CreateDtoFromEntity(token);
                response.Status = ResponseStatus.Success;
                return(response);
            }

            response.SetFailed();
            return(response);
        }