mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-21 05:43:19 -07:00
Moved the plex auth token to the plex settings where it should belong.
This commit is contained in:
parent
ffe6bc41ac
commit
57ec940d5a
18 changed files with 2753 additions and 2837 deletions
|
@ -290,19 +290,19 @@ namespace PlexRequests.UI.Modules
|
|||
return Response.AsJson(new { Result = false, Message = "Incorrect username or password!" });
|
||||
}
|
||||
|
||||
var oldSettings = AuthService.GetSettings();
|
||||
var oldSettings = PlexService.GetSettings();
|
||||
if (oldSettings != null)
|
||||
{
|
||||
oldSettings.PlexAuthToken = model.user.authentication_token;
|
||||
AuthService.SaveSettings(oldSettings);
|
||||
PlexService.SaveSettings(oldSettings);
|
||||
}
|
||||
else
|
||||
{
|
||||
var newModel = new AuthenticationSettings
|
||||
var newModel = new PlexSettings
|
||||
{
|
||||
PlexAuthToken = model.user.authentication_token
|
||||
};
|
||||
AuthService.SaveSettings(newModel);
|
||||
PlexService.SaveSettings(newModel);
|
||||
}
|
||||
|
||||
return Response.AsJson(new { Result = true, AuthToken = model.user.authentication_token });
|
||||
|
@ -311,7 +311,7 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
private Response GetUsers()
|
||||
{
|
||||
var settings = AuthService.GetSettings();
|
||||
var settings = PlexService.GetSettings();
|
||||
|
||||
var token = settings?.PlexAuthToken;
|
||||
if (token == null)
|
||||
|
|
|
@ -1,230 +1,227 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: ApplicationTesterModule.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
using System;
|
||||
|
||||
using Nancy;
|
||||
using Nancy.ModelBinding;
|
||||
using Nancy.Security;
|
||||
using Nancy.Validation;
|
||||
using NLog;
|
||||
|
||||
using PlexRequests.Api.Interfaces;
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
public class ApplicationTesterModule : BaseAuthModule
|
||||
{
|
||||
|
||||
public ApplicationTesterModule(ICouchPotatoApi cpApi, ISonarrApi sonarrApi, IPlexApi plexApi,
|
||||
ISettingsService<AuthenticationSettings> authSettings, ISickRageApi srApi, IHeadphonesApi hpApi, ISettingsService<PlexRequestSettings> pr) : base("test", pr)
|
||||
{
|
||||
this.RequiresAuthentication();
|
||||
|
||||
CpApi = cpApi;
|
||||
SonarrApi = sonarrApi;
|
||||
PlexApi = plexApi;
|
||||
AuthSettings = authSettings;
|
||||
SickRageApi = srApi;
|
||||
HeadphonesApi = hpApi;
|
||||
|
||||
Post["/cp"] = _ => CouchPotatoTest();
|
||||
Post["/sonarr"] = _ => SonarrTest();
|
||||
Post["/plex"] = _ => PlexTest();
|
||||
Post["/sickrage"] = _ => SickRageTest();
|
||||
Post["/headphones"] = _ => HeadphonesTest();
|
||||
|
||||
}
|
||||
|
||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private ISonarrApi SonarrApi { get; }
|
||||
private ICouchPotatoApi CpApi { get; }
|
||||
private IPlexApi PlexApi { get; }
|
||||
private ISickRageApi SickRageApi { get; }
|
||||
private IHeadphonesApi HeadphonesApi { get; }
|
||||
private ISettingsService<AuthenticationSettings> AuthSettings { get; }
|
||||
|
||||
private Response CouchPotatoTest()
|
||||
{
|
||||
var couchPotatoSettings = this.Bind<CouchPotatoSettings>();
|
||||
var valid = this.Validate(couchPotatoSettings);
|
||||
if (!valid.IsValid)
|
||||
{
|
||||
return Response.AsJson(valid.SendJsonError());
|
||||
}
|
||||
try
|
||||
{
|
||||
var status = CpApi.GetStatus(couchPotatoSettings.FullUri, couchPotatoSettings.ApiKey);
|
||||
return status.success
|
||||
? Response.AsJson(new JsonResponseModel { Result = true, Message = "Connected to CouchPotato successfully!" })
|
||||
: Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to CouchPotato, please check your settings." });
|
||||
|
||||
}
|
||||
catch (Exception e) // Exceptions are expected if we cannot connect so we will just log and swallow them.
|
||||
{
|
||||
Log.Warn("Exception thrown when attempting to get CP's status: ");
|
||||
Log.Warn(e);
|
||||
var message = $"Could not connect to CouchPotato, please check your settings. <strong>Exception Message:</strong> {e.Message}";
|
||||
if (e.InnerException != null)
|
||||
{
|
||||
message = $"Could not connect to CouchPotato, please check your settings. <strong>Exception Message:</strong> {e.InnerException.Message}";
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = message });
|
||||
}
|
||||
}
|
||||
|
||||
private Response SonarrTest()
|
||||
{
|
||||
var sonarrSettings = this.Bind<SonarrSettings>();
|
||||
var valid = this.Validate(sonarrSettings);
|
||||
if (!valid.IsValid)
|
||||
{
|
||||
return Response.AsJson(valid.SendJsonError());
|
||||
}
|
||||
try
|
||||
{
|
||||
var status = SonarrApi.SystemStatus(sonarrSettings.ApiKey, sonarrSettings.FullUri);
|
||||
return status?.version != null
|
||||
? Response.AsJson(new JsonResponseModel { Result = true, Message = "Connected to Sonarr successfully!" })
|
||||
: Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to Sonarr, please check your settings." });
|
||||
|
||||
}
|
||||
catch (Exception e) // Exceptions are expected, if we cannot connect so we will just log and swallow them.
|
||||
{
|
||||
Log.Warn("Exception thrown when attempting to get Sonarr's status: ");
|
||||
Log.Warn(e);
|
||||
var message = $"Could not connect to Sonarr, please check your settings. <strong>Exception Message:</strong> {e.Message}";
|
||||
if (e.InnerException != null)
|
||||
{
|
||||
message = $"Could not connect to Sonarr, please check your settings. <strong>Exception Message:</strong> {e.InnerException.Message}";
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = message });
|
||||
}
|
||||
}
|
||||
|
||||
private Response PlexTest()
|
||||
{
|
||||
var plexSettings = this.Bind<PlexSettings>();
|
||||
var valid = this.Validate(plexSettings);
|
||||
if (!valid.IsValid)
|
||||
{
|
||||
return Response.AsJson(valid.SendJsonError());
|
||||
}
|
||||
var settings = AuthSettings.GetSettings();
|
||||
if (settings?.PlexAuthToken == null)
|
||||
{
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Plex is not setup yet, you need to update your Authentication settings" });
|
||||
}
|
||||
try
|
||||
{
|
||||
var status = PlexApi.GetStatus(settings.PlexAuthToken, plexSettings.FullUri);
|
||||
return status != null
|
||||
? Response.AsJson(new JsonResponseModel { Result = true, Message = "Connected to Plex successfully!" })
|
||||
: Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to Plex, please check your settings." });
|
||||
|
||||
}
|
||||
catch (Exception e) // Exceptions are expected, if we cannot connect so we will just log and swallow them.
|
||||
{
|
||||
Log.Warn("Exception thrown when attempting to get Plex's status: ");
|
||||
Log.Warn(e);
|
||||
var message = $"Could not connect to Plex, please check your settings. <strong>Exception Message:</strong> {e.Message}";
|
||||
if (e.InnerException != null)
|
||||
{
|
||||
message = $"Could not connect to Plex, please check your settings. <strong>Exception Message:</strong> {e.InnerException.Message}";
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = message });
|
||||
}
|
||||
}
|
||||
|
||||
private Response SickRageTest()
|
||||
{
|
||||
var sickRageSettings = this.Bind<SickRageSettings>();
|
||||
var valid = this.Validate(sickRageSettings);
|
||||
if (!valid.IsValid)
|
||||
{
|
||||
return Response.AsJson(valid.SendJsonError());
|
||||
}
|
||||
try
|
||||
{
|
||||
var status = SickRageApi.Ping(sickRageSettings.ApiKey, sickRageSettings.FullUri);
|
||||
return status?.result == "success"
|
||||
? Response.AsJson(new JsonResponseModel { Result = true, Message = "Connected to SickRage successfully!" })
|
||||
: Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to SickRage, please check your settings." });
|
||||
|
||||
}
|
||||
catch (Exception e) // Exceptions are expected, if we cannot connect so we will just log and swallow them.
|
||||
{
|
||||
Log.Warn("Exception thrown when attempting to get SickRage's status: ");
|
||||
Log.Warn(e);
|
||||
var message = $"Could not connect to SickRage, please check your settings. <strong>Exception Message:</strong> {e.Message}";
|
||||
if (e.InnerException != null)
|
||||
{
|
||||
message = $"Could not connect to SickRage, please check your settings. <strong>Exception Message:</strong> {e.InnerException.Message}";
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = message });
|
||||
}
|
||||
}
|
||||
|
||||
private Response HeadphonesTest()
|
||||
{
|
||||
var settings = this.Bind<HeadphonesSettings>();
|
||||
var valid = this.Validate(settings);
|
||||
if (!valid.IsValid)
|
||||
{
|
||||
return Response.AsJson(valid.SendJsonError());
|
||||
}
|
||||
try
|
||||
{
|
||||
var result = HeadphonesApi.GetVersion(settings.ApiKey, settings.FullUri);
|
||||
if (!string.IsNullOrEmpty(result.latest_version))
|
||||
{
|
||||
return
|
||||
Response.AsJson(new JsonResponseModel
|
||||
{
|
||||
Result = true,
|
||||
Message = "Connected to Headphones successfully!"
|
||||
});
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to Headphones, please check your settings." });
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Warn("Exception thrown when attempting to get Headphones's status: ");
|
||||
Log.Warn(e);
|
||||
var message = $"Could not connect to Headphones, please check your settings. <strong>Exception Message:</strong> {e.Message}";
|
||||
if (e.InnerException != null)
|
||||
{
|
||||
message = $"Could not connect to Headphones, please check your settings. <strong>Exception Message:</strong> {e.InnerException.Message}";
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = message }); ;
|
||||
}
|
||||
}
|
||||
}
|
||||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: ApplicationTesterModule.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
using System;
|
||||
|
||||
using Nancy;
|
||||
using Nancy.ModelBinding;
|
||||
using Nancy.Security;
|
||||
using Nancy.Validation;
|
||||
using NLog;
|
||||
|
||||
using PlexRequests.Api.Interfaces;
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.UI.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
public class ApplicationTesterModule : BaseAuthModule
|
||||
{
|
||||
|
||||
public ApplicationTesterModule(ICouchPotatoApi cpApi, ISonarrApi sonarrApi, IPlexApi plexApi,
|
||||
ISickRageApi srApi, IHeadphonesApi hpApi, ISettingsService<PlexRequestSettings> pr) : base("test", pr)
|
||||
{
|
||||
this.RequiresAuthentication();
|
||||
|
||||
CpApi = cpApi;
|
||||
SonarrApi = sonarrApi;
|
||||
PlexApi = plexApi;
|
||||
SickRageApi = srApi;
|
||||
HeadphonesApi = hpApi;
|
||||
|
||||
Post["/cp"] = _ => CouchPotatoTest();
|
||||
Post["/sonarr"] = _ => SonarrTest();
|
||||
Post["/plex"] = _ => PlexTest();
|
||||
Post["/sickrage"] = _ => SickRageTest();
|
||||
Post["/headphones"] = _ => HeadphonesTest();
|
||||
|
||||
}
|
||||
|
||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private ISonarrApi SonarrApi { get; }
|
||||
private ICouchPotatoApi CpApi { get; }
|
||||
private IPlexApi PlexApi { get; }
|
||||
private ISickRageApi SickRageApi { get; }
|
||||
private IHeadphonesApi HeadphonesApi { get; }
|
||||
|
||||
private Response CouchPotatoTest()
|
||||
{
|
||||
var couchPotatoSettings = this.Bind<CouchPotatoSettings>();
|
||||
var valid = this.Validate(couchPotatoSettings);
|
||||
if (!valid.IsValid)
|
||||
{
|
||||
return Response.AsJson(valid.SendJsonError());
|
||||
}
|
||||
try
|
||||
{
|
||||
var status = CpApi.GetStatus(couchPotatoSettings.FullUri, couchPotatoSettings.ApiKey);
|
||||
return status.success
|
||||
? Response.AsJson(new JsonResponseModel { Result = true, Message = "Connected to CouchPotato successfully!" })
|
||||
: Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to CouchPotato, please check your settings." });
|
||||
|
||||
}
|
||||
catch (Exception e) // Exceptions are expected if we cannot connect so we will just log and swallow them.
|
||||
{
|
||||
Log.Warn("Exception thrown when attempting to get CP's status: ");
|
||||
Log.Warn(e);
|
||||
var message = $"Could not connect to CouchPotato, please check your settings. <strong>Exception Message:</strong> {e.Message}";
|
||||
if (e.InnerException != null)
|
||||
{
|
||||
message = $"Could not connect to CouchPotato, please check your settings. <strong>Exception Message:</strong> {e.InnerException.Message}";
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = message });
|
||||
}
|
||||
}
|
||||
|
||||
private Response SonarrTest()
|
||||
{
|
||||
var sonarrSettings = this.Bind<SonarrSettings>();
|
||||
var valid = this.Validate(sonarrSettings);
|
||||
if (!valid.IsValid)
|
||||
{
|
||||
return Response.AsJson(valid.SendJsonError());
|
||||
}
|
||||
try
|
||||
{
|
||||
var status = SonarrApi.SystemStatus(sonarrSettings.ApiKey, sonarrSettings.FullUri);
|
||||
return status?.version != null
|
||||
? Response.AsJson(new JsonResponseModel { Result = true, Message = "Connected to Sonarr successfully!" })
|
||||
: Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to Sonarr, please check your settings." });
|
||||
|
||||
}
|
||||
catch (Exception e) // Exceptions are expected, if we cannot connect so we will just log and swallow them.
|
||||
{
|
||||
Log.Warn("Exception thrown when attempting to get Sonarr's status: ");
|
||||
Log.Warn(e);
|
||||
var message = $"Could not connect to Sonarr, please check your settings. <strong>Exception Message:</strong> {e.Message}";
|
||||
if (e.InnerException != null)
|
||||
{
|
||||
message = $"Could not connect to Sonarr, please check your settings. <strong>Exception Message:</strong> {e.InnerException.Message}";
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = message });
|
||||
}
|
||||
}
|
||||
|
||||
private Response PlexTest()
|
||||
{
|
||||
var plexSettings = this.Bind<PlexSettings>();
|
||||
var valid = this.Validate(plexSettings);
|
||||
if (!valid.IsValid)
|
||||
{
|
||||
return Response.AsJson(valid.SendJsonError());
|
||||
}
|
||||
if (plexSettings?.PlexAuthToken == null)
|
||||
{
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Plex is not setup yet, you need to update your Authentication settings" });
|
||||
}
|
||||
try
|
||||
{
|
||||
var status = PlexApi.GetStatus(plexSettings.PlexAuthToken, plexSettings.FullUri);
|
||||
return status != null
|
||||
? Response.AsJson(new JsonResponseModel { Result = true, Message = "Connected to Plex successfully!" })
|
||||
: Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to Plex, please check your settings." });
|
||||
|
||||
}
|
||||
catch (Exception e) // Exceptions are expected, if we cannot connect so we will just log and swallow them.
|
||||
{
|
||||
Log.Warn("Exception thrown when attempting to get Plex's status: ");
|
||||
Log.Warn(e);
|
||||
var message = $"Could not connect to Plex, please check your settings. <strong>Exception Message:</strong> {e.Message}";
|
||||
if (e.InnerException != null)
|
||||
{
|
||||
message = $"Could not connect to Plex, please check your settings. <strong>Exception Message:</strong> {e.InnerException.Message}";
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = message });
|
||||
}
|
||||
}
|
||||
|
||||
private Response SickRageTest()
|
||||
{
|
||||
var sickRageSettings = this.Bind<SickRageSettings>();
|
||||
var valid = this.Validate(sickRageSettings);
|
||||
if (!valid.IsValid)
|
||||
{
|
||||
return Response.AsJson(valid.SendJsonError());
|
||||
}
|
||||
try
|
||||
{
|
||||
var status = SickRageApi.Ping(sickRageSettings.ApiKey, sickRageSettings.FullUri);
|
||||
return status?.result == "success"
|
||||
? Response.AsJson(new JsonResponseModel { Result = true, Message = "Connected to SickRage successfully!" })
|
||||
: Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to SickRage, please check your settings." });
|
||||
|
||||
}
|
||||
catch (Exception e) // Exceptions are expected, if we cannot connect so we will just log and swallow them.
|
||||
{
|
||||
Log.Warn("Exception thrown when attempting to get SickRage's status: ");
|
||||
Log.Warn(e);
|
||||
var message = $"Could not connect to SickRage, please check your settings. <strong>Exception Message:</strong> {e.Message}";
|
||||
if (e.InnerException != null)
|
||||
{
|
||||
message = $"Could not connect to SickRage, please check your settings. <strong>Exception Message:</strong> {e.InnerException.Message}";
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = message });
|
||||
}
|
||||
}
|
||||
|
||||
private Response HeadphonesTest()
|
||||
{
|
||||
var settings = this.Bind<HeadphonesSettings>();
|
||||
var valid = this.Validate(settings);
|
||||
if (!valid.IsValid)
|
||||
{
|
||||
return Response.AsJson(valid.SendJsonError());
|
||||
}
|
||||
try
|
||||
{
|
||||
var result = HeadphonesApi.GetVersion(settings.ApiKey, settings.FullUri);
|
||||
if (!string.IsNullOrEmpty(result.latest_version))
|
||||
{
|
||||
return
|
||||
Response.AsJson(new JsonResponseModel
|
||||
{
|
||||
Result = true,
|
||||
Message = "Connected to Headphones successfully!"
|
||||
});
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to Headphones, please check your settings." });
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Warn("Exception thrown when attempting to get Headphones's status: ");
|
||||
Log.Warn(e);
|
||||
var message = $"Could not connect to Headphones, please check your settings. <strong>Exception Message:</strong> {e.Message}";
|
||||
if (e.InnerException != null)
|
||||
{
|
||||
message = $"Could not connect to Headphones, please check your settings. <strong>Exception Message:</strong> {e.InnerException.Message}";
|
||||
}
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = message }); ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,7 +29,6 @@ using System.Threading.Tasks;
|
|||
|
||||
using Nancy;
|
||||
using Nancy.Linker;
|
||||
using Nancy.Responses.Negotiation;
|
||||
|
||||
using PlexRequests.Api.Interfaces;
|
||||
using PlexRequests.Core;
|
||||
|
@ -41,12 +40,11 @@ namespace PlexRequests.UI.Modules
|
|||
public class LandingPageModule : BaseModule
|
||||
{
|
||||
public LandingPageModule(ISettingsService<PlexRequestSettings> settingsService, ISettingsService<LandingPageSettings> landing,
|
||||
ISettingsService<PlexSettings> ps, IPlexApi pApi, ISettingsService<AuthenticationSettings> auth, IResourceLinker linker) : base("landing", settingsService)
|
||||
ISettingsService<PlexSettings> ps, IPlexApi pApi, IResourceLinker linker) : base("landing", settingsService)
|
||||
{
|
||||
LandingSettings = landing;
|
||||
PlexSettings = ps;
|
||||
PlexApi = pApi;
|
||||
AuthSettings = auth;
|
||||
Linker = linker;
|
||||
|
||||
Get["LandingPageIndex","/", true] = async (x, ct) =>
|
||||
|
@ -77,21 +75,19 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
private ISettingsService<LandingPageSettings> LandingSettings { get; }
|
||||
private ISettingsService<PlexSettings> PlexSettings { get; }
|
||||
private ISettingsService<AuthenticationSettings> AuthSettings { get; }
|
||||
private IPlexApi PlexApi { get; }
|
||||
private IResourceLinker Linker { get; }
|
||||
|
||||
private async Task<Response> CheckStatus()
|
||||
{
|
||||
var auth = await AuthSettings.GetSettingsAsync();
|
||||
var plexSettings = await PlexSettings.GetSettingsAsync();
|
||||
if (string.IsNullOrEmpty(auth.PlexAuthToken) || string.IsNullOrEmpty(plexSettings.Ip))
|
||||
if (string.IsNullOrEmpty(plexSettings.PlexAuthToken) || string.IsNullOrEmpty(plexSettings.Ip))
|
||||
{
|
||||
return Response.AsJson(false);
|
||||
}
|
||||
try
|
||||
{
|
||||
var status = PlexApi.GetStatus(auth.PlexAuthToken, plexSettings.FullUri);
|
||||
var status = PlexApi.GetStatus(plexSettings.PlexAuthToken, plexSettings.FullUri);
|
||||
return Response.AsJson(status != null);
|
||||
}
|
||||
catch (Exception)
|
||||
|
|
|
@ -1,98 +0,0 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: PlexUsersModule.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Nancy;
|
||||
using Nancy.Responses.Negotiation;
|
||||
|
||||
using PlexRequests.Api.Interfaces;
|
||||
using PlexRequests.Api.Models.Music;
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Store.Models;
|
||||
using PlexRequests.Store.Repository;
|
||||
using PlexRequests.UI.Models;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
public class PlexUsersModule : BaseAuthModule
|
||||
{
|
||||
public PlexUsersModule(ISettingsService<PlexRequestSettings> pr, IPlexApi plexApi, ISettingsService<AuthenticationSettings> auth,
|
||||
IRepository<PlexUsers> repo) : base("plexusers", pr)
|
||||
{
|
||||
PlexApi = plexApi;
|
||||
AuthSettings = auth;
|
||||
Repo = repo;
|
||||
|
||||
Get["/"] = x => Index();
|
||||
Get["/users", true] = async (x, ct) => await GetPlexUsers();
|
||||
|
||||
Post["/alias", true] = async (x, ct) => await Alias();
|
||||
}
|
||||
|
||||
private IPlexApi PlexApi { get; }
|
||||
private ISettingsService<AuthenticationSettings> AuthSettings { get; }
|
||||
private IRepository<PlexUsers> Repo { get; }
|
||||
|
||||
|
||||
private Negotiator Index()
|
||||
{
|
||||
return View["Index"];
|
||||
}
|
||||
|
||||
private async Task<Response> GetPlexUsers()
|
||||
{
|
||||
var authSettings = await AuthSettings.GetSettingsAsync();
|
||||
var users = PlexApi.GetUsers(authSettings.PlexAuthToken);
|
||||
|
||||
return Response.AsJson(users.User);
|
||||
}
|
||||
|
||||
private async Task<Response> Alias()
|
||||
{
|
||||
var plexUserId = (int)Request.Form["plexid"];
|
||||
var alias = (string)Request.Form["alias"];
|
||||
var allUsers = await Repo.GetAllAsync();
|
||||
var existingUser = allUsers.FirstOrDefault(x => x.PlexUserId == plexUserId);
|
||||
if (existingUser == null)
|
||||
{
|
||||
// Create a new mapping
|
||||
existingUser = new PlexUsers { PlexUserId = plexUserId, UserAlias = alias };
|
||||
}
|
||||
else
|
||||
{
|
||||
// Modify existing alias
|
||||
existingUser.UserAlias = alias;
|
||||
}
|
||||
|
||||
await Repo.InsertAsync(existingUser);
|
||||
|
||||
return Response.AsJson(new JsonResponseModel { Result = true });
|
||||
}
|
||||
}
|
||||
}
|
|
@ -49,19 +49,22 @@ namespace PlexRequests.UI.Modules
|
|||
{
|
||||
public class UserLoginModule : BaseModule
|
||||
{
|
||||
public UserLoginModule(ISettingsService<AuthenticationSettings> auth, IPlexApi api, ISettingsService<PlexRequestSettings> pr, ISettingsService<LandingPageSettings> lp, IAnalytics a) : base("userlogin", pr)
|
||||
public UserLoginModule(ISettingsService<AuthenticationSettings> auth, IPlexApi api, ISettingsService<PlexSettings> plexSettings, ISettingsService<PlexRequestSettings> pr, ISettingsService<LandingPageSettings> lp, IAnalytics a) : base("userlogin", pr)
|
||||
{
|
||||
AuthService = auth;
|
||||
LandingPageSettings = lp;
|
||||
Analytics = a;
|
||||
Api = api;
|
||||
PlexSettings = plexSettings;
|
||||
|
||||
Get["UserLoginIndex","/", true] = async (x, ct) => await Index();
|
||||
Post["/"] = x => LoginUser();
|
||||
Post["/", true] = async (x,ct) => await LoginUser();
|
||||
Get["/logout"] = x => Logout();
|
||||
}
|
||||
|
||||
private ISettingsService<AuthenticationSettings> AuthService { get; }
|
||||
private ISettingsService<LandingPageSettings> LandingPageSettings { get; }
|
||||
private ISettingsService<PlexSettings> PlexSettings { get; }
|
||||
private IPlexApi Api { get; }
|
||||
private IAnalytics Analytics { get; }
|
||||
|
||||
|
@ -74,7 +77,7 @@ namespace PlexRequests.UI.Modules
|
|||
return View["Index", settings];
|
||||
}
|
||||
|
||||
private Response LoginUser()
|
||||
private async Task<Response> LoginUser()
|
||||
{
|
||||
var dateTimeOffset = Request.Form.DateTimeOffset;
|
||||
var username = Request.Form.username.Value;
|
||||
|
@ -86,7 +89,8 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
var authenticated = false;
|
||||
|
||||
var settings = AuthService.GetSettings();
|
||||
var settings = await AuthService.GetSettingsAsync();
|
||||
var plexSettings = await PlexSettings.GetSettingsAsync();
|
||||
|
||||
if (IsUserInDeniedList(username, settings))
|
||||
{
|
||||
|
@ -109,14 +113,14 @@ 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, signedIn.user?.username))
|
||||
if (CheckIfUserIsOwner(plexSettings.PlexAuthToken, signedIn.user?.username))
|
||||
{
|
||||
Log.Debug("User is the account owner");
|
||||
authenticated = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
authenticated = CheckIfUserIsInPlexFriends(username, settings.PlexAuthToken);
|
||||
authenticated = CheckIfUserIsInPlexFriends(username, plexSettings.PlexAuthToken);
|
||||
Log.Debug("Friends list result = {0}", authenticated);
|
||||
}
|
||||
}
|
||||
|
@ -124,8 +128,8 @@ namespace PlexRequests.UI.Modules
|
|||
else if (settings.UserAuthentication) // Check against the users in Plex
|
||||
{
|
||||
Log.Debug("Need to auth");
|
||||
authenticated = CheckIfUserIsInPlexFriends(username, settings.PlexAuthToken);
|
||||
if (CheckIfUserIsOwner(settings.PlexAuthToken, username))
|
||||
authenticated = CheckIfUserIsInPlexFriends(username, plexSettings.PlexAuthToken);
|
||||
if (CheckIfUserIsOwner(plexSettings.PlexAuthToken, username))
|
||||
{
|
||||
Log.Debug("User is the account owner");
|
||||
authenticated = true;
|
||||
|
|
|
@ -18,13 +18,13 @@ namespace PlexRequests.UI.Modules
|
|||
{
|
||||
public class UserManagementModule : BaseModule
|
||||
{
|
||||
public UserManagementModule(ISettingsService<PlexRequestSettings> pr, ICustomUserMapper m, IPlexApi plexApi, ISettingsService<AuthenticationSettings> auth) : base("usermanagement", pr)
|
||||
public UserManagementModule(ISettingsService<PlexRequestSettings> pr, ICustomUserMapper m, IPlexApi plexApi, ISettingsService<PlexSettings> plex) : base("usermanagement", pr)
|
||||
{
|
||||
//this.RequiresClaims(UserClaims.Admin);
|
||||
|
||||
UserMapper = m;
|
||||
PlexApi = plexApi;
|
||||
AuthSettings = auth;
|
||||
PlexSettings = plex;
|
||||
|
||||
Get["/"] = x => Load();
|
||||
|
||||
|
@ -36,7 +36,7 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
private ICustomUserMapper UserMapper { get; }
|
||||
private IPlexApi PlexApi { get; }
|
||||
private ISettingsService<AuthenticationSettings> AuthSettings { get; }
|
||||
private ISettingsService<PlexSettings> PlexSettings { get; }
|
||||
|
||||
private Negotiator Load()
|
||||
{
|
||||
|
@ -63,11 +63,11 @@ namespace PlexRequests.UI.Modules
|
|||
});
|
||||
}
|
||||
|
||||
var authSettings = await AuthSettings.GetSettingsAsync();
|
||||
if (!string.IsNullOrEmpty(authSettings.PlexAuthToken))
|
||||
var plexSettings = await PlexSettings.GetSettingsAsync();
|
||||
if (!string.IsNullOrEmpty(plexSettings.PlexAuthToken))
|
||||
{
|
||||
//Get Plex Users
|
||||
var plexUsers = PlexApi.GetUsers(authSettings.PlexAuthToken);
|
||||
var plexUsers = PlexApi.GetUsers(plexSettings.PlexAuthToken);
|
||||
|
||||
foreach (var u in plexUsers.User)
|
||||
{
|
||||
|
@ -116,11 +116,11 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
private async Task<Response> PlexDetails(int id)
|
||||
{
|
||||
var authSettings = await AuthSettings.GetSettingsAsync();
|
||||
if (!string.IsNullOrEmpty(authSettings.PlexAuthToken))
|
||||
var plexSettings = await PlexSettings.GetSettingsAsync();
|
||||
if (!string.IsNullOrEmpty(plexSettings.PlexAuthToken))
|
||||
{
|
||||
//Get Plex Users
|
||||
var plexUsers = PlexApi.GetUsers(authSettings.PlexAuthToken);
|
||||
var plexUsers = PlexApi.GetUsers(plexSettings.PlexAuthToken);
|
||||
|
||||
var selectedUser = plexUsers.User?.FirstOrDefault(x => x.Id == id);
|
||||
if (selectedUser != null)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue