From 1d8b307bb5790aa8c0040a76638f57f757cfb782 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 18 May 2017 16:18:25 -0400 Subject: [PATCH] More notification updates --- Project-Unite/Controllers/ManageController.cs | 14 +++++++++- Project-Unite/Models/IdentityModels.cs | 2 +- Project-Unite/NotificationDaemon.cs | 27 +++++++++++++++++-- Project-Unite/Views/Manage/Index.cshtml | 11 +++++++- 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/Project-Unite/Controllers/ManageController.cs b/Project-Unite/Controllers/ManageController.cs index 243d2f0..c3d9921 100644 --- a/Project-Unite/Controllers/ManageController.cs +++ b/Project-Unite/Controllers/ManageController.cs @@ -111,6 +111,17 @@ namespace Project_Unite.Controllers } } + public ActionResult Notification(string id, string url) + { + var db = new ApplicationDbContext(); + var note = db.Notifications.FirstOrDefault(x => x.Id == id); + if (note == null) + return new HttpStatusCodeResult(404); + note.IsRead = false; + db.SaveChanges(); + return Redirect(url); + } + public ApplicationUserManager UserManager { get @@ -157,6 +168,7 @@ namespace Project_Unite.Controllers usr.ShowFollowers = model.ShowFollowers; usr.ShowFollowed = model.ShowFollowed; usr.ShowEmail = model.ShowEmail; + usr.EmailOnNotifications = model.EmailOnNotifications; usr.ShowPostAndTopicCounts = model.ShowPostAndTopicCounts; usr.ShowJoinDate = model.ShowJoinDate; if (usr.Email != model.Email) @@ -510,7 +522,7 @@ namespace Project_Unite.Controllers base.Dispose(disposing); } -#region Helpers + #region Helpers // Used for XSRF protection when adding external logins private const string XsrfKey = "XsrfId"; diff --git a/Project-Unite/Models/IdentityModels.cs b/Project-Unite/Models/IdentityModels.cs index 9e3898b..68c21fe 100644 --- a/Project-Unite/Models/IdentityModels.cs +++ b/Project-Unite/Models/IdentityModels.cs @@ -52,7 +52,7 @@ namespace Project_Unite.Models public bool ShowEmail { get; set; } public bool ShowPostAndTopicCounts { get; set; } public bool ShowJoinDate { get; set; } - + public bool EmailOnNotifications { get; set; } #endregion diff --git a/Project-Unite/NotificationDaemon.cs b/Project-Unite/NotificationDaemon.cs index 2e548ea..0512790 100644 --- a/Project-Unite/NotificationDaemon.cs +++ b/Project-Unite/NotificationDaemon.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; +using Microsoft.AspNet.Identity.Owin; using Microsoft.AspNet.SignalR; using Project_Unite.Models; @@ -70,18 +71,40 @@ namespace Project_Unite var user = db.Users.FirstOrDefault(x => x.Id == uid); if (user == null) throw new Exception("Cannot find user with ID " + target + "."); + string id = Guid.NewGuid().ToString(); var note = new Notification { - Id = Guid.NewGuid().ToString(), + Id = id, UserId = target, Title = title, Timestamp = DateTime.Now, - ActionUrl = url, + ActionUrl = $"http://getshiftos.ml/Manage/Notification/{id}?url={Uri.EscapeDataString(url)}", Description = desc, AvatarUrl = user.AvatarUrl }; db.Notifications.Add(note); + var t = db.Users.FirstOrDefault(x => x.Id == target); + if (t.EmailOnNotifications) + { + if (t.LastLogin <= DateTime.Now.AddDays(-7)) + { + var man = HttpContext.Current.GetOwinContext().GetUserManager(); + man.SendEmailAsync(target, "New notification", $@"

New notification

+ +

{note.Title}

+ + +

{user.FullName}

+
{user.DisplayName}
+ +

{note.Description}

+ +Click here to acknowledge this notification."); + + } + } + db.SaveChanges(); SendMessage(target, ComposeHtml(note)); diff --git a/Project-Unite/Views/Manage/Index.cshtml b/Project-Unite/Views/Manage/Index.cshtml index 9aab632..198180f 100644 --- a/Project-Unite/Views/Manage/Index.cshtml +++ b/Project-Unite/Views/Manage/Index.cshtml @@ -30,7 +30,8 @@ @@ -86,6 +87,14 @@ @Html.TextAreaFor(Model => Model.Hobbies, new { @class = "form-control" }) + +
+

Notifications

+

These settings are for the ShiftOS notification system on your account.

+ +

Send me notifications through email when I'm inactive

+

Check this option to allow us to email you when you receive a notification and you haven't logged in for a week.

@Html.CheckBoxFor(Model=>Model.EmailOnNotifications) +

Privacy & Security