Should fix issue #36

pull/39/head
Shannon Barrett 9 years ago
parent 613e4c3aa8
commit c28a26413a

@ -37,6 +37,6 @@ namespace PlexRequests.Api.Interfaces
PlexFriends GetUsers(string authToken);
PlexSearch SearchContent(string authToken, string searchTerm, Uri plexFullHost);
PlexStatus GetStatus(string authToken, Uri uri);
PlexAccount GetAccount(string authToken);
}
}

@ -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="Notifications\PushbulletPush.cs" />
<Compile Include="Notifications\PushbulletResponse.cs" />
<Compile Include="Plex\PlexAccount.cs" />
<Compile Include="Plex\PlexAuthentication.cs" />
<Compile Include="Plex\PlexError.cs" />
<Compile Include="Plex\PlexFriends.cs" />

@ -134,6 +134,25 @@ namespace PlexRequests.Api
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;
}
}
}

@ -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)
);

@ -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 @@ namespace PlexRequests.UI.Modules
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 @@ namespace PlexRequests.UI.Modules
: new JsonResponseModel { Result = false, Message = "Incorrect User or Password"});
}
private Response Logout()
{
Log.Debug("Logging Out");
@ -137,6 +149,12 @@ namespace PlexRequests.UI.Modules
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);

Loading…
Cancel
Save