Should fix issue #36

This commit is contained in:
Shannon Barrett 2016-03-18 19:16:29 -05:00
parent 613e4c3aa8
commit c28a26413a
6 changed files with 85 additions and 4 deletions

View file

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