mirror of
https://github.com/lempamo/Project-Unite.git
synced 2025-01-22 11:21:47 -05:00
More notification updates
This commit is contained in:
parent
0571a9c8d9
commit
1d8b307bb5
4 changed files with 49 additions and 5 deletions
|
@ -111,6 +111,17 @@ private set
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
public ApplicationUserManager UserManager
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -157,6 +168,7 @@ public ActionResult Index(ApplicationUser model)
|
||||||
usr.ShowFollowers = model.ShowFollowers;
|
usr.ShowFollowers = model.ShowFollowers;
|
||||||
usr.ShowFollowed = model.ShowFollowed;
|
usr.ShowFollowed = model.ShowFollowed;
|
||||||
usr.ShowEmail = model.ShowEmail;
|
usr.ShowEmail = model.ShowEmail;
|
||||||
|
usr.EmailOnNotifications = model.EmailOnNotifications;
|
||||||
usr.ShowPostAndTopicCounts = model.ShowPostAndTopicCounts;
|
usr.ShowPostAndTopicCounts = model.ShowPostAndTopicCounts;
|
||||||
usr.ShowJoinDate = model.ShowJoinDate;
|
usr.ShowJoinDate = model.ShowJoinDate;
|
||||||
if (usr.Email != model.Email)
|
if (usr.Email != model.Email)
|
||||||
|
@ -510,7 +522,7 @@ protected override void Dispose(bool disposing)
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Helpers
|
#region Helpers
|
||||||
// Used for XSRF protection when adding external logins
|
// Used for XSRF protection when adding external logins
|
||||||
private const string XsrfKey = "XsrfId";
|
private const string XsrfKey = "XsrfId";
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<Applicat
|
||||||
public bool ShowEmail { get; set; }
|
public bool ShowEmail { get; set; }
|
||||||
public bool ShowPostAndTopicCounts { get; set; }
|
public bool ShowPostAndTopicCounts { get; set; }
|
||||||
public bool ShowJoinDate { get; set; }
|
public bool ShowJoinDate { get; set; }
|
||||||
|
public bool EmailOnNotifications { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
|
using Microsoft.AspNet.Identity.Owin;
|
||||||
using Microsoft.AspNet.SignalR;
|
using Microsoft.AspNet.SignalR;
|
||||||
using Project_Unite.Models;
|
using Project_Unite.Models;
|
||||||
|
|
||||||
|
@ -70,18 +71,40 @@ public static void NotifyUser(string uid, string target, string title, string de
|
||||||
var user = db.Users.FirstOrDefault(x => x.Id == uid);
|
var user = db.Users.FirstOrDefault(x => x.Id == uid);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
throw new Exception("Cannot find user with ID " + target + ".");
|
throw new Exception("Cannot find user with ID " + target + ".");
|
||||||
|
string id = Guid.NewGuid().ToString();
|
||||||
var note = new Notification
|
var note = new Notification
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid().ToString(),
|
Id = id,
|
||||||
UserId = target,
|
UserId = target,
|
||||||
Title = title,
|
Title = title,
|
||||||
Timestamp = DateTime.Now,
|
Timestamp = DateTime.Now,
|
||||||
ActionUrl = url,
|
ActionUrl = $"http://getshiftos.ml/Manage/Notification/{id}?url={Uri.EscapeDataString(url)}",
|
||||||
Description = desc,
|
Description = desc,
|
||||||
AvatarUrl = user.AvatarUrl
|
AvatarUrl = user.AvatarUrl
|
||||||
};
|
};
|
||||||
db.Notifications.Add(note);
|
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();
|
db.SaveChanges();
|
||||||
|
|
||||||
SendMessage(target, ComposeHtml(note));
|
SendMessage(target, ComposeHtml(note));
|
||||||
|
|
|
@ -30,7 +30,8 @@
|
||||||
<ul id="tabs" data-tabs="tabs" class="nav nav-pills nav-stacked" role="tablist">
|
<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 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_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><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>
|
<li class="danger"><a data-toggle="tab" href="#t_danger">The Danger Zone</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -86,6 +87,14 @@
|
||||||
@Html.TextAreaFor(Model => Model.Hobbies, new { @class = "form-control" })
|
@Html.TextAreaFor(Model => Model.Hobbies, new { @class = "form-control" })
|
||||||
|
|
||||||
|
|
||||||
|
</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>
|
||||||
<div class="tab-pane fade in" id="t_privacy">
|
<div class="tab-pane fade in" id="t_privacy">
|
||||||
<h2>Privacy & Security</h2>
|
<h2>Privacy & Security</h2>
|
||||||
|
|
Loading…
Reference in a new issue