Esempio n. 1
0
        public override async Task <IViewProviderResult> BuildUpdateAsync(PlatoGoogleSettings settings, IViewProviderContext context)
        {
            var model = new GoogleSettingsViewModel();

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

            // Update settings
            if (context.Updater.ModelState.IsValid)
            {
                // Encrypt the secret
                var secret = string.Empty;
                if (!string.IsNullOrWhiteSpace(model.ClientSecret))
                {
                    try
                    {
                        secret = _encrypter.Encrypt(model.ClientSecret);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError(e, $"There was a problem encrypting the Google client secret. {e.Message}");
                        }
                    }
                }

                // Create the model
                settings = new PlatoGoogleSettings()
                {
                    ClientId     = model.ClientId,
                    ClientSecret = secret,
                    CallbackPath = model.CallbackPath,
                    TrackingId   = model.TrackingId
                };

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

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

            return(await BuildEditAsync(settings, context));
        }
Esempio n. 2
0
        public async Task <IActionResult> IndexPost(GoogleSettingsViewModel viewModel)
        {
            // Ensure we have permission
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditGitHubSettings))
            {
                return(Unauthorized());
            }

            // Execute view providers ProvideUpdateAsync method
            await _viewProvider.ProvideUpdateAsync(new PlatoGitHubSettings(), this);

            // Add alert
            _alerter.Success(T["Settings Updated Successfully!"]);

            return(RedirectToAction(nameof(Index)));
        }