diff --git a/Oqtane.Client/Modules/Admin/Site/Index.razor b/Oqtane.Client/Modules/Admin/Site/Index.razor index 63f22032..13d51301 100644 --- a/Oqtane.Client/Modules/Admin/Site/Index.razor +++ b/Oqtane.Client/Modules/Admin/Site/Index.razor @@ -605,8 +605,10 @@ 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.")); + 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) { @@ -616,7 +618,7 @@ } else { - AddModuleMessage(Localizer["Message.required.Smtp"], MessageType.Warning); + AddModuleMessage(Localizer["Message.Required.Smtp"], MessageType.Warning); } } diff --git a/Oqtane.Client/Modules/Admin/UserProfile/Add.razor b/Oqtane.Client/Modules/Admin/UserProfile/Add.razor index d04cc1b9..ceeb2713 100644 --- a/Oqtane.Client/Modules/Admin/UserProfile/Add.razor +++ b/Oqtane.Client/Modules/Admin/UserProfile/Add.razor @@ -49,7 +49,7 @@ var user = await UserService.GetUserAsync(username, PageState.Site.SiteId); if (user != null) { - var notification = new Notification(PageState.Site.SiteId, PageState.User, user, subject, body, null); + var notification = new Notification(PageState.Site.SiteId, PageState.User, user, subject, body); notification = await NotificationService.AddNotificationAsync(notification); await logger.LogInformation("Notification Created {NotificationId}", notification.NotificationId); NavigationManager.NavigateTo(NavigateUrl()); diff --git a/Oqtane.Server/Controllers/UserController.cs b/Oqtane.Server/Controllers/UserController.cs index 89efac3e..df6a804e 100644 --- a/Oqtane.Server/Controllers/UserController.cs +++ b/Oqtane.Server/Controllers/UserController.cs @@ -173,7 +173,7 @@ namespace Oqtane.Controllers string token = await _identityUserManager.GenerateEmailConfirmationTokenAsync(identityuser); string url = HttpContext.Request.Scheme + "://" + _alias.Name + "/login?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token); string body = "Dear " + user.DisplayName + ",\n\nIn Order To Complete The Registration Of Your User Account Please Click The Link Displayed Below:\n\n" + url + "\n\nThank You!"; - var notification = new Notification(user.SiteId, null, newUser, "User Account Verification", body, null); + var notification = new Notification(user.SiteId, newUser, "User Account Verification", body); _notifications.AddNotification(notification); } @@ -428,7 +428,7 @@ namespace Oqtane.Controllers "\n\nIf you did not request to reset your password you can safely ignore this message." + "\n\nThank You!"; - var notification = new Notification(user.SiteId, null, user, "User Password Reset", body, null); + var notification = new Notification(user.SiteId, user, "User Password Reset", body); _notifications.AddNotification(notification); _logger.Log(LogLevel.Information, this, LogFunction.Security, "Password Reset Notification Sent For {Username}", user.Username); } diff --git a/Oqtane.Server/Infrastructure/LogManager.cs b/Oqtane.Server/Infrastructure/LogManager.cs index 5a1d9984..b75a69f0 100644 --- a/Oqtane.Server/Infrastructure/LogManager.cs +++ b/Oqtane.Server/Infrastructure/LogManager.cs @@ -208,7 +208,7 @@ namespace Oqtane.Infrastructure if (userrole.Role.Name == RoleNames.Host) { var url = _accessor.HttpContext.Request.Scheme + "://" + _tenantManager.GetAlias().Name + "/admin/log"; - var notification = new Notification(log.SiteId.Value, null, userrole.User, "Site " + log.Level + " Notification", "Please visit " + url + " for more information", null); + var notification = new Notification(log.SiteId.Value, userrole.User, "Site " + log.Level + " Notification", "Please visit " + url + " for more information"); _notifications.AddNotification(notification); } } diff --git a/Oqtane.Shared/Models/Notification.cs b/Oqtane.Shared/Models/Notification.cs index 64e0fbc7..975b28c8 100644 --- a/Oqtane.Shared/Models/Notification.cs +++ b/Oqtane.Shared/Models/Notification.cs @@ -94,9 +94,46 @@ namespace Oqtane.Models /// public DateTime? SendOn { get; set; } + + // constructors public Notification() {} + public Notification(int siteId, User to, string subject, string body) + { + ConstructNotification(siteId, null, "", "", to, "", "", subject, body, null, null); + } + + public Notification(int siteId, User to, string subject, string body, DateTime sendOn) + { + ConstructNotification(siteId, null, "", "", to, "", "", subject, body, null, sendOn); + } + + public Notification(int siteId, User from, User to, string subject, string body) + { + ConstructNotification(siteId, from, "", "", to, "", "", subject, body, null, null); + } + public Notification(int siteId, User from, User to, string subject, string body, int? parentId) + { + ConstructNotification(siteId, from, "", "", to, "", "", subject, body, parentId, null); + } + + public Notification(int siteId, string toDisplayName, string toEmail, string subject, string body) + { + ConstructNotification(siteId, null, "", "", null, toDisplayName, toEmail, subject, body, null, null); + } + + public Notification(int siteId, string toDisplayName, string toEmail, string subject, string body, DateTime sendOn) + { + ConstructNotification(siteId, null, "", "", null, toDisplayName, toEmail, subject, body, null, sendOn); + } + + public Notification(int siteId, string fromDisplayName, string fromEmail, string toDisplayName, string toEmail, string subject, string body) + { + ConstructNotification(siteId, null, fromDisplayName, fromEmail, null, toDisplayName, toEmail, subject, body, null, null); + } + + private void ConstructNotification(int siteId, User from, string fromDisplayName, string fromEmail, User to, string toDisplayName, string toEmail, string subject, string body, int? parentId, DateTime? sendOn) { SiteId = siteId; if (from != null) @@ -105,37 +142,38 @@ namespace Oqtane.Models FromDisplayName = from.DisplayName; FromEmail = from.Email; } + else + { + FromUserId = null; + FromDisplayName = fromDisplayName; + FromEmail = fromEmail; + } if (to != null) { ToUserId = to.UserId; ToDisplayName = to.DisplayName; ToEmail = to.Email; } + else + { + ToUserId = null; + ToDisplayName = toDisplayName; + ToEmail = toEmail; + } Subject = subject; Body = body; ParentId = parentId; CreatedOn = DateTime.UtcNow; + if (sendOn != null) + { + SendOn = sendOn; + } + else + { + SendOn = CreatedOn; + } IsDelivered = false; DeliveredOn = null; - SendOn = DateTime.UtcNow; - } - - public Notification(int siteId, string fromDisplayName, string fromEmail, string toDisplayName, string toEmail, string subject, string body) - { - SiteId = siteId; - FromUserId = null; - FromDisplayName = fromDisplayName; - FromEmail = fromEmail; - ToUserId = null; - ToDisplayName = toDisplayName; - ToEmail = toEmail; - Subject = subject; - Body = body; - ParentId = null; - CreatedOn = DateTime.UtcNow; - IsDelivered = false; - DeliveredOn = null; - SendOn = DateTime.UtcNow; } }