diff options
| -rw-r--r-- | Project-Unite/Controllers/ManageController.cs | 14 | ||||
| -rw-r--r-- | Project-Unite/Models/IdentityModels.cs | 2 | ||||
| -rw-r--r-- | Project-Unite/NotificationDaemon.cs | 27 | ||||
| -rw-r--r-- | 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<ApplicationUserManager>(); + man.SendEmailAsync(target, "New notification", $@"<h1>New notification</h1> + +<h3>{note.Title}</h3> + +<img src=""{note.AvatarUrl}"" width=""128"" height=""128"" style=""border-radius:100%""/> +<h4>{user.FullName}</h4> +<h5>{user.DisplayName}</h5> + +<p>{note.Description}</p> + +<a href=""{note.ActionUrl}"">Click here to acknowledge this notification.</a>"); + + } + } + 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 @@ <ul id="tabs" data-tabs="tabs" class="nav nav-pills nav-stacked" role="tablist"> <li class="active"><a data-toggle="tab" href="#t_profile">Profile</a></li> <li><a data-toggle="tab" href="#t_privacy">Privacy & Security</a></li> - <li><a data-toggle="tab" href="#t_data">Data</a></li> + <li><a data-toggle="tab" href="#t_notifications">Notifications</a></li> + <li><a data-toggle="tab" href="#t_data">Data</a></li> <li><a data-toggle="tab" href="#t_api">API</a></li> <li class="danger"><a data-toggle="tab" href="#t_danger">The Danger Zone</a></li> </ul> @@ -87,6 +88,14 @@ </div> + <div class="tab-pane fade in" id="t_notifications"> + <h2>Notifications</h2> + <p>These settings are for the ShiftOS notification system on your account.</p> + + <h4>Send me notifications through email when I'm inactive</h4> + <p>Check this option to allow us to email you when you receive a notification and you haven't logged in for a week.</p> @Html.CheckBoxFor(Model=>Model.EmailOnNotifications) + + </div> <div class="tab-pane fade in" id="t_privacy"> <h2>Privacy & Security</h2> |
