mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-12 08:16:05 -07:00
Refactoring
This commit is contained in:
parent
8b3f35edbb
commit
f7a6614748
1 changed files with 12 additions and 16 deletions
|
@ -37,10 +37,7 @@ using PlexRequests.UI.Models;
|
||||||
|
|
||||||
namespace PlexRequests.UI.Modules
|
namespace PlexRequests.UI.Modules
|
||||||
{
|
{
|
||||||
// TODO: Check the settings to see if we need to authenticate
|
|
||||||
// TODO: Add ability to logout
|
// TODO: Add ability to logout
|
||||||
// TODO: If we need to authenticate we need to check if they are in Plex
|
|
||||||
// TODO: Allow the user of a username only or a Username and password
|
|
||||||
public class UserLoginModule : NancyModule
|
public class UserLoginModule : NancyModule
|
||||||
{
|
{
|
||||||
public UserLoginModule(ISettingsService<AuthenticationSettings> auth) : base("userlogin")
|
public UserLoginModule(ISettingsService<AuthenticationSettings> auth) : base("userlogin")
|
||||||
|
@ -72,36 +69,35 @@ namespace PlexRequests.UI.Modules
|
||||||
|
|
||||||
if (settings.UserAuthentication && settings.UsePassword) // Authenticate with Plex
|
if (settings.UserAuthentication && settings.UsePassword) // Authenticate with Plex
|
||||||
{
|
{
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
var users = api.GetUsers(settings.PlexAuthToken);
|
authenticated = CheckIfUserIsInPlexFriends(username, settings.PlexAuthToken);
|
||||||
if (users.User.Any(x => x.Username == username))
|
|
||||||
{
|
|
||||||
authenticated = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(settings.UserAuthentication) // Check against the users in Plex
|
else if(settings.UserAuthentication) // Check against the users in Plex
|
||||||
{
|
{
|
||||||
var users = api.GetUsers(settings.PlexAuthToken);
|
authenticated = CheckIfUserIsInPlexFriends(username, settings.PlexAuthToken);
|
||||||
if (users.User.Any(x => x.Username == username))
|
|
||||||
{
|
|
||||||
authenticated = true;
|
|
||||||
}
|
}
|
||||||
}
|
else if(!settings.UserAuthentication) // No auth, let them pass!
|
||||||
else if(!settings.UserAuthentication)
|
|
||||||
{
|
{
|
||||||
authenticated = true;
|
authenticated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Add to the session
|
// Add to the session (Used in the BaseModules)
|
||||||
Session[SessionKeys.UsernameKey] = (string)username;
|
Session[SessionKeys.UsernameKey] = (string)username;
|
||||||
|
|
||||||
return Response.AsJson(authenticated
|
return Response.AsJson(authenticated
|
||||||
? new JsonResponseModel { Result = true }
|
? new JsonResponseModel { Result = true }
|
||||||
: new JsonResponseModel { Result = false, Message = "Incorrect User or Password"});
|
: new JsonResponseModel { Result = false, Message = "Incorrect User or Password"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool CheckIfUserIsInPlexFriends(string username, string authToken)
|
||||||
|
{
|
||||||
|
var api = new PlexApi();
|
||||||
|
var users = api.GetUsers(authToken);
|
||||||
|
return users.User.Any(x => x.Username == username);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue