-
-
Notifications
You must be signed in to change notification settings - Fork 401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dev #39
Merged
Merged
Dev #39
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also need to check if it's an owner in this case, where we don't have the password enabled but we do want to authenticate |
||
|
@@ -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); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we take this out please :)