mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-10 23:42:36 -07:00
Should fix issue #36
This commit is contained in:
parent
613e4c3aa8
commit
c28a26413a
6 changed files with 85 additions and 4 deletions
|
@ -37,6 +37,6 @@ namespace PlexRequests.Api.Interfaces
|
||||||
PlexFriends GetUsers(string authToken);
|
PlexFriends GetUsers(string authToken);
|
||||||
PlexSearch SearchContent(string authToken, string searchTerm, Uri plexFullHost);
|
PlexSearch SearchContent(string authToken, string searchTerm, Uri plexFullHost);
|
||||||
PlexStatus GetStatus(string authToken, Uri uri);
|
PlexStatus GetStatus(string authToken, Uri uri);
|
||||||
|
PlexAccount GetAccount(string authToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
22
PlexRequests.Api.Models/Plex/PlexAccount.cs
Normal file
22
PlexRequests.Api.Models/Plex/PlexAccount.cs
Normal file
|
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -49,6 +49,7 @@
|
||||||
<Compile Include="Movie\CouchPotatoStatus.cs" />
|
<Compile Include="Movie\CouchPotatoStatus.cs" />
|
||||||
<Compile Include="Notifications\PushbulletPush.cs" />
|
<Compile Include="Notifications\PushbulletPush.cs" />
|
||||||
<Compile Include="Notifications\PushbulletResponse.cs" />
|
<Compile Include="Notifications\PushbulletResponse.cs" />
|
||||||
|
<Compile Include="Plex\PlexAccount.cs" />
|
||||||
<Compile Include="Plex\PlexAuthentication.cs" />
|
<Compile Include="Plex\PlexAuthentication.cs" />
|
||||||
<Compile Include="Plex\PlexError.cs" />
|
<Compile Include="Plex\PlexError.cs" />
|
||||||
<Compile Include="Plex\PlexFriends.cs" />
|
<Compile Include="Plex\PlexFriends.cs" />
|
||||||
|
|
|
@ -134,6 +134,25 @@ namespace PlexRequests.Api
|
||||||
|
|
||||||
return users;
|
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<PlexAccount>(request, new Uri("https://plex.tv/users/account"));
|
||||||
|
|
||||||
|
return account;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,3 +36,24 @@ CREATE TABLE IF NOT EXISTS Log
|
||||||
CallSite varchar(100) NOT NULL,
|
CallSite varchar(100) NOT NULL,
|
||||||
Exception 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)
|
||||||
|
);
|
|
@ -24,6 +24,8 @@
|
||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// ************************************************************************/
|
// ************************************************************************/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using Nancy;
|
using Nancy;
|
||||||
|
@ -98,11 +100,19 @@ namespace PlexRequests.UI.Modules
|
||||||
var signedIn = (PlexAuthentication)Api.SignIn(username, password);
|
var signedIn = (PlexAuthentication)Api.SignIn(username, password);
|
||||||
if (signedIn.user?.authentication_token != null)
|
if (signedIn.user?.authentication_token != null)
|
||||||
{
|
{
|
||||||
Log.Debug("Correct credentials, checking if the user is in the friends list");
|
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);
|
authenticated = CheckIfUserIsInPlexFriends(username, settings.PlexAuthToken);
|
||||||
Log.Debug("Friends list result = {0}", authenticated);
|
Log.Debug("Friends list result = {0}", authenticated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if(settings.UserAuthentication) // Check against the users in Plex
|
else if(settings.UserAuthentication) // Check against the users in Plex
|
||||||
{
|
{
|
||||||
Log.Debug("Need to auth");
|
Log.Debug("Need to auth");
|
||||||
|
@ -127,6 +137,8 @@ namespace PlexRequests.UI.Modules
|
||||||
: new JsonResponseModel { Result = false, Message = "Incorrect User or Password"});
|
: new JsonResponseModel { Result = false, Message = "Incorrect User or Password"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Response Logout()
|
private Response Logout()
|
||||||
{
|
{
|
||||||
Log.Debug("Logging Out");
|
Log.Debug("Logging Out");
|
||||||
|
@ -137,6 +149,12 @@ namespace PlexRequests.UI.Modules
|
||||||
return Context.GetRedirect("~/userlogin");
|
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)
|
private bool CheckIfUserIsInPlexFriends(string username, string authToken)
|
||||||
{
|
{
|
||||||
var users = Api.GetUsers(authToken);
|
var users = Api.GetUsers(authToken);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue