From 5c023341b696b441ce687ad0eff7a26245820887 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Fri, 16 Dec 2016 20:31:34 +0000 Subject: [PATCH] Fixed #788 and #791 --- PlexRequests.Core/ISecurityExtensions.cs | 3 ++- PlexRequests.Core/SecurityExtensions.cs | 9 +++++++-- PlexRequests.UI/Modules/BaseModule.cs | 2 +- PlexRequests.UI/Modules/UserLoginModule.cs | 14 ++++++++++++++ PlexRequests.UI/Resources/UI.resx | 5 ++++- PlexRequests.UI/Resources/UI1.Designer.cs | 11 ++++++++++- PlexRequests.UI/Views/Search/Index.cshtml | 5 ----- .../Views/Shared/Partial/_Navbar.cshtml | 11 +++++++++++ 8 files changed, 49 insertions(+), 11 deletions(-) diff --git a/PlexRequests.Core/ISecurityExtensions.cs b/PlexRequests.Core/ISecurityExtensions.cs index 10db3ccfe..25fd68334 100644 --- a/PlexRequests.Core/ISecurityExtensions.cs +++ b/PlexRequests.Core/ISecurityExtensions.cs @@ -1,6 +1,7 @@ using System; using Nancy; using Nancy.Security; +using Nancy.Session; using PlexRequests.Helpers.Permissions; namespace PlexRequests.Core @@ -29,6 +30,6 @@ namespace PlexRequests.Core /// /// The username. /// null if we cannot find a user - string GetUsername(string username); + string GetUsername(string username, ISession session); } } \ No newline at end of file diff --git a/PlexRequests.Core/SecurityExtensions.cs b/PlexRequests.Core/SecurityExtensions.cs index 38972cf22..4a237007e 100644 --- a/PlexRequests.Core/SecurityExtensions.cs +++ b/PlexRequests.Core/SecurityExtensions.cs @@ -30,6 +30,7 @@ using Nancy; using Nancy.Linker; using Nancy.Responses; using Nancy.Security; +using Nancy.Session; using PlexRequests.Core.Models; using PlexRequests.Helpers; using PlexRequests.Helpers.Permissions; @@ -91,7 +92,7 @@ namespace PlexRequests.Core /// /// The username. /// null if we cannot find a user - public string GetUsername(string username) + public string GetUsername(string username, ISession session) { var plexUser = PlexUsers.GetUserByUsername(username); if (plexUser != null) @@ -119,7 +120,11 @@ namespace PlexRequests.Core return dbUser.UserName; } } - return null; + + // could be a local user + var localName = session[SessionKeys.UsernameKey]; + + return localName as string; } diff --git a/PlexRequests.UI/Modules/BaseModule.cs b/PlexRequests.UI/Modules/BaseModule.cs index 81427c924..477d2d848 100644 --- a/PlexRequests.UI/Modules/BaseModule.cs +++ b/PlexRequests.UI/Modules/BaseModule.cs @@ -112,7 +112,7 @@ namespace PlexRequests.UI.Modules { try { - var username = Security.GetUsername(User.UserName); + var username = Security.GetUsername(User.UserName, Session); if (string.IsNullOrEmpty(username)) { return Session[SessionKeys.UsernameKey].ToString(); diff --git a/PlexRequests.UI/Modules/UserLoginModule.cs b/PlexRequests.UI/Modules/UserLoginModule.cs index a3c8f65e7..1276df045 100644 --- a/PlexRequests.UI/Modules/UserLoginModule.cs +++ b/PlexRequests.UI/Modules/UserLoginModule.cs @@ -228,6 +228,20 @@ namespace PlexRequests.UI.Modules loginGuid = Guid.Parse(dbUser.UserGuid); } + if (loginGuid != Guid.Empty) + { + if (!settings.UserAuthentication)// Do not need to auth make admin use login screen for now TODO remove this + { + var perms = (Permissions)dbUser.Permissions; + if (perms.HasFlag(Permissions.Administrator)) + { + var uri = Linker.BuildRelativeUri(Context, "UserLoginIndex"); + Session["TempMessage"] = Resources.UI.UserLogin_AdminUsePassword; + return Response.AsRedirect(uri.ToString()); + } + } + } + if(loginGuid == Guid.Empty && settings.UserAuthentication) { var defaultSettings = UserManagementSettings.GetSettings(); diff --git a/PlexRequests.UI/Resources/UI.resx b/PlexRequests.UI/Resources/UI.resx index a4433781f..fc5b4be3b 100644 --- a/PlexRequests.UI/Resources/UI.resx +++ b/PlexRequests.UI/Resources/UI.resx @@ -473,4 +473,7 @@ User Management - + + If you are an administrator, please use the other login page + + \ No newline at end of file diff --git a/PlexRequests.UI/Resources/UI1.Designer.cs b/PlexRequests.UI/Resources/UI1.Designer.cs index a5cf28b1f..fa19b86d6 100644 --- a/PlexRequests.UI/Resources/UI1.Designer.cs +++ b/PlexRequests.UI/Resources/UI1.Designer.cs @@ -223,7 +223,7 @@ namespace PlexRequests.UI.Resources { } /// - /// Looks up a localized string similar to A background process is currently running, so there might be some unexpected behavior. This shouldn't take too long.. + /// Looks up a localized string similar to Currently we are indexing all of the available tv shows and movies on the Plex server, so there might be some unexpected behavior. This shouldn't take too long.. /// public static string Layout_CacherRunning { get { @@ -1113,6 +1113,15 @@ namespace PlexRequests.UI.Resources { } } + /// + /// Looks up a localized string similar to If you are an administrator, please use the other login page. + /// + public static string UserLogin_AdminUsePassword { + get { + return ResourceManager.GetString("UserLogin_AdminUsePassword", resourceCulture); + } + } + /// /// Looks up a localized string similar to Incorrect User or Password. /// diff --git a/PlexRequests.UI/Views/Search/Index.cshtml b/PlexRequests.UI/Views/Search/Index.cshtml index 64446a264..b565ba234 100644 --- a/PlexRequests.UI/Views/Search/Index.cshtml +++ b/PlexRequests.UI/Views/Search/Index.cshtml @@ -37,11 +37,6 @@ } - - diff --git a/PlexRequests.UI/Views/Shared/Partial/_Navbar.cshtml b/PlexRequests.UI/Views/Shared/Partial/_Navbar.cshtml index 17149fc90..f94fa0881 100644 --- a/PlexRequests.UI/Views/Shared/Partial/_Navbar.cshtml +++ b/PlexRequests.UI/Views/Shared/Partial/_Navbar.cshtml @@ -93,6 +93,17 @@ } + else if (Html.IsLoggedIn(Context)) // Logged in but not admin + { + + + } +