mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-10 07:22:35 -07:00
This fixes #36
This commit is contained in:
parent
c5db1ed8e6
commit
792bbf5f95
3 changed files with 122 additions and 27 deletions
|
@ -25,6 +25,7 @@
|
|||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
|
@ -101,7 +102,7 @@ namespace PlexRequests.UI.Modules
|
|||
if (signedIn.user?.authentication_token != null)
|
||||
{
|
||||
Log.Debug("Correct credentials, checking if the user is account owner or in the friends list");
|
||||
if (CheckIfUserIsOwner(settings.PlexAuthToken, username))
|
||||
if (CheckIfUserIsOwner(settings.PlexAuthToken, signedIn.user?.username))
|
||||
{
|
||||
Log.Debug("User is the account owner");
|
||||
authenticated = true;
|
||||
|
@ -117,6 +118,11 @@ namespace PlexRequests.UI.Modules
|
|||
{
|
||||
Log.Debug("Need to auth");
|
||||
authenticated = CheckIfUserIsInPlexFriends(username, settings.PlexAuthToken);
|
||||
if (CheckIfUserIsOwner(settings.PlexAuthToken, username))
|
||||
{
|
||||
Log.Debug("User is the account owner");
|
||||
authenticated = true;
|
||||
}
|
||||
Log.Debug("Friends list result = {0}", authenticated);
|
||||
}
|
||||
else if(!settings.UserAuthentication) // No auth, let them pass!
|
||||
|
@ -152,7 +158,11 @@ namespace PlexRequests.UI.Modules
|
|||
private bool CheckIfUserIsOwner(string authToken, string userName)
|
||||
{
|
||||
var userAccount = Api.GetAccount(authToken);
|
||||
return userAccount.Username == userName;
|
||||
if (userAccount == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return userAccount.Username != null && userAccount.Username.Equals(userName, StringComparison.CurrentCultureIgnoreCase);
|
||||
}
|
||||
|
||||
private bool CheckIfUserIsInPlexFriends(string username, string authToken)
|
||||
|
@ -160,7 +170,8 @@ namespace PlexRequests.UI.Modules
|
|||
var users = Api.GetUsers(authToken);
|
||||
Log.Debug("Plex Users: ");
|
||||
Log.Debug(users.DumpJson());
|
||||
return users.User.Any(x => x.Username == username);
|
||||
var allUsers = users.User?.Where(x => !string.IsNullOrEmpty(x.Username));
|
||||
return allUsers != null && allUsers.Any(x => x.Username.Equals(username, StringComparison.CurrentCultureIgnoreCase));
|
||||
}
|
||||
|
||||
private bool IsUserInDeniedList(string username, AuthenticationSettings settings)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue