예제 #1
0
        public async Task <IActionResult> Create(CreateOpenIdScopeViewModel model, string returnUrl = null)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageScopes))
            {
                return(Forbid());
            }

            if (await _scopeManager.FindByNameAsync(model.Name) != null)
            {
                ModelState.AddModelError(nameof(model.Name), S["The name is already taken by another scope."]);
            }

            if (!ModelState.IsValid)
            {
                ViewData["ReturnUrl"] = returnUrl;
                return(View(model));
            }

            var descriptor = new OpenIdScopeDescriptor
            {
                Description = model.Description,
                DisplayName = model.DisplayName,
                Name        = model.Name
            };

            if (!string.IsNullOrEmpty(model.Resources))
            {
                descriptor.Resources.UnionWith(model.Resources.Split(' ', StringSplitOptions.RemoveEmptyEntries));
            }

            descriptor.Resources.UnionWith(model.Tenants
                                           .Where(tenant => tenant.Selected)
                                           .Where(tenant => !string.Equals(tenant.Name, _shellSettings.Name))
                                           .Select(tenant => OpenIdConstants.Prefixes.Tenant + tenant.Name));

            await _scopeManager.CreateAsync(descriptor);

            if (string.IsNullOrEmpty(returnUrl))
            {
                return(RedirectToAction("Index"));
            }

            return(LocalRedirect(returnUrl));
        }
예제 #2
0
        public async Task <IActionResult> Create(string returnUrl = null)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageScopes))
            {
                return(Forbid());
            }

            var model = new CreateOpenIdScopeViewModel();

            foreach (var tenant in _shellHost.GetAllSettings().Where(s => s.State == TenantState.Running))
            {
                model.Tenants.Add(new CreateOpenIdScopeViewModel.TenantEntry
                {
                    Current = string.Equals(tenant.Name, _shellSettings.Name),
                    Name    = tenant.Name
                });
            }

            ViewData["ReturnUrl"] = returnUrl;
            return(View(model));
        }
예제 #3
0
        public async Task <IActionResult> Create(string returnUrl = null)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageScopes))
            {
                return(Unauthorized());
            }

            var model = new CreateOpenIdScopeViewModel();

            foreach (var tenant in _shellSettingsManager.LoadSettings())
            {
                model.Tenants.Add(new CreateOpenIdScopeViewModel.TenantEntry
                {
                    Current = string.Equals(tenant.Name, _shellSettings.Name, StringComparison.Ordinal),
                    Name    = tenant.Name
                });
            }

            ViewData["ReturnUrl"] = returnUrl;
            return(View(model));
        }