Ejemplo n.º 1
0
        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()
                {
                    HostUrl         = model.HostUrl,
                    DemoUrl         = model.DemoUrl,
                    PlatoDesktopUrl = model.PlatoDesktopUrl
                };

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

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

            return(await BuildEditAsync(settings, context));
        }
Ejemplo n.º 2
0
        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 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           = model.SmtpSettings.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 _emailSettingsManager.SaveAsync(settings);

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

            return(await BuildEditAsync(settings, context));
        }
Ejemplo n.º 3
0
        public override async Task <IViewProviderResult> BuildUpdateAsync(FileSetting settings, IViewProviderContext context)
        {
            var model = new EditFileSettingsViewModel();

            // 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 FileSetting()
                {
                    RoleId            = role.Id,
                    MaxFileSize       = model.MaxFileSize,
                    AvailableSpace    = model.AvailableSpace,
                    AllowedExtensions = GetPostedExtensions()
                };

                var result = await _attachmentSettingsStore.SaveAsync(settings);

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

            return(await BuildEditAsync(settings, context));
        }
Ejemplo n.º 4
0
        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.RecycleShell(_shellSettings);
                }
            }

            return(await BuildEditAsync(settings, context));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> FinishSetUpPost(string returnUrl)
        {
            var descriptor = await _tourDescriptorStore.GetAsync();

            if (descriptor == null)
            {
                return(NotFound());
            }

            descriptor.Completed = true;

            var result = await _tourDescriptorStore.SaveAsync(descriptor);

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

                // Success
                _alerter.Success(T[$"Setup Finished Successfully!"]);
            }
            else
            {
                _alerter.Danger(T["A problem occurred ending the setup assistant!"]);
            }

            if (!string.IsNullOrEmpty(returnUrl))
            {
                // Redirect to returnUrl
                return(RedirectToLocal(returnUrl));
            }

            return(Redirect("~/"));
        }
Ejemplo n.º 6
0
        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.RecycleShell(_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)));
        }
Ejemplo n.º 7
0
        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 _siteSettingsManager.SaveAsync(settings);

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

            return(await BuildEditAsync(viewModel, context));
        }
Ejemplo n.º 8
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.RecycleShell(_shellSettings);
                }
            }

            return(await BuildEditAsync(settings, context));
        }
Ejemplo n.º 9
0
        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.RecycleShell(_shellSettings);
                }
            }

            return(await BuildEditAsync(settings, context));
        }
Ejemplo n.º 10
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
                    {
                        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.RecycleShell(_shellSettings);
                }
            }

            return(await BuildEditAsync(settings, context));
        }
Ejemplo n.º 11
0
 void RecycleShell()
 {
     _platoHost.RecycleShell(_shellSettings);
 }
Ejemplo n.º 12
0
        public override async Task <IViewProviderResult> BuildUpdateAsync(DefaultTenantSettings settings, IViewProviderContext context)
        {
            var model = new EditTenantSettingsViewModel();

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

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

                // Encrypt password
                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 DefaultTenantSettings()
                {
                    ConnectionString = connectionString,
                    TablePrefix      = model.TablePrefix,
                    SmtpSettings     = new SmtpSettings()
                    {
                        DefaultFrom        = model.SmtpSettings.DefaultFrom,
                        Host               = model.SmtpSettings.Host,
                        Port               = model.SmtpSettings.Port,
                        UserName           = model.SmtpSettings.UserName,
                        Password           = password,
                        RequireCredentials = model.SmtpSettings.RequireCredentials,
                        EnableSsl          = model.SmtpSettings.EnableSsl
                    }
                };

                var result = await _tenantSettingsStore.SaveAsync(settings);

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

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