예제 #1
0
        public MediatorResponse <ProviderViewModel> Sites(string ukprn)
        {
            var providerProfile = _providerProvider.GetProviderViewModel(ukprn);

            return(GetMediatorResponse(ProviderMediatorCodes.Sites.Ok, providerProfile));
        }
        public MediatorResponse <ProviderViewModel> GetProvider(int providerId)
        {
            var viewModel = _providerProvider.GetProviderViewModel(providerId);

            return(GetMediatorResponse(AdminMediatorCodes.GetProvider.Ok, viewModel));
        }
예제 #3
0
        public MediatorResponse <AuthorizeResponseViewModel> Authorize(ClaimsPrincipal principal)
        {
            var viewModel = new AuthorizeResponseViewModel();

            if (string.IsNullOrEmpty(principal?.Identity?.Name))
            {
                return(GetMediatorResponse(ProviderUserMediatorCodes.Authorize.EmptyUsername, viewModel, AuthorizeMessages.EmptyUsername, UserMessageLevel.Error));
            }

            var username = principal.Identity.Name;

            viewModel.Username = username;

            var userProfile = _providerUserProvider.GetUserProfileViewModel(username);

            if (userProfile != null)
            {
                viewModel.EmailAddress         = userProfile.EmailAddress;
                viewModel.EmailAddressVerified = userProfile.EmailAddressVerified;
            }

            var ukprn = principal.GetUkprn();

            if (string.IsNullOrWhiteSpace(ukprn))
            {
                return(GetMediatorResponse(ProviderUserMediatorCodes.Authorize.MissingProviderIdentifier, viewModel, AuthorizeMessages.MissingProviderIdentifier, UserMessageLevel.Error));
            }

            if (!principal.IsInRole(Roles.Faa))
            {
                return(GetMediatorResponse(ProviderUserMediatorCodes.Authorize.MissingServicePermission, viewModel, AuthorizeMessages.MissingServicePermission, UserMessageLevel.Warning));
            }

            var provider = _providerProvider.GetProviderViewModel(ukprn);

            if (provider == null)
            {
                return(GetMediatorResponse(ProviderUserMediatorCodes.Authorize.NoProviderProfile, viewModel, AuthorizeMessages.NoProviderProfile, UserMessageLevel.Info));
            }

            viewModel.ProviderId = provider.ProviderId;

            if (provider.ProviderSiteViewModels.Count() < MinProviderSites)
            {
                return(GetMediatorResponse(ProviderUserMediatorCodes.Authorize.FailedMinimumSitesCountCheck, viewModel, AuthorizeMessages.FailedMinimumSitesCountCheck, UserMessageLevel.Warning));
            }

            if (userProfile == null)
            {
                var isFirstUser = !_providerUserProvider.GetProviderUsers(ukprn).Any();

                if (isFirstUser)
                {
                    return(GetMediatorResponse(ProviderUserMediatorCodes.Authorize.FirstUser, viewModel, AuthorizeMessages.FirstUser, UserMessageLevel.Info));
                }

                return(GetMediatorResponse(ProviderUserMediatorCodes.Authorize.NoUserProfile, viewModel, AuthorizeMessages.NoUserProfile, UserMessageLevel.Info));
            }

            if (!userProfile.EmailAddressVerified)
            {
                return(GetMediatorResponse(ProviderUserMediatorCodes.Authorize.EmailAddressNotVerified, viewModel,
                                           AuthorizeMessages.EmailAddressNotVerified, UserMessageLevel.Info));
            }

            if (!provider.IsMigrated)
            {
                return(GetMediatorResponse(ProviderUserMediatorCodes.Authorize.ProviderNotMigrated, viewModel));
            }

            return(GetMediatorResponse(ProviderUserMediatorCodes.Authorize.Ok, viewModel));
        }