public async Task <Environment> GetAsync(string projectId, string environmentId)
        {
            var entity = await _cosmosToggleDataContext.EnvironmentRepository.GetByIdAsync(environmentId, projectId);

            if (entity == null)
            {
                await _notificationContext.AddAsync(HttpStatusCode.NotFound, $"Environment not found. ProjectId '{projectId}' EnvironmentId: '{environmentId}' ");

                return(null);
            }

            return(_mapper.Map <Environment>(entity));
        }
Пример #2
0
        private async Task CreatePasswordAsync(string email, string password, string activationCode, string activationKey)
        {
            var user = await _cosmosToggleDataContext.UserRepository.GetByEmailAsync(email);

            if (user != null)
            {
                user.Password = password;
                user.Status   = UserStatus.Activated;
                await _cosmosToggleDataContext.UserRepository.UpdateAsync(user, user.Id);
            }
            else
            {
                await _notificationContext.AddAsync(HttpStatusCode.Conflict, "User already exists");
            }
        }
Пример #3
0
        public async Task <Flag> GetAsync(string projectId, string environmentId, string flagId)
        {
            if (!await _authAppService.UserHasAuthProjectAsync(projectId))
            {
                return(null);
            }

            var entity = await _cosmosToggleDataContext.FlagRepository.GetAsync(projectId, environmentId, flagId);

            if (entity == null)
            {
                await _notificationContext.AddAsync(HttpStatusCode.NotFound, $"Flag not found - Id: '{flagId}' - EnviromentId: '{environmentId}' - ProjectId: {projectId}");

                return(null);
            }

            return(_mapper.Map <Flag>(entity));
        }
Пример #4
0
        public async Task <string> GetUserIdAsync()
        {
            if (_httpContextAccessor.HttpContext != null && _httpContextAccessor.HttpContext.User != null &&
                _httpContextAccessor.HttpContext.User.Identity != null)
            {
                var identity = _httpContextAccessor.HttpContext.User.Identity as ClaimsIdentity;

                if (identity != null && identity.Claims != null)
                {
                    var userId = identity.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value;

                    if (string.IsNullOrEmpty(userId))
                    {
                        await _notificationContext.AddAsync(HttpStatusCode.Unauthorized, "Unauthorized", "Claim 'UserId' not found.");
                    }

                    return(userId);
                }
            }

            return(string.Empty);
        }
Пример #5
0
        public async Task <bool> UserHasAuthProjectAsync(string projectId)
        {
            var user = await _securityContext.GetUserAsync();

            var friendlyMessage = $"User unauthorized in project '{projectId}'.";

            if (user == null)
            {
                await _notificationContext.AddAsync(HttpStatusCode.Unauthorized, $"User not found in claims", friendlyMessage);

                return(false);
            }

            if (user.Projects == null || !user.Projects.Contains(projectId))
            {
                await _notificationContext.AddAsync(HttpStatusCode.Unauthorized, $"User projects list not contains '{projectId}'", friendlyMessage);

                return(false);
            }

            return(true);
        }
Пример #6
0
        public async Task <IEnumerable <Project> > GetByUserIdAsync(string userId)
        {
            var user = await _securityContext.GetUserAsync();

            if (user != null && await _securityContext.MatchUserIdAsync(userId))
            {
                if (user.Projects != null && user.Projects.Count() > 0)
                {
                    var result = new List <Project> {
                    };

                    foreach (var projectId in user.Projects)
                    {
                        var entity = await _cosmosToggleDataContext.ProjectRepository.GetByIdAsync(projectId, projectId);

                        if (entity != null)
                        {
                            result.Add(_mapper.Map <Project>(entity));
                        }
                    }

                    if (result.Count == 0)
                    {
                        await _notificationContext.AddAsync(HttpStatusCode.NotFound, $"Projects not found");

                        return(null);
                    }

                    return(result);
                }
                else
                {
                    await _notificationContext.AddAsync(HttpStatusCode.NotFound, $"Projects not found");
                }
            }

            return(null);
        }