add ability to test SMTP connection in Site Settings
This commit is contained in:
		| @ -7,146 +7,150 @@ | ||||
| @inject IThemeService  ThemeService | ||||
| @inject ISettingService  SettingService | ||||
| @inject IStringLocalizer<Index> Localizer | ||||
| @inject INotificationService NotificationService | ||||
|  | ||||
| @if (_initialized) | ||||
| { | ||||
| <table class="table table-borderless"> | ||||
|     <tr> | ||||
|         <td> | ||||
|             <Label For="name" HelpText="Enter the site name" ResourceKey="Name">Name: </Label> | ||||
|         </td> | ||||
|         <td> | ||||
|             <input id="name" class="form-control" @bind="@_name" /> | ||||
|         </td> | ||||
|     </tr> | ||||
|     <tr> | ||||
|         <td> | ||||
|             <Label For="tenant" HelpText="Enter the tenant for the site" ResourceKey="Tenant">Tenant: </Label> | ||||
|         </td> | ||||
|         <td> | ||||
|             <input id="tenant" class="form-control" @bind="@_tenant" readonly /> | ||||
|         </td> | ||||
|     </tr> | ||||
|     <tr> | ||||
|         <td> | ||||
|             <Label For="alias" HelpText="Enter the alias for the server" ResourceKey="Aliases">Aliases: </Label> | ||||
|         </td> | ||||
|         <td> | ||||
|             <textarea id="alias" class="form-control" @bind="@_urls" rows="3"></textarea> | ||||
|         </td> | ||||
|     </tr> | ||||
|     <tr> | ||||
|         <td> | ||||
|             <Label For="logo" HelpText="Upload a logo for the site" ResourceKey="Logo">Logo: </Label> | ||||
|         </td> | ||||
|         <td> | ||||
|             <FileManager FileId="@_logofileid" Filter="@Constants.ImageFiles" @ref="_logofilemanager" /> | ||||
|         </td> | ||||
|     </tr> | ||||
|     <tr> | ||||
|         <td> | ||||
|             <Label For="favicon" HelpText="Select Your default icon" ResourceKey="FavoriteIcon">Favicon: </Label> | ||||
|         </td> | ||||
|         <td> | ||||
|             <FileManager FileId="@_faviconfileid" Filter="ico" @ref="_faviconfilemanager" /> | ||||
|         </td> | ||||
|     </tr> | ||||
|     <tr> | ||||
|         <td> | ||||
|             <Label For="defaultTheme" HelpText="Select the sites default theme" ResourceKey="DefaultTheme">Default Theme: </Label> | ||||
|         </td> | ||||
|         <td> | ||||
|             <select id="defaultTheme" class="form-control" @onchange="(e => ThemeChanged(e))"> | ||||
|                 <option value="-"><@Localizer["Select Theme"]></option> | ||||
|                 @foreach (var theme in _themes) | ||||
|                 { | ||||
|                     if (theme.TypeName == _themetype) | ||||
|                     { | ||||
|                         <option value="@theme.TypeName" selected>@theme.Name</option> | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         <option value="@theme.TypeName">@theme.Name</option> | ||||
|                     } | ||||
|                 } | ||||
|             </select> | ||||
|         </td> | ||||
|     </tr> | ||||
|     @if (_layouts.Count > 0) | ||||
|     { | ||||
|     <table class="table table-borderless"> | ||||
|         <tr> | ||||
|             <td> | ||||
|                 <Label For="defaultLayout" HelpText="Select the sites default layout" ResourceKey="DefaultLayout">Default Layout: </Label> | ||||
|                 <Label For="name" HelpText="Enter the site name" ResourceKey="Name">Name: </Label> | ||||
|             </td> | ||||
|             <td> | ||||
|                 <select id="defaultLayout" class="form-control" @bind="@_layouttype"> | ||||
|                     <option value="-"><@Localizer["Select Layout"]></option> | ||||
|                     @foreach (var layout in _layouts) | ||||
|                 <input id="name" class="form-control" @bind="@_name" /> | ||||
|             </td> | ||||
|         </tr> | ||||
|         <tr> | ||||
|             <td> | ||||
|                 <Label For="tenant" HelpText="Enter the tenant for the site" ResourceKey="Tenant">Tenant: </Label> | ||||
|             </td> | ||||
|             <td> | ||||
|                 <input id="tenant" class="form-control" @bind="@_tenant" readonly /> | ||||
|             </td> | ||||
|         </tr> | ||||
|         <tr> | ||||
|             <td> | ||||
|                 <Label For="alias" HelpText="Enter the alias for the server" ResourceKey="Aliases">Aliases: </Label> | ||||
|             </td> | ||||
|             <td> | ||||
|                 <textarea id="alias" class="form-control" @bind="@_urls" rows="3"></textarea> | ||||
|             </td> | ||||
|         </tr> | ||||
|         <tr> | ||||
|             <td> | ||||
|                 <Label For="allowRegister" HelpText="Do you want the users to be able to register for an account on the site" ResourceKey="AllowRegistration">Allow User Registration? </Label> | ||||
|             </td> | ||||
|             <td> | ||||
|                 <select id="allowRegister" class="form-control" @bind="@_allowregistration"> | ||||
|                     <option value="True">@Localizer["Yes"]</option> | ||||
|                     <option value="False">@Localizer["No"]</option> | ||||
|                 </select> | ||||
|             </td> | ||||
|         </tr> | ||||
|         <tr> | ||||
|             <td> | ||||
|                 <Label For="isDeleted" HelpText="Is this site deleted?" ResourceKey="IsDeleted">Is Deleted? </Label> | ||||
|             </td> | ||||
|             <td> | ||||
|                 <select id="isDeleted" class="form-control" @bind="@_isdeleted"> | ||||
|                     <option value="True">@Localizer["Yes"]</option> | ||||
|                     <option value="False">@Localizer["No"]</option> | ||||
|                 </select> | ||||
|             </td> | ||||
|         </tr> | ||||
|     </table> | ||||
|     <Section Name="Appearance" Heading="Appearance" ResourceKey="Appearance"> | ||||
|     <table class="table table-borderless"> | ||||
|         <tr> | ||||
|             <td> | ||||
|                 <Label For="logo" HelpText="Specify a logo for the site" ResourceKey="Logo">Logo: </Label> | ||||
|             </td> | ||||
|             <td> | ||||
|                 <FileManager FileId="@_logofileid" Filter="@Constants.ImageFiles" @ref="_logofilemanager" /> | ||||
|             </td> | ||||
|         </tr> | ||||
|         <tr> | ||||
|             <td> | ||||
|                 <Label For="favicon" HelpText="Specify a Favicon" ResourceKey="FavoriteIcon">Favicon: </Label> | ||||
|             </td> | ||||
|             <td> | ||||
|                 <FileManager FileId="@_faviconfileid" Filter="ico" @ref="_faviconfilemanager" /> | ||||
|             </td> | ||||
|         </tr> | ||||
|         <tr> | ||||
|             <td> | ||||
|                 <Label For="defaultTheme" HelpText="Select the sites default theme" ResourceKey="DefaultTheme">Default Theme: </Label> | ||||
|             </td> | ||||
|             <td> | ||||
|                 <select id="defaultTheme" class="form-control" @onchange="(e => ThemeChanged(e))"> | ||||
|                     <option value="-"><@Localizer["Select Theme"]></option> | ||||
|                     @foreach (var theme in _themes) | ||||
|                     { | ||||
|                         <option value="@(layout.TypeName)">@(layout.Name)</option> | ||||
|                         if (theme.TypeName == _themetype) | ||||
|                         { | ||||
|                             <option value="@theme.TypeName" selected>@theme.Name</option> | ||||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                             <option value="@theme.TypeName">@theme.Name</option> | ||||
|                         } | ||||
|                     } | ||||
|                 </select> | ||||
|             </td> | ||||
|         </tr> | ||||
|     } | ||||
|     <tr> | ||||
|         <td> | ||||
|             <Label For="defaultContainer" HelpText="Select the default container for the site" ResourceKey="DefaultContainer">Default Container: </Label> | ||||
|         </td> | ||||
|         <td> | ||||
|             <select id="defaultContainer" class="form-control" @bind="@_containertype"> | ||||
|                 <option value="-"><@Localizer["Select Container"]></option> | ||||
|                 @foreach (var container in _containers) | ||||
|                 { | ||||
|                     <option value="@container.TypeName">@container.Name</option> | ||||
|                 } | ||||
|             </select> | ||||
|         </td> | ||||
|     </tr> | ||||
|     <tr> | ||||
|         <td> | ||||
|             <Label For="defaultAdminContainer" HelpText="Select the default admin container for the site" ResourceKey="DefaultAdminContainer">Default Admin Container: </Label> | ||||
|         </td> | ||||
|         <td> | ||||
|             <select id="defaultAdminContainer" class="form-control" @bind="@_admincontainertype"> | ||||
|                 <option value="-"><@Localizer["Select Container"]></option> | ||||
|                 <option value=""><@Localizer["Default Admin Container"]></option> | ||||
|                 @foreach (var container in _containers) | ||||
|                 { | ||||
|                     <option value="@container.TypeName">@container.Name</option> | ||||
|                 } | ||||
|             </select> | ||||
|         </td> | ||||
|     </tr> | ||||
|     <tr> | ||||
|         <td> | ||||
|             <Label For="allowRegister" HelpText="Do you want the users to be able to register for an account on the site" ResourceKey="AllowRegistration">Allow User Registration? </Label> | ||||
|         </td> | ||||
|         <td> | ||||
|             <select id="allowRegister" class="form-control" @bind="@_allowregistration"> | ||||
|                 <option value="True">@Localizer["Yes"]</option> | ||||
|                 <option value="False">@Localizer["No"]</option> | ||||
|             </select> | ||||
|         </td> | ||||
|     </tr> | ||||
|     <tr> | ||||
|         <td> | ||||
|             <Label For="isDeleted" HelpText="Is this site deleted?" ResourceKey="IsDeleted">Is Deleted? </Label> | ||||
|         </td> | ||||
|         <td> | ||||
|             <select id="isDeleted" class="form-control" @bind="@_isdeleted"> | ||||
|                 <option value="True">@Localizer["Yes"]</option> | ||||
|                 <option value="False">@Localizer["No"]</option> | ||||
|             </select> | ||||
|         </td> | ||||
|     </tr> | ||||
| </table> | ||||
|  | ||||
|         @if (_layouts.Count > 0) | ||||
|         { | ||||
|             <tr> | ||||
|                 <td> | ||||
|                     <Label For="defaultLayout" HelpText="Select the sites default layout" ResourceKey="DefaultLayout">Default Layout: </Label> | ||||
|                 </td> | ||||
|                 <td> | ||||
|                     <select id="defaultLayout" class="form-control" @bind="@_layouttype"> | ||||
|                         <option value="-"><@Localizer["Select Layout"]></option> | ||||
|                         @foreach (var layout in _layouts) | ||||
|                         { | ||||
|                             <option value="@(layout.TypeName)">@(layout.Name)</option> | ||||
|                         } | ||||
|                     </select> | ||||
|                 </td> | ||||
|             </tr> | ||||
|         } | ||||
|         <tr> | ||||
|             <td> | ||||
|                 <Label For="defaultContainer" HelpText="Select the default container for the site" ResourceKey="DefaultContainer">Default Container: </Label> | ||||
|             </td> | ||||
|             <td> | ||||
|                 <select id="defaultContainer" class="form-control" @bind="@_containertype"> | ||||
|                     <option value="-"><@Localizer["Select Container"]></option> | ||||
|                     @foreach (var container in _containers) | ||||
|                     { | ||||
|                         <option value="@container.TypeName">@container.Name</option> | ||||
|                     } | ||||
|                 </select> | ||||
|             </td> | ||||
|         </tr> | ||||
|         <tr> | ||||
|             <td> | ||||
|                 <Label For="defaultAdminContainer" HelpText="Select the default admin container for the site" ResourceKey="DefaultAdminContainer">Default Admin Container: </Label> | ||||
|             </td> | ||||
|             <td> | ||||
|                 <select id="defaultAdminContainer" class="form-control" @bind="@_admincontainertype"> | ||||
|                     <option value="-"><@Localizer["Select Container"]></option> | ||||
|                     <option value=""><@Localizer["Default Admin Container"]></option> | ||||
|                     @foreach (var container in _containers) | ||||
|                     { | ||||
|                         <option value="@container.TypeName">@container.Name</option> | ||||
|                     } | ||||
|                 </select> | ||||
|             </td> | ||||
|         </tr> | ||||
|     </table> | ||||
|     </Section> | ||||
|     <Section Name="SMTP" Heading="SMTP Settings" ResourceKey="SMTPSettings"> | ||||
|         <table class="table table-borderless"> | ||||
|             <tr> | ||||
|                 <td colspan="2"> | ||||
|                     @Localizer["Please Note That SMTP Requires The Notification Job To Be Enabled In the Scheduled Jobs"] | ||||
|                     <strong>@Localizer["Please Note That SMTP Requires The Notification Job To Be Enabled In Scheduled Jobs"]</strong> | ||||
|                 </td> | ||||
|             </tr> | ||||
|             <tr> | ||||
| @ -201,6 +205,8 @@ | ||||
|                 </td> | ||||
|             </tr> | ||||
|         </table> | ||||
|         <button type="button" class="btn btn-secondary" @onclick="SendEmail">@Localizer["Test SMTP Configuration"]</button> | ||||
|         <br /><br /> | ||||
|     </Section> | ||||
|     <Section Name="PWA" Heading="Progressive Web Application Settings" ResourceKey="PWASettings"> | ||||
|         <table class="table table-borderless"> | ||||
| @ -482,7 +488,6 @@ | ||||
|                         await SettingService.UpdateSiteSettingsAsync(settings, site.SiteId); | ||||
|  | ||||
|                         await logger.LogInformation("Site Settings Saved {Site}", site); | ||||
|  | ||||
|                         AddModuleMessage(Localizer["Site Settings Saved"], MessageType.Success); | ||||
|                     } | ||||
|                 } | ||||
| @ -502,4 +507,36 @@ | ||||
|             AddModuleMessage(Localizer["Error Saving Site"], MessageType.Error); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private async Task SendEmail() | ||||
|     { | ||||
|         if (_smtphost != "" && _smtpport != "" && _smtpsender != "") | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var settings = await SettingService.GetSiteSettingsAsync(PageState.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, PageState.Site.SiteId); | ||||
|                 await logger.LogInformation("Site SMTP Settings Saved"); | ||||
|  | ||||
|                 await NotificationService.AddNotificationAsync(new Notification(PageState.Site.SiteId, PageState.User.DisplayName, PageState.User.Email, PageState.User.DisplayName, PageState.User.Email, PageState.Site.Name + " SMTP Configuration Test", "SMTP Server Is Configured Correctly.")); | ||||
|                 AddModuleMessage(Localizer["SMTP Settings Saved And A Message Has Been Sent To The Email Address Associated To Your User Account... Please Wait A Few Minutes For Delivery. If You Do Not Receive The Email Please Review The Notification Job In Scheduled Jobs For Any Log Details."], MessageType.Info); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 await logger.LogError(ex, "Error Testing SMTP Configuration"); | ||||
|                 AddModuleMessage(Localizer["Error Testing SMTP Configuration"], MessageType.Error); | ||||
|             } | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             AddModuleMessage(Localizer["You Must Specify The SMTP Host, Port, And Sender"], MessageType.Warning); | ||||
|         } | ||||
|  | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -55,7 +55,7 @@ | ||||
|             { | ||||
|                 var notification = new Notification(PageState.Site.SiteId, PageState.User, user, subject, body, null); | ||||
|                 notification = await NotificationService.AddNotificationAsync(notification); | ||||
|                 await logger.LogInformation("Notification Created {Notification}", notification); | ||||
|                 await logger.LogInformation("Notification Created {NotificationId}", notification.NotificationId); | ||||
|                 NavigationManager.NavigateTo(NavigateUrl()); | ||||
|             } | ||||
|             else | ||||
|  | ||||
| @ -183,7 +183,7 @@ | ||||
|             { | ||||
|                 var notification = new Notification(PageState.Site.SiteId, PageState.User, user, subject, body, notificationid); | ||||
|                 notification = await NotificationService.AddNotificationAsync(notification); | ||||
|                 await logger.LogInformation("Notification Created {Notification}", notification); | ||||
|                 await logger.LogInformation("Notification Created {NotificationId}", notification.NotificationId); | ||||
|                 NavigationManager.NavigateTo(NavigateUrl()); | ||||
|             } | ||||
|             else | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Shaun Walker
					Shaun Walker