Beispiel #1
0
        public override async Task <IViewProviderResult> BuildUpdateAsync(DemoSettings settings, IViewProviderContext context)
        {
            var model = new DemoSettingsViewModel();

            // Validate model
            if (!await context.Updater.TryUpdateModelAsync(model))
            {
                return(await BuildEditAsync(settings, context));
            }

            // Update settings
            if (context.Updater.ModelState.IsValid)
            {
                // Encrypt the password
                var adminPassword = string.Empty;
                if (!string.IsNullOrWhiteSpace(model.AdminPassword))
                {
                    try
                    {
                        var protector = _dataProtectionProvider.CreateProtector(nameof(DemoOptionsConfiguration));
                        adminPassword = protector.Protect(model.AdminPassword);
                    }
                    catch (Exception e)
                    {
                        _logger.LogError($"There was a problem encrypting the Twitter app secret. {e.Message}");
                    }
                }

                // Create the model
                settings = new DemoSettings()
                {
                    AdminUserName = model.AdminUserName,
                    AdminPassword = adminPassword
                };

                // Persist the settings
                var result = await _demoSettingsStore.SaveAsync(settings);

                if (result != null)
                {
                    // Recycle shell context to ensure changes take effect
                    _platoHost.RecycleShellContext(_shellSettings);
                }
            }

            return(await BuildEditAsync(settings, context));
        }
        public override async Task <IDisplayResult> UpdateAsync(DemoSettings settings, BuildEditorContext context)
        {
            // Since this DisplayDriver is for the ISite object this UpdateAsync will be called every time if a site
            // settings editor is being updated. To make sure that this is for our editor group check it here.
            if (context.GroupId == EditorGroupId)
            {
                // Authorize here too.
                if (!await IsAuthorizedToManageDemoSettingsAsync())
                {
                    return(null);
                }

                // Update the view model and the model as usual.
                var model = new DemoSettingsViewModel();

                await context.Updater.TryUpdateModelAsync(model, Prefix);

                settings.Message = model.Message;
            }

            return(await EditAsync(settings, context));
        }