Skip to content

Commit

Permalink
Merge pull request #625 from mikecasas/feature-email
Browse files Browse the repository at this point in the history
Send notification based on a future datetime
  • Loading branch information
sbwalker authored Jun 19, 2020
2 parents 04ffb07 + 20b83c8 commit 65df054
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Oqtane.Client/Modules/Admin/UserProfile/Add.razor
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
notification.ParentId = null;
notification.CreatedOn = DateTime.UtcNow;
notification.IsDelivered = false;
notification.DeliveredOn = null;
notification.DeliveredOn = null;
notification.SendOn = DateTime.UtcNow;
notification = await NotificationService.AddNotificationAsync(notification);
await logger.LogInformation("Notification Created {Notification}", notification);
NavigationManager.NavigateTo(NavigateUrl());
Expand Down
3 changes: 2 additions & 1 deletion Oqtane.Client/Modules/Admin/UserProfile/View.razor
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@
notification.ParentId = notificationid;
notification.CreatedOn = DateTime.UtcNow;
notification.IsDelivered = false;
notification.DeliveredOn = null;
notification.DeliveredOn = null;
notification.SendOn = DateTime.UtcNow;
notification = await NotificationService.AddNotificationAsync(notification);
await logger.LogInformation("Notification Created {Notification}", notification);
NavigationManager.NavigateTo(NavigateUrl());
Expand Down
4 changes: 3 additions & 1 deletion Oqtane.Server/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private async Task<User> CreateUser(User user)
notification.SiteId = user.SiteId;
notification.FromUserId = null;
notification.ToUserId = newUser.UserId;
notification.ToEmail = "";
notification.ToEmail = newUser.Email;
notification.Subject = "User Account Verification";
string token = await _identityUserManager.GenerateEmailConfirmationTokenAsync(identityuser);
string url = HttpContext.Request.Scheme + "://" + _tenants.GetAlias().Name + "/login?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token);
Expand All @@ -157,6 +157,7 @@ private async Task<User> CreateUser(User user)
notification.CreatedOn = DateTime.UtcNow;
notification.IsDelivered = false;
notification.DeliveredOn = null;
notification.SendOn = DateTime.UtcNow;
_notifications.AddNotification(notification);
}

Expand Down Expand Up @@ -385,6 +386,7 @@ public async Task Forgot([FromBody] User user)
notification.CreatedOn = DateTime.UtcNow;
notification.IsDelivered = false;
notification.DeliveredOn = null;
notification.SendOn = DateTime.UtcNow;
_notifications.AddNotification(notification);
_logger.Log(LogLevel.Information, this, LogFunction.Security, "Password Reset Notification Sent For {Username}", user.Username);
}
Expand Down
4 changes: 4 additions & 0 deletions Oqtane.Server/Oqtane.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@
<Content Remove="wwwroot\Modules\Templates\**" />
<EmbeddedResource Remove="wwwroot\Modules\Templates\**" />
</ItemGroup>
<ItemGroup>
<None Remove="Scripts\Tenant.01.00.01.01.sql" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Scripts\Master.00.00.00.00.sql" />
<EmbeddedResource Include="Scripts\Master.00.09.00.00.sql" />
<EmbeddedResource Include="Scripts\Master.01.00.01.00.sql" />
<EmbeddedResource Include="Scripts\Tenant.01.00.01.01.sql" />
<EmbeddedResource Include="Scripts\Tenant.00.00.00.00.sql" />
<EmbeddedResource Include="Scripts\Tenant.00.09.00.00.sql" />
<EmbeddedResource Include="Scripts\Tenant.00.09.01.00.sql" />
Expand Down
1 change: 1 addition & 0 deletions Oqtane.Server/Repository/NotificationRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public IEnumerable<Notification> GetNotifications(int siteId, int fromUserId, in
return _db.Notification
.Where(item => item.SiteId == siteId)
.Where(item => item.IsDelivered == false)
.Where(item => item.SendOn < System.DateTime.UtcNow)
.ToList();
}

Expand Down
12 changes: 12 additions & 0 deletions Oqtane.Server/Scripts/Tenant.01.00.01.01.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Version 1.0.1 Notification migration script
*/

ALTER TABLE [dbo].[Notification] ADD
[SendOn] [datetime] NULL
GO

UPDATE [dbo].[Notification] SET SendOn = CreatedOn WHERE SendOn IS NULL
GO
1 change: 1 addition & 0 deletions Oqtane.Shared/Models/Notification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Notification : IDeletable
public string DeletedBy { get; set; }
public DateTime? DeletedOn { get; set; }
public bool IsDeleted { get; set; }
public DateTime? SendOn { get; set; }
}

}

0 comments on commit 65df054

Please sign in to comment.