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

            // 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.AppSecret))
                {
                    try
                    {
                        secret = _encrypter.Encrypt(model.AppSecret);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError(e, $"There was a problem encrypting the Facebook app secret. {e.Message}");
                        }
                    }
                }

                // Create the model
                settings = new PlatoFacebookSettings()
                {
                    AppId        = model.AppId,
                    AppSecret    = secret,
                    CallbackPath = model.CallbackPath
                };

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

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

            return(await BuildEditAsync(settings, context));
        }
Esempio n. 2
0
        public override async Task <IViewProviderResult> BuildUpdateAsync(FacebookSettings settings, IViewProviderContext context)
        {
            var model = new FacebookSettingsViewModel();

            // 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.AppSecret))
                {
                    try
                    {
                        var protector = _dataProtectionProvider.CreateProtector(nameof(FacebookOptionsConfiguration));
                        secret = protector.Protect(model.AppSecret);
                    }
                    catch (Exception e)
                    {
                        _logger.LogError($"There was a problem encrypting the Facebook app secret. {e.Message}");
                    }
                }

                // Create the model
                settings = new FacebookSettings()
                {
                    AppId     = model.AppId,
                    AppSecret = secret
                };

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

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

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