예제 #1
0
        public void Configure(DefaultTenantSettings options)
        {
            var settings = _emailSettingsStore
                           .GetAsync()
                           .GetAwaiter()
                           .GetResult();

            // We have no settings to configure

            if (settings != null)
            {
                // Decrypt the connection string
                if (!string.IsNullOrWhiteSpace(settings.ConnectionString))
                {
                    try
                    {
                        options.ConnectionString = _encrypter.Decrypt(settings.ConnectionString);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError(e, $"There was a problem decrypting the default tenant connection string. {e.Message}");
                        }
                    }
                }

                options.TablePrefix = settings.TablePrefix;

                var smtpSettings = settings.SmtpSettings;
                if (smtpSettings != null)
                {
                    options.SmtpSettings.DefaultFrom             = smtpSettings.DefaultFrom;
                    options.SmtpSettings.DeliveryMethod          = smtpSettings.DeliveryMethod;
                    options.SmtpSettings.PickupDirectoryLocation = smtpSettings.PickupDirectoryLocation;
                    options.SmtpSettings.Host                  = smtpSettings.Host;
                    options.SmtpSettings.Port                  = smtpSettings.Port;
                    options.SmtpSettings.EnableSsl             = smtpSettings.EnableSsl;
                    options.SmtpSettings.RequireCredentials    = smtpSettings.RequireCredentials;
                    options.SmtpSettings.UseDefaultCredentials = smtpSettings.UseDefaultCredentials;
                    options.SmtpSettings.UserName              = smtpSettings.UserName;

                    // Decrypt the password
                    if (!String.IsNullOrWhiteSpace(smtpSettings.Password))
                    {
                        try
                        {
                            options.SmtpSettings.Password = _encrypter.Decrypt(smtpSettings.Password);
                        }
                        catch (Exception e)
                        {
                            if (_logger.IsEnabled(LogLevel.Error))
                            {
                                _logger.LogError(e, $"There was a problem decrypting the SMTP password. {e.Message}");
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        // -----------------

        private async Task <EditTenantSettingsViewModel> GetModel()
        {
            var settings = await _tenantSettingsStore.GetAsync();

            if (settings != null)
            {
                // Decrypt connection string
                var connectionString = string.Empty;
                if (!String.IsNullOrWhiteSpace(settings.ConnectionString))
                {
                    try
                    {
                        connectionString = _encrypter.Decrypt(settings.ConnectionString);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError(e, $"There was a problem decrypting the default tenant connection string. {e.Message}");
                        }
                    }
                }

                // Decrypt password
                var password = string.Empty;
                if (!String.IsNullOrWhiteSpace(settings.SmtpSettings.Password))
                {
                    try
                    {
                        password = _encrypter.Decrypt(settings.SmtpSettings.Password);
                    }
                    catch (Exception e)
                    {
                        if (_logger.IsEnabled(LogLevel.Error))
                        {
                            _logger.LogError(e, $"There was a problem decrypting the default tenant connection string. {e.Message}");
                        }
                    }
                }

                return(new EditTenantSettingsViewModel()
                {
                    ConnectionString = connectionString,
                    TablePrefix = settings.TablePrefix,
                    SmtpSettings = new SmtpSettingsViewModel()
                    {
                        DefaultFrom = _platoOptions.DemoMode
                            ? "*****@*****.**"
                            : settings.SmtpSettings.DefaultFrom,
                        Host = _platoOptions.DemoMode
                            ? "smtp.example.com"
                            : settings.SmtpSettings.Host,
                        Port = settings.SmtpSettings.Port,
                        UserName = _platoOptions.DemoMode
                            ? "*****@*****.**"
                            : settings.SmtpSettings.UserName,
                        Password = _platoOptions.DemoMode
                            ? ""
                            : password,
                        RequireCredentials = settings.SmtpSettings.RequireCredentials,
                        EnableSsl = settings.SmtpSettings.EnableSsl
                    }
                });
            }

            return(new EditTenantSettingsViewModel());
        }