mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-14 01:02:57 -07:00
Reworking the login page for #426
This commit is contained in:
parent
a82fdbc3bd
commit
f03392691c
5 changed files with 98 additions and 68 deletions
|
@ -69,7 +69,18 @@ namespace PlexRequests.UI.Modules
|
||||||
|
|
||||||
ModulePath = settingModulePath;
|
ModulePath = settingModulePath;
|
||||||
|
|
||||||
Before += (ctx) => SetCookie();
|
Before += (ctx) =>
|
||||||
|
{
|
||||||
|
SetCookie();
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(ctx.Request.Session["TempMessage"] as string))
|
||||||
|
{
|
||||||
|
ctx.ViewBag.TempMessage = ctx.Request.Session["TempMessage"];
|
||||||
|
ctx.ViewBag.TempType = ctx.Request.Session["TempType"];
|
||||||
|
ctx.Request.Session.DeleteAll();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private int _dateTimeOffset = -1;
|
private int _dateTimeOffset = -1;
|
||||||
|
|
|
@ -183,17 +183,13 @@ namespace PlexRequests.UI.Modules
|
||||||
|
|
||||||
private async Task<Response> ProcessMovies(MovieSearchType searchType, string searchTerm)
|
private async Task<Response> ProcessMovies(MovieSearchType searchType, string searchTerm)
|
||||||
{
|
{
|
||||||
var apiMovies = new List<MovieResult>();
|
List<MovieResult> apiMovies;
|
||||||
await Task.Factory.StartNew(
|
|
||||||
() =>
|
|
||||||
{
|
|
||||||
switch (searchType)
|
switch (searchType)
|
||||||
{
|
{
|
||||||
case MovieSearchType.Search:
|
case MovieSearchType.Search:
|
||||||
return
|
var movies = await MovieApi.SearchMovie(searchTerm);
|
||||||
MovieApi.SearchMovie(searchTerm)
|
apiMovies = movies.Select(x =>
|
||||||
.Result.Select(
|
|
||||||
x =>
|
|
||||||
new MovieResult()
|
new MovieResult()
|
||||||
{
|
{
|
||||||
Adult = x.Adult,
|
Adult = x.Adult,
|
||||||
|
@ -212,18 +208,17 @@ namespace PlexRequests.UI.Modules
|
||||||
VoteCount = x.VoteCount
|
VoteCount = x.VoteCount
|
||||||
})
|
})
|
||||||
.ToList();
|
.ToList();
|
||||||
|
break;
|
||||||
case MovieSearchType.CurrentlyPlaying:
|
case MovieSearchType.CurrentlyPlaying:
|
||||||
return MovieApi.GetCurrentPlayingMovies().Result.ToList();
|
apiMovies = await MovieApi.GetCurrentPlayingMovies();
|
||||||
|
break;
|
||||||
case MovieSearchType.Upcoming:
|
case MovieSearchType.Upcoming:
|
||||||
return MovieApi.GetUpcomingMovies().Result.ToList();
|
apiMovies = await MovieApi.GetUpcomingMovies();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return new List<MovieResult>();
|
apiMovies = new List<MovieResult>();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}).ContinueWith(
|
|
||||||
(t) =>
|
|
||||||
{
|
|
||||||
apiMovies = t.Result;
|
|
||||||
});
|
|
||||||
|
|
||||||
var allResults = await RequestService.GetAllAsync();
|
var allResults = await RequestService.GetAllAsync();
|
||||||
allResults = allResults.Where(x => x.Type == RequestType.Movie);
|
allResults = allResults.Where(x => x.Type == RequestType.Movie);
|
||||||
|
@ -236,7 +231,7 @@ namespace PlexRequests.UI.Modules
|
||||||
var plexMovies = Checker.GetPlexMovies();
|
var plexMovies = Checker.GetPlexMovies();
|
||||||
var settings = await PrService.GetSettingsAsync();
|
var settings = await PrService.GetSettingsAsync();
|
||||||
var viewMovies = new List<SearchMovieViewModel>();
|
var viewMovies = new List<SearchMovieViewModel>();
|
||||||
foreach (MovieResult movie in apiMovies)
|
foreach (var movie in apiMovies)
|
||||||
{
|
{
|
||||||
var viewMovie = new SearchMovieViewModel
|
var viewMovie = new SearchMovieViewModel
|
||||||
{
|
{
|
||||||
|
@ -437,7 +432,7 @@ namespace PlexRequests.UI.Modules
|
||||||
}
|
}
|
||||||
|
|
||||||
Analytics.TrackEventAsync(Category.Search, Action.Request, "Movie", Username, CookieHelper.GetAnalyticClientId(Cookies));
|
Analytics.TrackEventAsync(Category.Search, Action.Request, "Movie", Username, CookieHelper.GetAnalyticClientId(Cookies));
|
||||||
var movieInfo = MovieApi.GetMovieInformation(movieId).Result;
|
var movieInfo = await MovieApi.GetMovieInformation(movieId);
|
||||||
var fullMovieName = $"{movieInfo.Title}{(movieInfo.ReleaseDate.HasValue ? $" ({movieInfo.ReleaseDate.Value.Year})" : string.Empty)}";
|
var fullMovieName = $"{movieInfo.Title}{(movieInfo.ReleaseDate.HasValue ? $" ({movieInfo.ReleaseDate.Value.Year})" : string.Empty)}";
|
||||||
|
|
||||||
var existingRequest = await RequestService.CheckRequestAsync(movieId);
|
var existingRequest = await RequestService.CheckRequestAsync(movieId);
|
||||||
|
|
|
@ -31,6 +31,7 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
using Nancy;
|
using Nancy;
|
||||||
using Nancy.Extensions;
|
using Nancy.Extensions;
|
||||||
|
using Nancy.Linker;
|
||||||
using Nancy.Responses.Negotiation;
|
using Nancy.Responses.Negotiation;
|
||||||
|
|
||||||
using NLog;
|
using NLog;
|
||||||
|
@ -49,16 +50,18 @@ namespace PlexRequests.UI.Modules
|
||||||
{
|
{
|
||||||
public class UserLoginModule : BaseModule
|
public class UserLoginModule : BaseModule
|
||||||
{
|
{
|
||||||
public UserLoginModule(ISettingsService<AuthenticationSettings> auth, IPlexApi api, ISettingsService<PlexSettings> plexSettings, 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, IResourceLinker linker) : base("userlogin", pr)
|
||||||
{
|
{
|
||||||
AuthService = auth;
|
AuthService = auth;
|
||||||
LandingPageSettings = lp;
|
LandingPageSettings = lp;
|
||||||
Analytics = a;
|
Analytics = a;
|
||||||
Api = api;
|
Api = api;
|
||||||
PlexSettings = plexSettings;
|
PlexSettings = plexSettings;
|
||||||
|
Linker = linker;
|
||||||
|
|
||||||
Get["UserLoginIndex","/", true] = async (x, ct) => await Index();
|
Get["UserLoginIndex", "/", true] = async (x, ct) => await Index();
|
||||||
Post["/", true] = async (x,ct) => await LoginUser();
|
Post["/", true] = async (x, ct) => await LoginUser();
|
||||||
Get["/logout"] = x => Logout();
|
Get["/logout"] = x => Logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,13 +69,13 @@ namespace PlexRequests.UI.Modules
|
||||||
private ISettingsService<LandingPageSettings> LandingPageSettings { get; }
|
private ISettingsService<LandingPageSettings> LandingPageSettings { get; }
|
||||||
private ISettingsService<PlexSettings> PlexSettings { get; }
|
private ISettingsService<PlexSettings> PlexSettings { get; }
|
||||||
private IPlexApi Api { get; }
|
private IPlexApi Api { get; }
|
||||||
|
private IResourceLinker Linker { get; }
|
||||||
private IAnalytics Analytics { get; }
|
private IAnalytics Analytics { get; }
|
||||||
|
|
||||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
public async Task<Negotiator> Index()
|
public async Task<Negotiator> Index()
|
||||||
{
|
{
|
||||||
|
|
||||||
var settings = await AuthService.GetSettingsAsync();
|
var settings = await AuthService.GetSettingsAsync();
|
||||||
return View["Index", settings];
|
return View["Index", settings];
|
||||||
}
|
}
|
||||||
|
@ -84,7 +87,9 @@ namespace PlexRequests.UI.Modules
|
||||||
Log.Debug("Username \"{0}\" attempting to login", username);
|
Log.Debug("Username \"{0}\" attempting to login", username);
|
||||||
if (string.IsNullOrWhiteSpace(username))
|
if (string.IsNullOrWhiteSpace(username))
|
||||||
{
|
{
|
||||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Incorrect User or Password" });
|
Session["TempMessage"] = "username";
|
||||||
|
var uri = Linker.BuildAbsoluteUri(Context, "UserLoginIndex");
|
||||||
|
return Response.AsRedirect(uri.ToString()); // TODO Check this
|
||||||
}
|
}
|
||||||
|
|
||||||
var authenticated = false;
|
var authenticated = false;
|
||||||
|
@ -95,7 +100,8 @@ namespace PlexRequests.UI.Modules
|
||||||
if (IsUserInDeniedList(username, settings))
|
if (IsUserInDeniedList(username, settings))
|
||||||
{
|
{
|
||||||
Log.Debug("User is in denied list, not allowing them to authenticate");
|
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 uri = Linker.BuildAbsoluteUri(Context, "UserLoginIndex", "error=check");
|
||||||
|
return Response.AsRedirect(uri.ToString()); // TODO Check this
|
||||||
}
|
}
|
||||||
|
|
||||||
var password = string.Empty;
|
var password = string.Empty;
|
||||||
|
@ -153,7 +159,8 @@ namespace PlexRequests.UI.Modules
|
||||||
|
|
||||||
if (!authenticated)
|
if (!authenticated)
|
||||||
{
|
{
|
||||||
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Incorrect User or Password" });
|
var uri = Linker.BuildAbsoluteUri(Context, "UserLoginIndex", "error=incorrect");
|
||||||
|
return Response.AsRedirect(uri.ToString()); // TODO Check this
|
||||||
}
|
}
|
||||||
|
|
||||||
var landingSettings = LandingPageSettings.GetSettings();
|
var landingSettings = LandingPageSettings.GetSettings();
|
||||||
|
@ -161,16 +168,19 @@ namespace PlexRequests.UI.Modules
|
||||||
if (landingSettings.Enabled)
|
if (landingSettings.Enabled)
|
||||||
{
|
{
|
||||||
if (!landingSettings.BeforeLogin)
|
if (!landingSettings.BeforeLogin)
|
||||||
return Response.AsJson(new JsonResponseModel { Result = true, Message = "landing" });
|
{
|
||||||
|
var uri = Linker.BuildAbsoluteUri(Context, "LandingPageIndex");
|
||||||
|
return Response.AsRedirect(uri.ToString());
|
||||||
}
|
}
|
||||||
return Response.AsJson(new JsonResponseModel { Result = true, Message = "search" });
|
}
|
||||||
|
var retVal = Linker.BuildAbsoluteUri(Context, "SearchIndex");
|
||||||
|
return Response.AsRedirect(retVal.ToString()); // TODO Check this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Response Logout()
|
private Response Logout()
|
||||||
{
|
{
|
||||||
Log.Debug("Logging Out");
|
|
||||||
if (Session[SessionKeys.UsernameKey] != null)
|
if (Session[SessionKeys.UsernameKey] != null)
|
||||||
{
|
{
|
||||||
Session.Delete(SessionKeys.UsernameKey);
|
Session.Delete(SessionKeys.UsernameKey);
|
||||||
|
|
|
@ -157,15 +157,9 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-5 ">
|
<div class="col-sm-5 ">
|
||||||
<div>
|
<div>
|
||||||
{{#if_eq type "movie"}}
|
|
||||||
<a href="https://www.themoviedb.org/movie/{{id}}/" target="_blank">
|
|
||||||
<h4>{{title}} ({{year}})</h4>
|
|
||||||
</a>
|
|
||||||
{{else}}
|
|
||||||
<a href="http://www.imdb.com/title/{{imdb}}/" target="_blank">
|
<a href="http://www.imdb.com/title/{{imdb}}/" target="_blank">
|
||||||
<h4>{{title}} ({{year}})</h4>
|
<h4>{{title}} ({{year}})</h4>
|
||||||
</a>
|
</a>
|
||||||
{{/if_eq}}
|
|
||||||
</div>
|
</div>
|
||||||
<p>{{overview}}</p>
|
<p>{{overview}}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
@using PlexRequests.UI.Helpers
|
|
||||||
|
@using PlexRequests.UI.Helpers
|
||||||
@using PlexRequests.UI.Resources
|
@using PlexRequests.UI.Resources
|
||||||
|
@{
|
||||||
|
var nullableError = Context.ViewBag.TempMessage ?? string.Empty;
|
||||||
|
var error = false;
|
||||||
|
if (!string.IsNullOrEmpty(nullableError))
|
||||||
|
{
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
<div class="home">
|
<div class="home">
|
||||||
<h1>@UI.UserLogin_Title</h1>
|
<h1>@UI.UserLogin_Title</h1>
|
||||||
<div>
|
<div>
|
||||||
|
@ -8,6 +17,7 @@
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<form method="POST" id="loginForm">
|
<form method="POST" id="loginForm">
|
||||||
|
<input id="dateTimeOffset" name="DateTimeOffset" hidden="hidden" />
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
<label>@UI.UserLogin_Username</label>
|
<label>@UI.UserLogin_Username</label>
|
||||||
|
@ -24,7 +34,7 @@
|
||||||
<label> @UI.UserLogin_Password </label>
|
<label> @UI.UserLogin_Password </label>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<input id="password" class="form-control form-control-custom" name="Password" type="password" placeholder="@UI.UserLogin_Password"/>
|
<input id="password" class="form-control form-control-custom" name="Password" type="password" placeholder="@UI.UserLogin_Password" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<br />
|
<br />
|
||||||
|
@ -36,15 +46,25 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
$(function () {
|
$(function () {
|
||||||
var base = '@Html.GetBaseUrl()';
|
|
||||||
$('#loginBtn').click(function (e) {
|
$('#dateTimeOffset').val(new Date().getTimezoneOffset());
|
||||||
|
|
||||||
|
@if (error)
|
||||||
|
{
|
||||||
|
<text>
|
||||||
|
|
||||||
|
generateNotify('@nullableError',"warning");
|
||||||
|
|
||||||
|
</text>
|
||||||
|
}
|
||||||
|
|
||||||
|
@*$('#loginBtn').click(function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var $form = $("#loginForm");
|
var $form = $("#loginForm");
|
||||||
var formData = $form.serialize();
|
var formData = $form.serialize();
|
||||||
var dtOffset = new Date().getTimezoneOffset();
|
var dtOffset = new Date().getTimezoneOffset();
|
||||||
formData += ('&DateTimeOffset=' + dtOffset);
|
formData += ('&DateTimeOffset=' + dtOffset);
|
||||||
|
|
||||||
var url = createBaseUrl(base, '/search');
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: $form.prop("method"),
|
type: $form.prop("method"),
|
||||||
url: $form.prop("action"),
|
url: $form.prop("action"),
|
||||||
|
@ -53,7 +73,6 @@
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
console.log(response);
|
console.log(response);
|
||||||
if (response.result === true) {
|
if (response.result === true) {
|
||||||
|
|
||||||
location.replace(response.message);
|
location.replace(response.message);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -65,6 +84,7 @@
|
||||||
generateNotify("@UI.Javascript_SomethingWentWrong", "danger");
|
generateNotify("@UI.Javascript_SomethingWentWrong", "danger");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});*@
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue