From 467b6ba9da1ec34a54961b9ca309dfdc9b66a40f Mon Sep 17 00:00:00 2001 From: Grayson Walker Date: Wed, 15 Sep 2021 19:10:14 -0400 Subject: [PATCH] site validation --- Oqtane.Client/Modules/Admin/Site/Index.razor | 516 ++++++++++--------- 1 file changed, 264 insertions(+), 252 deletions(-) diff --git a/Oqtane.Client/Modules/Admin/Site/Index.razor b/Oqtane.Client/Modules/Admin/Site/Index.razor index 8d53687f..8602c80c 100644 --- a/Oqtane.Client/Modules/Admin/Site/Index.razor +++ b/Oqtane.Client/Modules/Admin/Site/Index.razor @@ -13,213 +13,217 @@ @if (_initialized) { -
-
- -
- -
-
-
- -
- @if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) - { - - } - else - { - - } -
-
-
- -
- -
-
-
- -
- -
-
-
-
+
- +
- +
- +
- + @if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) + { + + } + else + { + + }
- +
- -
-
-
- -
- -
-
-
- -
- -
-
- -
-
-
-
-
-
-
-
- @Localizer["Smtp.Required.EnableNotificationJob"]
-
-
-
- -
- -
-
-
- -
- -
-
-
- -
-
- +
- -
-
-
- -
- -
-
-
- -
- -
-
- -

- -
- - -
-
-
-
- -
-
-
- -
- -
-
-
- -
- -
-
-
- @if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) - { -
+
- +
- +
- +
- +
- +
- + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+
+
+
+
+
+
+
+ @Localizer["Smtp.Required.EnableNotificationJob"]
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +

+ +
+ + +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
- } -
- - -
-
- + @if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) + { +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ } +
+ + +
+
+ + } @code { + private ElementReference form; + private bool validated = false; private bool _initialized = false; private List _themeList; private List _themes = new List(); @@ -384,122 +388,130 @@ private async Task SaveSite() { - try + validated = true; + var interop = new Interop(JSRuntime); + if (await interop.FormValid(form)) { - if (_name != string.Empty && _urls != string.Empty && _themetype != "-" && _containertype != "-") + try { - var unique = true; - if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) + if (_name != string.Empty && _urls != string.Empty && _themetype != "-" && _containertype != "-") { - _urls = _urls.Replace("\n", ","); - foreach (string name in _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) + var unique = true; + if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) { - if (_aliasList.Exists(item => item.Name == name && item.SiteId != PageState.Alias.SiteId && item.TenantId != PageState.Alias.TenantId)) + foreach (string name in _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { - unique = false; + if (_aliasList.Exists(item => item.Name == name && item.SiteId != PageState.Alias.SiteId && item.TenantId != PageState.Alias.TenantId)) + { + unique = false; + } } } - } - if (unique) - { - var site = await SiteService.GetSiteAsync(PageState.Site.SiteId); - if (site != null) + if (unique) { - bool refresh = (site.DefaultThemeType != _themetype || site.DefaultContainerType != _containertype); - - site.Name = _name; - site.AllowRegistration = (_allowregistration == null ? true : Boolean.Parse(_allowregistration)); - site.IsDeleted = (_isdeleted == null ? true : Boolean.Parse(_isdeleted)); - - site.LogoFileId = null; - var logofileid = _logofilemanager.GetFileId(); - if (logofileid != -1) + var site = await SiteService.GetSiteAsync(PageState.Site.SiteId); + if (site != null) { - site.LogoFileId = logofileid; - } - var faviconFieldId = _faviconfilemanager.GetFileId(); - if (faviconFieldId != -1) - { - site.FaviconFileId = faviconFieldId; - } - site.DefaultThemeType = _themetype; - site.DefaultContainerType = _containertype; - site.AdminContainerType = _admincontainertype; + bool refresh = (site.DefaultThemeType != _themetype || site.DefaultContainerType != _containertype); - site.PwaIsEnabled = (_pwaisenabled == null ? true : Boolean.Parse(_pwaisenabled)); - var pwaappiconfileid = _pwaappiconfilemanager.GetFileId(); - if (pwaappiconfileid != -1) - { - site.PwaAppIconFileId = pwaappiconfileid; - } - var pwasplashiconfileid = _pwasplashiconfilemanager.GetFileId(); - if (pwasplashiconfileid != -1) - { - site.PwaSplashIconFileId = pwasplashiconfileid; - } + site.Name = _name; + site.AllowRegistration = (_allowregistration == null ? true : Boolean.Parse(_allowregistration)); + site.IsDeleted = (_isdeleted == null ? true : Boolean.Parse(_isdeleted)); - site = await SiteService.UpdateSiteAsync(site); - - var settings = await SettingService.GetSiteSettingsAsync(site.SiteId); - SettingService.SetSetting(settings, "SMTPHost", _smtphost); - SettingService.SetSetting(settings, "SMTPPort", _smtpport); - SettingService.SetSetting(settings, "SMTPSSL", _smtpssl); - SettingService.SetSetting(settings, "SMTPUsername", _smtpusername); - SettingService.SetSetting(settings, "SMTPPassword", _smtppassword); - SettingService.SetSetting(settings, "SMTPSender", _smtpsender); - await SettingService.UpdateSiteSettingsAsync(settings, site.SiteId); - - if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) - { - var names = _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); - foreach (Alias alias in _aliasList.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList()) + site.LogoFileId = null; + var logofileid = _logofilemanager.GetFileId(); + if (logofileid != -1) { - if (!names.Contains(alias.Name)) + site.LogoFileId = logofileid; + } + var faviconFieldId = _faviconfilemanager.GetFileId(); + if (faviconFieldId != -1) + { + site.FaviconFileId = faviconFieldId; + } + site.DefaultThemeType = _themetype; + site.DefaultContainerType = _containertype; + site.AdminContainerType = _admincontainertype; + + site.PwaIsEnabled = (_pwaisenabled == null ? true : Boolean.Parse(_pwaisenabled)); + var pwaappiconfileid = _pwaappiconfilemanager.GetFileId(); + if (pwaappiconfileid != -1) + { + site.PwaAppIconFileId = pwaappiconfileid; + } + var pwasplashiconfileid = _pwasplashiconfilemanager.GetFileId(); + if (pwasplashiconfileid != -1) + { + site.PwaSplashIconFileId = pwasplashiconfileid; + } + + site = await SiteService.UpdateSiteAsync(site); + + var settings = await SettingService.GetSiteSettingsAsync(site.SiteId); + SettingService.SetSetting(settings, "SMTPHost", _smtphost); + SettingService.SetSetting(settings, "SMTPPort", _smtpport); + SettingService.SetSetting(settings, "SMTPSSL", _smtpssl); + SettingService.SetSetting(settings, "SMTPUsername", _smtpusername); + SettingService.SetSetting(settings, "SMTPPassword", _smtppassword); + SettingService.SetSetting(settings, "SMTPSender", _smtpsender); + await SettingService.UpdateSiteSettingsAsync(settings, site.SiteId); + + if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host)) + { + var names = _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + foreach (Alias alias in _aliasList.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList()) { - await AliasService.DeleteAliasAsync(alias.AliasId); + if (!names.Contains(alias.Name)) + { + await AliasService.DeleteAliasAsync(alias.AliasId); + } + } + + foreach (string name in names) + { + if (!_aliasList.Exists(item => item.Name == name)) + { + Alias alias = new Alias(); + alias.Name = name; + alias.TenantId = site.TenantId; + alias.SiteId = site.SiteId; + await AliasService.AddAliasAsync(alias); + } } } - foreach (string name in names) + await logger.LogInformation("Site Settings Saved {Site}", site); + + if (refresh) { - if (!_aliasList.Exists(item => item.Name == name)) - { - Alias alias = new Alias(); - alias.Name = name; - alias.TenantId = site.TenantId; - alias.SiteId = site.SiteId; - await AliasService.AddAliasAsync(alias); - } + NavigationManager.NavigateTo(NavigateUrl()); // refresh to show new theme or container + } + else + { + AddModuleMessage(Localizer["Success.Settings.SaveSite"], MessageType.Success); } } - - await logger.LogInformation("Site Settings Saved {Site}", site); - - if (refresh) - { - NavigationManager.NavigateTo(NavigateUrl()); // refresh to show new theme or container - } - else - { - AddModuleMessage(Localizer["Success.Settings.SaveSite"], MessageType.Success); - } + } + else + { + AddModuleMessage(Localizer["Message.Aliases.Taken"], MessageType.Warning); } } else { - AddModuleMessage(Localizer["Message.Aliases.Taken"], MessageType.Warning); + AddModuleMessage(Localizer["Message.Required.SiteName"], MessageType.Warning); } } - else + catch (Exception ex) { - AddModuleMessage(Localizer["Message.Required.SiteName"], MessageType.Warning); + await logger.LogError(ex, "Error Saving Site {SiteId} {Error}", PageState.Site.SiteId, ex.Message); + AddModuleMessage(Localizer["Error.SaveSite"], MessageType.Error); } } - catch (Exception ex) + else { - await logger.LogError(ex, "Error Saving Site {SiteId} {Error}", PageState.Site.SiteId, ex.Message); - AddModuleMessage(Localizer["Error.SaveSite"], MessageType.Error); + AddModuleMessage(SharedLocalizer["Message.InfoRequired"], MessageType.Warning); } } @@ -560,7 +572,7 @@ } else { - AddModuleMessage(Localizer["Message.Required.Smtp"], MessageType.Warning); + AddModuleMessage(Localizer["Message.required.Smtp"], MessageType.Warning); } } }