668 lines
29 KiB
Plaintext
668 lines
29 KiB
Plaintext
@namespace Oqtane.Modules.Admin.Site
|
|
@inherits ModuleBase
|
|
@using System.Text.RegularExpressions
|
|
@inject NavigationManager NavigationManager
|
|
@inject ISiteService SiteService
|
|
@inject ITenantService TenantService
|
|
@inject IDatabaseService DatabaseService
|
|
@inject IAliasService AliasService
|
|
@inject IThemeService ThemeService
|
|
@inject ISettingService SettingService
|
|
@inject IStringLocalizer<Index> Localizer
|
|
@inject INotificationService NotificationService
|
|
@inject IStringLocalizer<SharedResources> SharedLocalizer
|
|
|
|
@if (_initialized)
|
|
{
|
|
<form @ref="form" class="@(validated ? "was-validated" : "needs-validation")" novalidate>
|
|
<div class="container">
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="name" HelpText="Enter the site name" ResourceKey="Name">Name: </Label>
|
|
<div class="col-sm-9">
|
|
<input id="name" class="form-control" @bind="@_name" maxlength="200" required />
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="logo" HelpText="Specify a logo for the site" ResourceKey="Logo">Logo: </Label>
|
|
<div class="col-sm-9">
|
|
<FileManager FileId="@_logofileid" Filter="@Constants.ImageFiles" @ref="_logofilemanager" />
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="favicon" HelpText="Specify a Favicon" ResourceKey="FavoriteIcon">Favicon: </Label>
|
|
<div class="col-sm-9">
|
|
<FileManager FileId="@_faviconfileid" Filter="ico" @ref="_faviconfilemanager" />
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="defaultTheme" HelpText="Select the sites default theme" ResourceKey="DefaultTheme">Default Theme: </Label>
|
|
<div class="col-sm-9">
|
|
<select id="defaultTheme" class="form-select" value="@_themetype" @onchange="(e => ThemeChanged(e))" required>
|
|
<option value="-"><@Localizer["Theme.Select"]></option>
|
|
@foreach (var theme in _themes)
|
|
{
|
|
<option value="@theme.TypeName">@theme.Name</option>
|
|
}
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="defaultContainer" HelpText="Select the default container for the site" ResourceKey="DefaultContainer">Default Container: </Label>
|
|
<div class="col-sm-9">
|
|
<select id="defaultContainer" class="form-select" @bind="@_containertype" required>
|
|
<option value="-"><@Localizer["Container.Select"]></option>
|
|
@foreach (var container in _containers)
|
|
{
|
|
<option value="@container.TypeName">@container.Name</option>
|
|
}
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="defaultAdminContainer" HelpText="Select the default admin container for the site" ResourceKey="DefaultAdminContainer">Default Admin Container: </Label>
|
|
<div class="col-sm-9">
|
|
<select id="defaultAdminContainer" class="form-select" @bind="@_admincontainertype" required>
|
|
<option value="-"><@Localizer["Container.Select"]></option>
|
|
<option value="@Constants.DefaultAdminContainer"><@Localizer["DefaultAdminContainer"]></option>
|
|
@foreach (var container in _containers)
|
|
{
|
|
<option value="@container.TypeName">@container.Name</option>
|
|
}
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="isDeleted" HelpText="Is this site deleted?" ResourceKey="IsDeleted">Deleted? </Label>
|
|
<div class="col-sm-9">
|
|
<select id="isDeleted" class="form-select" @bind="@_isdeleted" required>
|
|
<option value="True">@SharedLocalizer["Yes"]</option>
|
|
<option value="False">@SharedLocalizer["No"]</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<Section Name="SMTP" Heading="SMTP Settings" ResourceKey="SMTPSettings">
|
|
<div class="container">
|
|
<div class="row mb-1 align-items-center">
|
|
<div class="col-sm-3">
|
|
</div>
|
|
<div class="col-sm-9">
|
|
<strong>@Localizer["Smtp.Required.EnableNotificationJob"]</strong><br />
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="host" HelpText="Enter the host name of the SMTP server" ResourceKey="Host">Host: </Label>
|
|
<div class="col-sm-9">
|
|
<input id="host" class="form-control" @bind="@_smtphost" />
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="port" HelpText="Enter the port number for the SMTP server. Please note this field is required if you provide a host name." ResourceKey="Port">Port: </Label>
|
|
<div class="col-sm-9">
|
|
<input id="port" class="form-control" @bind="@_smtpport" />
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="enabledSSl" HelpText="Specify if SSL is required for your SMTP server" ResourceKey="UseSsl">SSL Enabled: </Label>
|
|
<div class="col-sm-9">
|
|
<select id="enabledSSl" class="form-select" @bind="@_smtpssl" >
|
|
<option value="True">@SharedLocalizer["Yes"]</option>
|
|
<option value="False">@SharedLocalizer["No"]</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="username" HelpText="Enter the username for your SMTP account" ResourceKey="SmptUsername">Username: </Label>
|
|
<div class="col-sm-9">
|
|
<input id="username" class="form-control" @bind="@_smtpusername" />
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="password" HelpText="Enter the password for your SMTP account" ResourceKey="SmtpPassword">Password: </Label>
|
|
<div class="col-sm-9">
|
|
<div class="input-group">
|
|
<input id="password" type="@_smtppasswordtype" class="form-control" @bind="@_smtppassword" />
|
|
<button type="button" class="btn btn-secondary" @onclick="@ToggleSMTPPassword">@_togglesmtppassword</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="sender" HelpText="Enter the email which emails will be sent from. Please note that this email address may need to be authorized with the SMTP server." ResourceKey="SmptSender">Email Sender: </Label>
|
|
<div class="col-sm-9">
|
|
<input id="sender" class="form-control" @bind="@_smtpsender" />
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="retention" HelpText="Number of days of notifications to retain" ResourceKey="Retention">Retention (Days): </Label>
|
|
<div class="col-sm-9">
|
|
<input id="retention" class="form-control" @bind="@_retention" />
|
|
</div>
|
|
</div>
|
|
<button type="button" class="btn btn-secondary" @onclick="SendEmail">@Localizer["Smtp.TestConfig"]</button>
|
|
<br /><br />
|
|
</div>
|
|
</Section>
|
|
<Section Name="PWA" Heading="Progressive Web Application Settings" ResourceKey="PWASettings">
|
|
<div class="container">
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="isEnabled" HelpText="Select whether you would like this site to be available as a Progressive Web Application (PWA)" ResourceKey="EnablePWA">Is Enabled? </Label>
|
|
<div class="col-sm-9">
|
|
<select id="isEnabled" class="form-select" @bind="@_pwaisenabled" required>
|
|
<option value="True">@SharedLocalizer["Yes"]</option>
|
|
<option value="False">@SharedLocalizer["No"]</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="appIcon" HelpText="Include an application icon for your PWA. It should be a PNG which is 192 X 192 pixels in dimension." ResourceKey="PwaApplicationIcon">App Icon: </Label>
|
|
<div class="col-sm-9">
|
|
<FileManager FileId="@_pwaappiconfileid" Filter="png" @ref="_pwaappiconfilemanager" />
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="splashIcon" HelpText="Include a splash icon for your PWA. It should be a PNG which is 512 X 512 pixels in dimension." ResourceKey="PwaSplashIcon">Splash Icon: </Label>
|
|
<div class="col-sm-9">
|
|
<FileManager FileId="@_pwasplashiconfileid" Filter="png" @ref="_pwasplashiconfilemanager" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Section>
|
|
@if (_aliases != null && UserSecurity.IsAuthorized(PageState.User, RoleNames.Host))
|
|
{
|
|
<Section Name="Aliases" Heading="Aliases" ResourceKey="Aliases">
|
|
<div class="container">
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="alias" HelpText="The aliases for the site. An alias can be a domain name (www.site.com) or a virtual folder (ie. www.site.com/folder). If a site has multiple aliases they should be separated by commas." ResourceKey="Aliases">Aliases: </Label>
|
|
<div class="col-sm-9">
|
|
<textarea id="alias" class="form-control" @bind="@_urls" rows="3" required></textarea>
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="defaultalias" HelpText="The default alias for the site. Requests for non-default aliases will be redirected to the default alias." ResourceKey="DefaultAlias">Default Alias: </Label>
|
|
<div class="col-sm-9">
|
|
<select id="defaultalias" class="form-select" @bind="@_defaultalias" required>
|
|
@foreach (string name in _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(sValue => sValue.Trim()).ToArray())
|
|
{
|
|
<option value="@name">@name</option>
|
|
}
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Section>
|
|
<Section Name="Hosting" Heading="Hosting Model" ResourceKey="Hosting">
|
|
<div class="container">
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="runtime" HelpText="The Blazor runtime hosting model" ResourceKey="Runtime">Runtime: </Label>
|
|
<div class="col-sm-9">
|
|
<select id="runtime" class="form-select" @bind="@_runtime" required>
|
|
<option value="Server">@SharedLocalizer["BlazorServer"]</option>
|
|
<option value="WebAssembly">@SharedLocalizer["BlazorWebAssembly"]</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="prerender" HelpText="Specifies if the site should be prerendered (for search crawlers, etc...)" ResourceKey="Prerender">Prerender? </Label>
|
|
<div class="col-sm-9">
|
|
<select id="prerender" class="form-select" @bind="@_prerender" required>
|
|
<option value="Prerendered">@SharedLocalizer["Yes"]</option>
|
|
<option value="">@SharedLocalizer["No"]</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Section>
|
|
<Section Name="TenantInformation" Heading="Tenant Information" ResourceKey="TenantInformation">
|
|
<div class="container">
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="tenant" HelpText="The tenant for the site" ResourceKey="Tenant">Tenant: </Label>
|
|
<div class="col-sm-9">
|
|
<input id="tenant" class="form-control" @bind="@_tenant" readonly />
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="database" HelpText="The database for the tenant" ResourceKey="Database">Database: </Label>
|
|
<div class="col-sm-9">
|
|
<input id="database" class="form-control" @bind="@_database" readonly />
|
|
</div>
|
|
</div>
|
|
<div class="row mb-1 align-items-center">
|
|
<Label Class="col-sm-3" For="connectionstring" HelpText="The connection information for the database" ResourceKey="ConnectionString">Connection: </Label>
|
|
<div class="col-sm-9">
|
|
<textarea id="connectionstring" class="form-control" @bind="@_connectionstring" rows="2" readonly></textarea>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Section>
|
|
}
|
|
<br />
|
|
<button type="button" class="btn btn-success" @onclick="SaveSite">@SharedLocalizer["Save"]</button>
|
|
<ActionDialog Header="Delete Site" Message="@Localizer["Confirm.DeleteSite"]" Action="Delete" Security="SecurityAccessLevel.Host" Class="btn btn-danger" OnClick="@(async () => await DeleteSite())" ResourceKey="DeleteSite" />
|
|
<br />
|
|
<br />
|
|
<AuditInfo CreatedBy="@_createdby" CreatedOn="@_createdon" ModifiedBy="@_modifiedby" ModifiedOn="@_modifiedon" DeletedBy="@_deletedby" DeletedOn="@_deletedon"></AuditInfo>
|
|
</form>
|
|
}
|
|
|
|
@code {
|
|
private ElementReference form;
|
|
private bool validated = false;
|
|
private bool _initialized = false;
|
|
private List<Theme> _themeList;
|
|
private List<ThemeControl> _themes = new List<ThemeControl>();
|
|
private List<ThemeControl> _containers = new List<ThemeControl>();
|
|
private string _name = string.Empty;
|
|
private List<Alias> _aliases;
|
|
private string _defaultalias = string.Empty;
|
|
private string _urls = string.Empty;
|
|
private string _runtime = "";
|
|
private string _prerender = "";
|
|
private int _logofileid = -1;
|
|
private FileManager _logofilemanager;
|
|
private int _faviconfileid = -1;
|
|
private FileManager _faviconfilemanager;
|
|
private string _themetype = "-";
|
|
private string _containertype = "-";
|
|
private string _admincontainertype = "-";
|
|
private string _smtphost = string.Empty;
|
|
private string _smtpport = string.Empty;
|
|
private string _smtpssl = "False";
|
|
private string _smtpusername = string.Empty;
|
|
private string _smtppassword = string.Empty;
|
|
private string _smtppasswordtype = "password";
|
|
private string _togglesmtppassword = string.Empty;
|
|
private string _smtpsender = string.Empty;
|
|
private string _retention = string.Empty;
|
|
private string _pwaisenabled;
|
|
private int _pwaappiconfileid = -1;
|
|
private FileManager _pwaappiconfilemanager;
|
|
private int _pwasplashiconfileid = -1;
|
|
private FileManager _pwasplashiconfilemanager;
|
|
private string _tenant = string.Empty;
|
|
private string _database = string.Empty;
|
|
private string _connectionstring = string.Empty;
|
|
private string _createdby;
|
|
private DateTime _createdon;
|
|
private string _modifiedby;
|
|
private DateTime _modifiedon;
|
|
private string _deletedby;
|
|
private DateTime? _deletedon;
|
|
private string _isdeleted;
|
|
|
|
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
_themeList = await ThemeService.GetThemesAsync();
|
|
Site site = await SiteService.GetSiteAsync(PageState.Site.SiteId);
|
|
if (site != null)
|
|
{
|
|
_name = site.Name;
|
|
_runtime = site.Runtime;
|
|
_prerender = site.RenderMode.Replace(_runtime, "");
|
|
_isdeleted = site.IsDeleted.ToString();
|
|
|
|
if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host))
|
|
{
|
|
await GetAliases();
|
|
}
|
|
|
|
if (site.LogoFileId != null)
|
|
{
|
|
_logofileid = site.LogoFileId.Value;
|
|
}
|
|
|
|
if (site.FaviconFileId != null)
|
|
{
|
|
_faviconfileid = site.FaviconFileId.Value;
|
|
}
|
|
|
|
_themes = ThemeService.GetThemeControls(_themeList);
|
|
_themetype = (!string.IsNullOrEmpty(site.DefaultThemeType)) ? site.DefaultThemeType : Constants.DefaultTheme;
|
|
_containers = ThemeService.GetContainerControls(_themeList, _themetype);
|
|
_containertype = (!string.IsNullOrEmpty(site.DefaultContainerType)) ? site.DefaultContainerType : Constants.DefaultContainer;
|
|
_admincontainertype = (!string.IsNullOrEmpty(site.AdminContainerType)) ? site.AdminContainerType : Constants.DefaultAdminContainer;
|
|
|
|
_pwaisenabled = site.PwaIsEnabled.ToString();
|
|
if (site.PwaAppIconFileId != null)
|
|
{
|
|
_pwaappiconfileid = site.PwaAppIconFileId.Value;
|
|
}
|
|
if (site.PwaSplashIconFileId != null)
|
|
{
|
|
_pwasplashiconfileid = site.PwaSplashIconFileId.Value;
|
|
}
|
|
|
|
var settings = await SettingService.GetSiteSettingsAsync(site.SiteId);
|
|
_smtphost = SettingService.GetSetting(settings, "SMTPHost", string.Empty);
|
|
_smtpport = SettingService.GetSetting(settings, "SMTPPort", string.Empty);
|
|
_smtpssl = SettingService.GetSetting(settings, "SMTPSSL", "False");
|
|
_smtpusername = SettingService.GetSetting(settings, "SMTPUsername", string.Empty);
|
|
_smtppassword = SettingService.GetSetting(settings, "SMTPPassword", string.Empty);
|
|
_togglesmtppassword = SharedLocalizer["ShowPassword"];
|
|
_smtpsender = SettingService.GetSetting(settings, "SMTPSender", string.Empty);
|
|
_retention = SettingService.GetSetting(settings, "NotificationRetention", "30");
|
|
|
|
if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host))
|
|
{
|
|
var tenants = await TenantService.GetTenantsAsync();
|
|
var _databases = await DatabaseService.GetDatabasesAsync();
|
|
var tenant = tenants.Find(item => item.TenantId == site.TenantId);
|
|
if (tenant != null)
|
|
{
|
|
_tenant = tenant.Name;
|
|
_database = _databases.Find(item => item.DBType == tenant.DBType)?.Name;
|
|
_connectionstring = tenant.DBConnectionString;
|
|
}
|
|
}
|
|
|
|
_createdby = site.CreatedBy;
|
|
_createdon = site.CreatedOn;
|
|
_modifiedby = site.ModifiedBy;
|
|
_modifiedon = site.ModifiedOn;
|
|
_deletedby = site.DeletedBy;
|
|
_deletedon = site.DeletedOn;
|
|
|
|
_initialized = true;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.LogError(ex, "Error Loading Site {SiteId} {Error}", PageState.Site.SiteId, ex.Message);
|
|
AddModuleMessage(ex.Message, MessageType.Error);
|
|
}
|
|
}
|
|
|
|
private async void ThemeChanged(ChangeEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
_themetype = (string)e.Value;
|
|
if (_themetype != "-")
|
|
{
|
|
_containers = ThemeService.GetContainerControls(_themeList, _themetype);
|
|
}
|
|
else
|
|
{
|
|
_containers = new List<ThemeControl>();
|
|
}
|
|
_containertype = "-";
|
|
_admincontainertype = Constants.DefaultAdminContainer;
|
|
StateHasChanged();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.LogError(ex, "Error Loading Pane Layouts For Theme {ThemeType} {Error}", _themetype, ex.Message);
|
|
AddModuleMessage(Localizer["Error.Theme.LoadPane"], MessageType.Error);
|
|
}
|
|
}
|
|
|
|
private async Task SaveSite()
|
|
{
|
|
validated = true;
|
|
var interop = new Interop(JSRuntime);
|
|
if (await interop.FormValid(form))
|
|
{
|
|
try
|
|
{
|
|
if (_name != string.Empty && _themetype != "-" && _containertype != "-")
|
|
{
|
|
var unique = true;
|
|
if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host))
|
|
{
|
|
_urls = Regex.Replace(_urls, @"\r\n?|\n", ","); // convert line breaks to commas
|
|
var aliases = await AliasService.GetAliasesAsync();
|
|
foreach (string name in _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(sValue => sValue.Trim()).ToArray())
|
|
{
|
|
var alias = aliases.Where(item => item.Name == name).FirstOrDefault();
|
|
if (alias != null && unique)
|
|
{
|
|
unique = (alias.TenantId == PageState.Site.TenantId && alias.SiteId == PageState.Site.SiteId);
|
|
}
|
|
}
|
|
if (unique && string.IsNullOrEmpty(_defaultalias)) unique = false;
|
|
}
|
|
|
|
if (unique)
|
|
{
|
|
var site = await SiteService.GetSiteAsync(PageState.Site.SiteId);
|
|
if (site != null)
|
|
{
|
|
bool refresh = false;
|
|
bool reload = false;
|
|
|
|
site.Name = _name;
|
|
if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host))
|
|
{
|
|
if (site.Runtime != _runtime || site.RenderMode != _runtime + _prerender)
|
|
{
|
|
site.Runtime = _runtime;
|
|
site.RenderMode = _runtime + _prerender;
|
|
reload = true; // needs to be reloaded on server
|
|
}
|
|
}
|
|
site.IsDeleted = (_isdeleted == null ? true : Boolean.Parse(_isdeleted));
|
|
|
|
site.LogoFileId = null;
|
|
var logofileid = _logofilemanager.GetFileId();
|
|
if (logofileid != -1)
|
|
{
|
|
site.LogoFileId = logofileid;
|
|
}
|
|
int? faviconFieldId = _faviconfilemanager.GetFileId();
|
|
if (faviconFieldId == -1) faviconFieldId = null;
|
|
if (site.FaviconFileId != faviconFieldId)
|
|
{
|
|
site.FaviconFileId = faviconFieldId;
|
|
reload = true; // needs to be reloaded on server
|
|
}
|
|
if (site.DefaultThemeType != _themetype)
|
|
{
|
|
site.DefaultThemeType = _themetype;
|
|
refresh = true; // needs to be refreshed on client
|
|
}
|
|
if (site.DefaultContainerType != _containertype)
|
|
{
|
|
site.DefaultContainerType = _containertype;
|
|
refresh = true; // needs to be refreshed on client
|
|
}
|
|
site.AdminContainerType = _admincontainertype;
|
|
|
|
if (site.PwaIsEnabled.ToString() != _pwaisenabled)
|
|
{
|
|
site.PwaIsEnabled = Boolean.Parse(_pwaisenabled);
|
|
reload = true; // needs to be reloaded on server
|
|
}
|
|
int? pwaappiconfileid = _pwaappiconfilemanager.GetFileId();
|
|
if (pwaappiconfileid == -1) pwaappiconfileid = null;
|
|
if (site.PwaAppIconFileId != pwaappiconfileid)
|
|
{
|
|
site.PwaAppIconFileId = pwaappiconfileid;
|
|
reload = true; // needs to be reloaded on server
|
|
}
|
|
int? pwasplashiconfileid = _pwasplashiconfilemanager.GetFileId();
|
|
if (pwasplashiconfileid == -1) pwasplashiconfileid = null;
|
|
if (site.PwaSplashIconFileId != pwasplashiconfileid)
|
|
{
|
|
site.PwaSplashIconFileId = pwasplashiconfileid;
|
|
reload = true; // needs to be reloaded on server
|
|
}
|
|
|
|
site = await SiteService.UpdateSiteAsync(site);
|
|
|
|
var settings = await SettingService.GetSiteSettingsAsync(site.SiteId);
|
|
settings = SettingService.SetSetting(settings, "SMTPHost", _smtphost, true);
|
|
settings = SettingService.SetSetting(settings, "SMTPPort", _smtpport, true);
|
|
settings = SettingService.SetSetting(settings, "SMTPSSL", _smtpssl, true);
|
|
settings = SettingService.SetSetting(settings, "SMTPUsername", _smtpusername, true);
|
|
settings = SettingService.SetSetting(settings, "SMTPPassword", _smtppassword, true);
|
|
settings = SettingService.SetSetting(settings, "SMTPSender", _smtpsender, true);
|
|
settings = SettingService.SetSetting(settings, "NotificationRetention", _retention, true);
|
|
await SettingService.UpdateSiteSettingsAsync(settings, site.SiteId);
|
|
|
|
if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host))
|
|
{
|
|
var names = _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
|
|
.Select(sValue => sValue.Trim()).ToArray();
|
|
foreach (Alias alias in _aliases)
|
|
{
|
|
if (!names.Contains(alias.Name.Trim()))
|
|
{
|
|
await AliasService.DeleteAliasAsync(alias.AliasId);
|
|
}
|
|
}
|
|
|
|
foreach (string name in names)
|
|
{
|
|
var alias = _aliases.Find(item => item.Name.Trim() == name);
|
|
if (alias == null)
|
|
{
|
|
alias = new Alias();
|
|
alias.Name = name;
|
|
alias.TenantId = site.TenantId;
|
|
alias.SiteId = site.SiteId;
|
|
alias.IsDefault = (name == _defaultalias);
|
|
await AliasService.AddAliasAsync(alias);
|
|
}
|
|
else
|
|
{
|
|
if (alias.Name != name || alias.IsDefault != (alias.Name.Trim() == _defaultalias))
|
|
{
|
|
alias.Name = name;
|
|
alias.IsDefault = (name == _defaultalias);
|
|
await AliasService.UpdateAliasAsync(alias);
|
|
}
|
|
}
|
|
}
|
|
await GetAliases();
|
|
}
|
|
|
|
await logger.LogInformation("Site Settings Saved {Site}", site);
|
|
|
|
if (refresh || reload)
|
|
{
|
|
NavigationManager.NavigateTo(NavigateUrl(true), reload); // refresh/reload
|
|
}
|
|
else
|
|
{
|
|
AddModuleMessage(Localizer["Success.Settings.SaveSite"], MessageType.Success);
|
|
await interop.ScrollTo(0, 0, "smooth");
|
|
}
|
|
}
|
|
}
|
|
else // deuplicate alias or default alias not specified
|
|
{
|
|
AddModuleMessage(Localizer["Message.Aliases.Taken"], MessageType.Warning);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AddModuleMessage(Localizer["Message.Required.SiteName"], MessageType.Warning);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.LogError(ex, "Error Saving Site {SiteId} {Error}", PageState.Site.SiteId, ex.Message);
|
|
AddModuleMessage(Localizer["Error.SaveSite"], MessageType.Error);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AddModuleMessage(SharedLocalizer["Message.InfoRequired"], MessageType.Warning);
|
|
}
|
|
}
|
|
|
|
private async Task DeleteSite()
|
|
{
|
|
try
|
|
{
|
|
var sites = await SiteService.GetSitesAsync();
|
|
if (sites.Count > 1)
|
|
{
|
|
await SiteService.DeleteSiteAsync(PageState.Site.SiteId);
|
|
await logger.LogInformation("Site Deleted {SiteId}", PageState.Site.SiteId);
|
|
|
|
var aliases = await AliasService.GetAliasesAsync();
|
|
foreach (Alias a in aliases.Where(item => item.SiteId == PageState.Site.SiteId && item.TenantId == PageState.Site.TenantId))
|
|
{
|
|
await AliasService.DeleteAliasAsync(a.AliasId);
|
|
}
|
|
|
|
NavigationManager.NavigateTo(NavigateUrl("admin/sites"));
|
|
}
|
|
else
|
|
{
|
|
AddModuleMessage(Localizer["Message.FailAuth.DeleteSite"], MessageType.Warning);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.LogError(ex, "Error Deleting Site {SiteId} {Error}", PageState.Site.SiteId, ex.Message);
|
|
AddModuleMessage(Localizer["Error.DeleteSite"], MessageType.Error);
|
|
}
|
|
}
|
|
|
|
private async Task SendEmail()
|
|
{
|
|
if (_smtphost != "" && _smtpport != "" && _smtpsender != "")
|
|
{
|
|
try
|
|
{
|
|
var settings = await SettingService.GetSiteSettingsAsync(PageState.Site.SiteId);
|
|
SettingService.SetSetting(settings, "SMTPHost", _smtphost, true);
|
|
SettingService.SetSetting(settings, "SMTPPort", _smtpport, true);
|
|
SettingService.SetSetting(settings, "SMTPSSL", _smtpssl, true);
|
|
SettingService.SetSetting(settings, "SMTPUsername", _smtpusername, true);
|
|
SettingService.SetSetting(settings, "SMTPPassword", _smtppassword, true);
|
|
SettingService.SetSetting(settings, "SMTPSender", _smtpsender, true);
|
|
await SettingService.UpdateSiteSettingsAsync(settings, PageState.Site.SiteId);
|
|
await logger.LogInformation("Site SMTP Settings Saved");
|
|
|
|
await NotificationService.AddNotificationAsync(new Notification(PageState.Site.SiteId, PageState.User, PageState.Site.Name + " SMTP Configuration Test", "SMTP Server Is Configured Correctly."));
|
|
AddModuleMessage(Localizer["Info.Smtp.SaveSettings"], MessageType.Info);
|
|
var interop = new Interop(JSRuntime);
|
|
await interop.ScrollTo(0, 0, "smooth");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.LogError(ex, "Error Testing SMTP Configuration");
|
|
AddModuleMessage(Localizer["Error.Smtp.TestConfig"], MessageType.Error);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AddModuleMessage(Localizer["Message.Required.Smtp"], MessageType.Warning);
|
|
}
|
|
}
|
|
|
|
private async Task GetAliases()
|
|
{
|
|
_urls = string.Empty;
|
|
_defaultalias = string.Empty;
|
|
_aliases = await AliasService.GetAliasesAsync();
|
|
_aliases = _aliases.Where(item => item.SiteId == PageState.Site.SiteId && item.TenantId == PageState.Site.TenantId).OrderBy(item => item.AliasId).ToList();
|
|
foreach (Alias alias in _aliases)
|
|
{
|
|
_urls += (_urls == string.Empty) ? alias.Name.Trim() : ", " + alias.Name.Trim();
|
|
if (alias.IsDefault && string.IsNullOrEmpty(_defaultalias)) _defaultalias = alias.Name.Trim();
|
|
}
|
|
if (string.IsNullOrEmpty(_defaultalias)) _defaultalias = _aliases.First().Name.Trim();
|
|
}
|
|
|
|
private void ToggleSMTPPassword()
|
|
{
|
|
if (_smtppasswordtype == "password")
|
|
{
|
|
_smtppasswordtype = "text";
|
|
_togglesmtppassword = SharedLocalizer["HidePassword"];
|
|
}
|
|
else
|
|
{
|
|
_smtppasswordtype = "password";
|
|
_togglesmtppassword = SharedLocalizer["ShowPassword"];
|
|
}
|
|
}
|
|
}
|