more small tweaks around the username/alias

This commit is contained in:
Jamie.Rees 2017-01-25 12:03:55 +00:00
parent 9f7523d7c5
commit 3d2209d163
6 changed files with 23 additions and 7 deletions

View file

@ -114,9 +114,13 @@ namespace Ombi.Core
} }
// could be a local user // could be a local user
var localName = session[SessionKeys.UsernameKey]; var hasSessionKey = session[SessionKeys.UsernameKey] != null;
if (hasSessionKey)
{
return (string)session[SessionKeys.UsernameKey];
}
return localName as string; return string.Empty;
} }

View file

@ -25,6 +25,7 @@
// ************************************************************************/ // ************************************************************************/
#endregion #endregion
using Newtonsoft.Json;
using Ombi.Helpers; using Ombi.Helpers;
using Ombi.Helpers.Permissions; using Ombi.Helpers.Permissions;
@ -38,5 +39,8 @@ namespace Ombi.Core.Users
public Features Features { get; set; } public Features Features { get; set; }
public string EmailAddress { get; set; } public string EmailAddress { get; set; }
public UserType Type { get; set; } public UserType Type { get; set; }
[JsonIgnore]
public string UsernameOrAlias => string.IsNullOrEmpty(UserAlias) ? Username : UserAlias;
} }
} }

View file

@ -152,10 +152,16 @@ namespace Ombi.Services.Notification
var users = UserHelper.GetUsersWithFeature(Features.RequestAddedNotification).ToList(); var users = UserHelper.GetUsersWithFeature(Features.RequestAddedNotification).ToList();
Log.Debug("Notifying Users Count {0}", users.Count); Log.Debug("Notifying Users Count {0}", users.Count);
var userNamesWithFeature = users.Select(x => x.Username).ToList(); // Get the usernames or alias depending if they have an alias
var userNamesWithFeature = users.Select(x => x.UsernameOrAlias).ToList();
var usersToNotify = userNamesWithFeature.Intersect(model.AllUsers, StringComparer.CurrentCultureIgnoreCase).ToList();
if (!usersToNotify.Any())
{
Log.Debug("Could not find any users after the .Intersect()");
}
var usersToNotify = userNamesWithFeature.Intersect(model.AllUsers, StringComparer.CurrentCultureIgnoreCase);
Log.Debug("Users being notified for this request count {0}", users.Count); Log.Debug("Users being notified for this request count {0}", users.Count);
foreach (var user in usersToNotify) foreach (var user in usersToNotify)
{ {

View file

@ -26,6 +26,7 @@
#endregion #endregion
using Dapper.Contrib.Extensions; using Dapper.Contrib.Extensions;
using Newtonsoft.Json;
namespace Ombi.Store.Models namespace Ombi.Store.Models
{ {

View file

@ -149,9 +149,10 @@ namespace Ombi.UI.Modules
protected bool LoggedIn => Context?.CurrentUser != null; protected bool LoggedIn => Context?.CurrentUser != null;
protected string Culture { get; set; } private string Culture { get; set; }
protected const string CultureCookieName = "_culture"; protected const string CultureCookieName = "_culture";
protected Response SetCookie()
private Response SetCookie()
{ {
try try
{ {

View file

@ -564,7 +564,7 @@ namespace Ombi.UI.Modules
UserLogins.Insert(new UserLogins { UserId = userId, Type = UserType.PlexUser, LastLoggedIn = DateTime.UtcNow }); UserLogins.Insert(new UserLogins { UserId = userId, Type = UserType.PlexUser, LastLoggedIn = DateTime.UtcNow });
Log.Debug("We are authenticated! Setting session."); Log.Debug("We are authenticated! Setting session.");
// Add to the session (Used in the BaseModules) // Add to the session (Used in the BaseModules)
Session[SessionKeys.UsernameKey] = (string)username; Session[SessionKeys.UsernameKey] = username;
Session[SessionKeys.ClientDateTimeOffsetKey] = dateTimeOffset; Session[SessionKeys.ClientDateTimeOffsetKey] = dateTimeOffset;
var plexLocal = plexLocalUsers.FirstOrDefault(x => x.Username == username); var plexLocal = plexLocalUsers.FirstOrDefault(x => x.Username == username);