diff --git a/PlexRequests.Api.Interfaces/IPlexApi.cs b/PlexRequests.Api.Interfaces/IPlexApi.cs
index 473bf3237..e0c8029e6 100644
--- a/PlexRequests.Api.Interfaces/IPlexApi.cs
+++ b/PlexRequests.Api.Interfaces/IPlexApi.cs
@@ -37,6 +37,6 @@ public interface IPlexApi
PlexFriends GetUsers(string authToken);
PlexSearch SearchContent(string authToken, string searchTerm, Uri plexFullHost);
PlexStatus GetStatus(string authToken, Uri uri);
-
+ PlexAccount GetAccount(string authToken);
}
}
\ No newline at end of file
diff --git a/PlexRequests.Api.Models/Plex/PlexAccount.cs b/PlexRequests.Api.Models/Plex/PlexAccount.cs
new file mode 100644
index 000000000..be1fbef24
--- /dev/null
+++ b/PlexRequests.Api.Models/Plex/PlexAccount.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Serialization;
+
+namespace PlexRequests.Api.Models.Plex
+{
+ [XmlRoot(ElementName = "user")]
+ public class PlexAccount
+ {
+ [XmlAttribute(AttributeName = "id")]
+ public string Id { get; set; }
+ [XmlAttribute(AttributeName = "username")]
+ public string Username { get; set; }
+ [XmlAttribute(AttributeName = "email")]
+ public string Email { get; set; }
+ [XmlAttribute(AttributeName = "authenticationToken")]
+ public string AuthToken { get; set; }
+ }
+}
diff --git a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj
index 402cdd22a..8a4d30e62 100644
--- a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj
+++ b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj
@@ -49,6 +49,7 @@
+
diff --git a/PlexRequests.Api/PlexApi.cs b/PlexRequests.Api/PlexApi.cs
index 2308910b7..0c6e2a373 100644
--- a/PlexRequests.Api/PlexApi.cs
+++ b/PlexRequests.Api/PlexApi.cs
@@ -134,6 +134,25 @@ public PlexStatus GetStatus(string authToken, Uri uri)
return users;
}
+
+ public PlexAccount GetAccount(string authToken)
+ {
+ var request = new RestRequest
+ {
+ Method = Method.GET,
+ };
+
+ request.AddHeader("X-Plex-Client-Identifier", "Test213");
+ request.AddHeader("X-Plex-Product", "Request Plex");
+ request.AddHeader("X-Plex-Version", Version);
+ request.AddHeader("X-Plex-Token", authToken);
+ request.AddHeader("Content-Type", "application/xml");
+
+ var api = new ApiRequest();
+ var account = api.ExecuteXml(request, new Uri("https://plex.tv/users/account"));
+
+ return account;
+ }
}
}
diff --git a/PlexRequests.Store/SqlTables.sql b/PlexRequests.Store/SqlTables.sql
index d696da6b4..a6e696fba 100644
--- a/PlexRequests.Store/SqlTables.sql
+++ b/PlexRequests.Store/SqlTables.sql
@@ -35,4 +35,25 @@ CREATE TABLE IF NOT EXISTS Log
Message varchar(100) NOT NULL,
CallSite varchar(100) NOT NULL,
Exception varchar(100) NOT NULL
+);
+
+CREATE TABLE IF NOT EXISTS Requested
+(
+ Id INTEGER PRIMARY KEY AUTOINCREMENT,
+ Type INTEGER NOT NULL,
+ ProviderId INTEGER NOT NULL,
+ ImdbId varchar(50),
+ Overview varchar(50),
+ Title varchar(50) NOT NULL,
+ PosterPath varchar(50) NOT NULL,
+ ReleaseDate varchar(50) NOT NULL,
+ Status varchar(50) NOT NULL,
+ AdminNote varchar(50),
+ Approved INTEGER NOT NULL,
+ LatestTv INTEGER NOT NULL,
+ RequestedBy varchar(50),
+ RequestedDate varchar(50) NOT NULL,
+ Available INTEGER(50),
+ Issues INTEGER,
+ OtherMessage varchar(50)
);
\ No newline at end of file
diff --git a/PlexRequests.UI/Modules/UserLoginModule.cs b/PlexRequests.UI/Modules/UserLoginModule.cs
index f4901061e..224f86d5e 100644
--- a/PlexRequests.UI/Modules/UserLoginModule.cs
+++ b/PlexRequests.UI/Modules/UserLoginModule.cs
@@ -24,6 +24,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
+
+using System.Collections.Generic;
using System.Linq;
using Nancy;
@@ -98,9 +100,17 @@ private Response LoginUser()
var signedIn = (PlexAuthentication)Api.SignIn(username, password);
if (signedIn.user?.authentication_token != null)
{
- Log.Debug("Correct credentials, checking if the user is in the friends list");
- authenticated = CheckIfUserIsInPlexFriends(username, settings.PlexAuthToken);
- Log.Debug("Friends list result = {0}", authenticated);
+ Log.Debug("Correct credentials, checking if the user is account owner or in the friends list");
+ if (CheckIfUserIsOwner(settings.PlexAuthToken, username))
+ {
+ Log.Debug("User is the account owner");
+ authenticated = true;
+ }
+ else
+ {
+ authenticated = CheckIfUserIsInPlexFriends(username, settings.PlexAuthToken);
+ Log.Debug("Friends list result = {0}", authenticated);
+ }
}
}
else if(settings.UserAuthentication) // Check against the users in Plex
@@ -127,6 +137,8 @@ private Response LoginUser()
: new JsonResponseModel { Result = false, Message = "Incorrect User or Password"});
}
+
+
private Response Logout()
{
Log.Debug("Logging Out");
@@ -137,6 +149,12 @@ private Response Logout()
return Context.GetRedirect("~/userlogin");
}
+ private bool CheckIfUserIsOwner(string authToken, string userName)
+ {
+ var userAccount = Api.GetAccount(authToken);
+ return userAccount.Username == userName;
+ }
+
private bool CheckIfUserIsInPlexFriends(string username, string authToken)
{
var users = Api.GetUsers(authToken);