public override async Task <IViewProviderResult> BuildUpdateAsync(PlatoSiteSettings settings, IViewProviderContext context) { var model = new PlatoSiteSettingsViewModel(); // Validate model if (!await context.Updater.TryUpdateModelAsync(model)) { return(await BuildEditAsync(settings, context)); } // Update settings if (context.Updater.ModelState.IsValid) { // Create the model settings = new PlatoSiteSettings() { DemoUrl = model.DemoUrl, PlatoDesktopUrl = model.PlatoDesktopUrl }; // 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 <IViewProviderResult> BuildUpdateAsync(EmailSettings settings, IViewProviderContext context) { var model = new EmailSettingsViewModel(); // Validate model if (!await context.Updater.TryUpdateModelAsync(model)) { return(await BuildEditAsync(settings, context)); } // Update settings if (context.Updater.ModelState.IsValid) { // Encrypt the password var username = model.SmtpSettings.UserName; var password = string.Empty; if (!string.IsNullOrWhiteSpace(model.SmtpSettings.Password)) { try { password = _encrypter.Encrypt(model.SmtpSettings.Password); } catch (Exception e) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError($"There was a problem encrypting the SMTP server password. {e.Message}"); } } } settings = new EmailSettings() { SmtpSettings = new SmtpSettings() { DefaultFrom = model.SmtpSettings.DefaultFrom, Host = model.SmtpSettings.Host, Port = model.SmtpSettings.Port, UserName = username, Password = password, RequireCredentials = model.SmtpSettings.RequireCredentials, EnableSsl = model.SmtpSettings.EnableSsl, PollingInterval = model.SmtpSettings.PollInterval, BatchSize = model.SmtpSettings.BatchSize, SendAttempts = model.SmtpSettings.SendAttempts, EnablePolling = model.SmtpSettings.EnablePolling } }; var result = await _emailSettingsStore.SaveAsync(settings); if (result != null) { // Recycle shell context to ensure changes take effect _platoHost.RecycleShellContext(_shellSettings); } } return(await BuildEditAsync(settings, context)); }
void RecycleShell() { var httpContext = _httpContextAccessor.HttpContext; var shellSettings = _runningShellTable.Match(httpContext); _platoHost.RecycleShellContext(shellSettings); }
public override async Task <IViewProviderResult> BuildUpdateAsync(SearchSettings settings, IViewProviderContext context) { var model = new SearchSettingsViewModel(); // Validate model if (!await context.Updater.TryUpdateModelAsync(model)) { return(await BuildEditAsync(settings, context)); } // Update settings if (context.Updater.ModelState.IsValid) { var result = await _searchSettingsStore.SaveAsync(new SearchSettings() { SearchType = model.SearchType }); if (result != null) { // Recycle shell context to ensure changes take effect _platoHost.RecycleShellContext(_shellSettings); } } return(await BuildEditAsync(settings, context)); }
public override async Task <IViewProviderResult> BuildUpdateAsync(AttachmentSetting settings, IViewProviderContext context) { var model = new EditAttachmentSettingsViewModel(); // Validate model if (!await context.Updater.TryUpdateModelAsync(model)) { return(await BuildEditAsync(settings, context)); } // Update settings if (context.Updater.ModelState.IsValid) { var role = await _platoRoleStore.GetByIdAsync(model.RoleId); settings = new AttachmentSetting() { RoleId = role.Id, AvailableSpace = model.AvailableSpace, AllowedExtensions = GetPostedExtensions() }; var result = await _attachmentSettingsStore.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<IViewProviderResult> BuildUpdateAsync(SettingsIndex viewModel, IViewProviderContext context) { var model = new SiteSettingsViewModel(); // Validate model if (!await context.Updater.TryUpdateModelAsync(model)) { return await BuildEditAsync(viewModel, context); } // Update settings if (context.Updater.ModelState.IsValid) { var homeRoutes = _homeRouteManager.GetDefaultRoutes(); var settings = await _siteSettingsStore.GetAsync(); if (settings != null) { settings.SiteName = model.SiteName; settings.TimeZone = model.TimeZone; settings.DateTimeFormat = model.DateTimeFormat; settings.Culture = model.Culture; settings.Theme = model.Theme; settings.HomeRoute = homeRoutes?.FirstOrDefault(r => r.Id.Equals(model.HomeRoute, StringComparison.InvariantCultureIgnoreCase)); } else { // Create new settings settings = new SiteSettings() { SiteName = model.SiteName, TimeZone = model.TimeZone, DateTimeFormat = model.DateTimeFormat, Culture = model.Culture, Theme = model.Theme, HomeRoute = homeRoutes?.FirstOrDefault(r => r.Id.Equals(model.HomeRoute, StringComparison.InvariantCultureIgnoreCase)) }; } // Update settings var result = await _siteSettingsStore.SaveAsync(settings); if (result != null) { // Recycle shell context to ensure changes take effect _platoHost.RecycleShellContext(_shellSettings); } } return await BuildEditAsync(viewModel, context); }
public async Task <IActionResult> Delete(string id) { // Ensure we have permission if (!await _authorizationService.AuthorizeAsync(User, Permissions.DeleteThemes)) { return(Unauthorized()); } // Get theme var theme = _siteThemeLoader .AvailableThemes.FirstOrDefault(t => t.Id.Equals(id, StringComparison.OrdinalIgnoreCase)); // Ensure we found the theme if (theme == null) { return(NotFound()); } // Is the theme we are deleting our current theme var currentTheme = await _contextFacade.GetCurrentThemeAsync(); if (currentTheme.Equals(theme.FullPath, StringComparison.OrdinalIgnoreCase)) { // Get settings var settings = await _siteSettingsStore.GetAsync(); // Clear theme, ensures we fallback to our default theme settings.Theme = ""; // Save settings var updatedSettings = await _siteSettingsStore.SaveAsync(settings); if (updatedSettings != null) { // Recycle shell context to ensure changes take effect _platoHost.RecycleShellContext(_shellSettings); } } // Delete the theme from the file system var result = _fileSystem.DeleteDirectory(theme.FullPath); if (result) { _alerter.Success(T["Theme Deleted Successfully"]); } else { _alerter.Danger(T[$"Could not delete the theme at \"{theme.FullPath}\""]); } return(RedirectToAction(nameof(Index))); }
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)); }
public override async Task <IViewProviderResult> BuildUpdateAsync(PlatoSlackSettings settings, IViewProviderContext context) { var model = new SlackSettingsViewModel(); // Validate model if (!await context.Updater.TryUpdateModelAsync(model)) { return(await BuildEditAsync(settings, context)); } // Update settings if (context.Updater.ModelState.IsValid) { // Encrypt the secret var webHookUrl = string.Empty; var accessTokenSecret = string.Empty; if (!string.IsNullOrWhiteSpace(model.WebHookUrl)) { try { webHookUrl = _encrypter.Encrypt(model.WebHookUrl); } catch (Exception e) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError(e, $"There was a problem encrypting the Slack Web Hook URL. {e.Message}"); } } } // Create the model settings = new PlatoSlackSettings() { WebHookUrl = webHookUrl }; // Persist the settings var result = await _TwitterSettingsStore.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 <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 { adminPassword = _encrypter.Encrypt(model.AdminPassword); } catch (Exception e) { if (_logger.IsEnabled(LogLevel.Error)) { _logger.LogError(e, $"There was a problem encrypting the demo administrator password. {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 <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)); }