mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-12 16:22:55 -07:00
Added a bunch of logging
This commit is contained in:
parent
4c0884999e
commit
3188a720fa
2 changed files with 37 additions and 13 deletions
|
@ -105,6 +105,7 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
if (tvShow?.data == null)
|
||||
{
|
||||
Log.Trace("TV Show data is null");
|
||||
return Response.AsJson("");
|
||||
}
|
||||
var model = new List<SearchTvShowViewModel>();
|
||||
|
@ -137,32 +138,39 @@ namespace PlexRequests.UI.Modules
|
|||
Zap2ItId = t.zap2itId
|
||||
});
|
||||
}
|
||||
|
||||
Log.Trace("Returning TV Show results: ");
|
||||
Log.Trace(model.DumpJson());
|
||||
return Response.AsJson(model);
|
||||
}
|
||||
|
||||
private Response UpcomingMovies()
|
||||
private Response UpcomingMovies() // TODO : Not used
|
||||
{
|
||||
var movies = MovieApi.GetUpcomingMovies();
|
||||
var result = movies.Result;
|
||||
Log.Trace("Movie Upcoming Results: ");
|
||||
Log.Trace(result.DumpJson());
|
||||
return Response.AsJson(result);
|
||||
}
|
||||
|
||||
private Response CurrentlyPlayingMovies()
|
||||
private Response CurrentlyPlayingMovies() // TODO : Not used
|
||||
{
|
||||
var movies = MovieApi.GetCurrentPlayingMovies();
|
||||
var result = movies.Result;
|
||||
Log.Trace("Movie Currently Playing Results: ");
|
||||
Log.Trace(result.DumpJson());
|
||||
return Response.AsJson(result);
|
||||
}
|
||||
|
||||
private Response RequestMovie(int movieId)
|
||||
{
|
||||
Log.Trace("Requesting movie with id {0}", movieId);
|
||||
Log.Info("Requesting movie with id {0}", movieId);
|
||||
if (RequestService.CheckRequest(movieId))
|
||||
{
|
||||
Log.Trace("movie with id {0} exists", movieId);
|
||||
return Response.AsJson(new { Result = false, Message = "Movie has already been requested!" });
|
||||
}
|
||||
Log.Trace("movie with id {0} doesnt exists", movieId);
|
||||
Log.Debug("movie with id {0} doesnt exists", movieId);
|
||||
var cpSettings = CpService.GetSettings();
|
||||
if (cpSettings.ApiKey == null)
|
||||
{
|
||||
|
@ -195,16 +203,17 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
|
||||
var settings = PrService.GetSettings();
|
||||
Log.Trace(settings.DumpJson());
|
||||
if (!settings.RequireApproval)
|
||||
{
|
||||
var cp = new CouchPotatoApi();
|
||||
Log.Trace("Adding movie to CP (No approval required)");
|
||||
Log.Info("Adding movie to CP (No approval required)");
|
||||
var result = cp.AddMovie(model.ImdbId, cpSettings.ApiKey, model.Title, cpSettings.FullUri);
|
||||
Log.Trace("Adding movie to CP result {0}", result);
|
||||
Log.Debug("Adding movie to CP result {0}", result);
|
||||
if (result)
|
||||
{
|
||||
model.Approved = true;
|
||||
Log.Trace("Adding movie to database requests (No approval required)");
|
||||
Log.Debug("Adding movie to database requests (No approval required)");
|
||||
RequestService.AddRequest(movieId, model);
|
||||
|
||||
return Response.AsJson(new { Result = true });
|
||||
|
@ -214,7 +223,7 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
try
|
||||
{
|
||||
Log.Trace("Adding movie to database requests");
|
||||
Log.Debug("Adding movie to database requests");
|
||||
var id = RequestService.AddRequest(movieId, model);
|
||||
//BackgroundJob.Enqueue(() => Checker.CheckAndUpdate(model.Title, (int)id));
|
||||
|
||||
|
@ -236,7 +245,6 @@ namespace PlexRequests.UI.Modules
|
|||
/// <returns></returns>
|
||||
private Response RequestTvShow(int showId, bool latest)
|
||||
{
|
||||
// Latest send to Sonarr and no need to store in DB
|
||||
if (RequestService.CheckRequest(showId))
|
||||
{
|
||||
return Response.AsJson(new { Result = false, Message = "TV Show has already been requested!" });
|
||||
|
|
|
@ -30,16 +30,17 @@ using Nancy;
|
|||
using Nancy.Extensions;
|
||||
using Nancy.Responses.Negotiation;
|
||||
|
||||
using NLog;
|
||||
|
||||
using PlexRequests.Api.Interfaces;
|
||||
using PlexRequests.Api.Models;
|
||||
using PlexRequests.Api.Models.Plex;
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers;
|
||||
using PlexRequests.UI.Models;
|
||||
|
||||
namespace PlexRequests.UI.Modules
|
||||
{
|
||||
// TODO: Add ability to logout
|
||||
public class UserLoginModule : NancyModule
|
||||
{
|
||||
public UserLoginModule(ISettingsService<AuthenticationSettings> auth, IPlexApi api) : base("userlogin")
|
||||
|
@ -54,6 +55,8 @@ namespace PlexRequests.UI.Modules
|
|||
private ISettingsService<AuthenticationSettings> AuthService { get; }
|
||||
private IPlexApi Api { get; }
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public Negotiator Index()
|
||||
{
|
||||
var settings = AuthService.GetSettings();
|
||||
|
@ -63,7 +66,7 @@ namespace PlexRequests.UI.Modules
|
|||
private Response LoginUser()
|
||||
{
|
||||
var username = Request.Form.username.Value;
|
||||
|
||||
Log.Debug("Username \"{0}\" attempting to login",username);
|
||||
if (string.IsNullOrWhiteSpace(username))
|
||||
{
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Incorrect User or Password" });
|
||||
|
@ -72,39 +75,49 @@ namespace PlexRequests.UI.Modules
|
|||
var authenticated = false;
|
||||
|
||||
var settings = AuthService.GetSettings();
|
||||
|
||||
Log.Debug("Settings: ");
|
||||
Log.Debug(settings.DumpJson());
|
||||
|
||||
if (IsUserInDeniedList(username, settings))
|
||||
{
|
||||
Log.Debug("User is in denied list, not allowing them to authenticate");
|
||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Incorrect User or Password" });
|
||||
}
|
||||
|
||||
var password = string.Empty;
|
||||
if (settings.UsePassword)
|
||||
{
|
||||
Log.Debug("Using password");
|
||||
password = Request.Form.password.Value;
|
||||
}
|
||||
|
||||
|
||||
if (settings.UserAuthentication && settings.UsePassword) // Authenticate with Plex
|
||||
{
|
||||
Log.Debug("Need to auth and also provide pass");
|
||||
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);
|
||||
}
|
||||
}
|
||||
else if(settings.UserAuthentication) // Check against the users in Plex
|
||||
{
|
||||
Log.Debug("Need to auth");
|
||||
authenticated = CheckIfUserIsInPlexFriends(username, settings.PlexAuthToken);
|
||||
Log.Debug("Friends list result = {0}", authenticated);
|
||||
}
|
||||
else if(!settings.UserAuthentication) // No auth, let them pass!
|
||||
{
|
||||
Log.Debug("No need to auth");
|
||||
authenticated = true;
|
||||
}
|
||||
|
||||
if (authenticated)
|
||||
{
|
||||
Log.Debug("We are authenticated! Setting session.");
|
||||
// Add to the session (Used in the BaseModules)
|
||||
Session[SessionKeys.UsernameKey] = (string)username;
|
||||
}
|
||||
|
@ -116,6 +129,7 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
private Response Logout()
|
||||
{
|
||||
Log.Debug("Logging Out");
|
||||
if (Session[SessionKeys.UsernameKey] != null)
|
||||
{
|
||||
Session.Delete(SessionKeys.UsernameKey);
|
||||
|
@ -126,6 +140,8 @@ namespace PlexRequests.UI.Modules
|
|||
private bool CheckIfUserIsInPlexFriends(string username, string authToken)
|
||||
{
|
||||
var users = Api.GetUsers(authToken);
|
||||
Log.Debug("Plex Users: ");
|
||||
Log.Debug(users.DumpJson());
|
||||
return users.User.Any(x => x.Username == username);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue