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;
|
||||
|
||||
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;
|
||||
|
|
|
@ -183,17 +183,13 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
private async Task<Response> ProcessMovies(MovieSearchType searchType, string searchTerm)
|
||||
{
|
||||
var apiMovies = new List<MovieResult>();
|
||||
await Task.Factory.StartNew(
|
||||
() =>
|
||||
{
|
||||
List<MovieResult> apiMovies;
|
||||
|
||||
switch (searchType)
|
||||
{
|
||||
case MovieSearchType.Search:
|
||||
return
|
||||
MovieApi.SearchMovie(searchTerm)
|
||||
.Result.Select(
|
||||
x =>
|
||||
var movies = await MovieApi.SearchMovie(searchTerm);
|
||||
apiMovies = movies.Select(x =>
|
||||
new MovieResult()
|
||||
{
|
||||
Adult = x.Adult,
|
||||
|
@ -212,18 +208,17 @@ namespace PlexRequests.UI.Modules
|
|||
VoteCount = x.VoteCount
|
||||
})
|
||||
.ToList();
|
||||
break;
|
||||
case MovieSearchType.CurrentlyPlaying:
|
||||
return MovieApi.GetCurrentPlayingMovies().Result.ToList();
|
||||
apiMovies = await MovieApi.GetCurrentPlayingMovies();
|
||||
break;
|
||||
case MovieSearchType.Upcoming:
|
||||
return MovieApi.GetUpcomingMovies().Result.ToList();
|
||||
apiMovies = await MovieApi.GetUpcomingMovies();
|
||||
break;
|
||||
default:
|
||||
return new List<MovieResult>();
|
||||
apiMovies = new List<MovieResult>();
|
||||
break;
|
||||
}
|
||||
}).ContinueWith(
|
||||
(t) =>
|
||||
{
|
||||
apiMovies = t.Result;
|
||||
});
|
||||
|
||||
var allResults = await RequestService.GetAllAsync();
|
||||
allResults = allResults.Where(x => x.Type == RequestType.Movie);
|
||||
|
@ -236,7 +231,7 @@ namespace PlexRequests.UI.Modules
|
|||
var plexMovies = Checker.GetPlexMovies();
|
||||
var settings = await PrService.GetSettingsAsync();
|
||||
var viewMovies = new List<SearchMovieViewModel>();
|
||||
foreach (MovieResult movie in apiMovies)
|
||||
foreach (var movie in apiMovies)
|
||||
{
|
||||
var viewMovie = new SearchMovieViewModel
|
||||
{
|
||||
|
@ -437,7 +432,7 @@ namespace PlexRequests.UI.Modules
|
|||
}
|
||||
|
||||
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 existingRequest = await RequestService.CheckRequestAsync(movieId);
|
||||
|
|
|
@ -31,6 +31,7 @@ using System.Threading.Tasks;
|
|||
|
||||
using Nancy;
|
||||
using Nancy.Extensions;
|
||||
using Nancy.Linker;
|
||||
using Nancy.Responses.Negotiation;
|
||||
|
||||
using NLog;
|
||||
|
@ -49,16 +50,18 @@ namespace PlexRequests.UI.Modules
|
|||
{
|
||||
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;
|
||||
LandingPageSettings = lp;
|
||||
Analytics = a;
|
||||
Api = api;
|
||||
PlexSettings = plexSettings;
|
||||
Linker = linker;
|
||||
|
||||
Get["UserLoginIndex","/", true] = async (x, ct) => await Index();
|
||||
Post["/", true] = async (x,ct) => await LoginUser();
|
||||
Get["UserLoginIndex", "/", true] = async (x, ct) => await Index();
|
||||
Post["/", true] = async (x, ct) => await LoginUser();
|
||||
Get["/logout"] = x => Logout();
|
||||
}
|
||||
|
||||
|
@ -66,13 +69,13 @@ namespace PlexRequests.UI.Modules
|
|||
private ISettingsService<LandingPageSettings> LandingPageSettings { get; }
|
||||
private ISettingsService<PlexSettings> PlexSettings { get; }
|
||||
private IPlexApi Api { get; }
|
||||
private IResourceLinker Linker { get; }
|
||||
private IAnalytics Analytics { get; }
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public async Task<Negotiator> Index()
|
||||
{
|
||||
|
||||
var settings = await AuthService.GetSettingsAsync();
|
||||
return View["Index", settings];
|
||||
}
|
||||
|
@ -84,7 +87,9 @@ namespace PlexRequests.UI.Modules
|
|||
Log.Debug("Username \"{0}\" attempting to login", 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;
|
||||
|
@ -95,7 +100,8 @@ namespace PlexRequests.UI.Modules
|
|||
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 uri = Linker.BuildAbsoluteUri(Context, "UserLoginIndex", "error=check");
|
||||
return Response.AsRedirect(uri.ToString()); // TODO Check this
|
||||
}
|
||||
|
||||
var password = string.Empty;
|
||||
|
@ -153,7 +159,8 @@ namespace PlexRequests.UI.Modules
|
|||
|
||||
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();
|
||||
|
@ -161,16 +168,19 @@ namespace PlexRequests.UI.Modules
|
|||
if (landingSettings.Enabled)
|
||||
{
|
||||
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()
|
||||
{
|
||||
Log.Debug("Logging Out");
|
||||
if (Session[SessionKeys.UsernameKey] != null)
|
||||
{
|
||||
Session.Delete(SessionKeys.UsernameKey);
|
||||
|
|
|
@ -157,15 +157,9 @@
|
|||
</div>
|
||||
<div class="col-sm-5 ">
|
||||
<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">
|
||||
<h4>{{title}} ({{year}})</h4>
|
||||
</a>
|
||||
{{/if_eq}}
|
||||
</div>
|
||||
<p>{{overview}}</p>
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
@using PlexRequests.UI.Helpers
|
||||
|
||||
@using PlexRequests.UI.Helpers
|
||||
@using PlexRequests.UI.Resources
|
||||
@{
|
||||
var nullableError = Context.ViewBag.TempMessage ?? string.Empty;
|
||||
var error = false;
|
||||
if (!string.IsNullOrEmpty(nullableError))
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
<div class="home">
|
||||
<h1>@UI.UserLogin_Title</h1>
|
||||
<div>
|
||||
|
@ -8,6 +17,7 @@
|
|||
</p>
|
||||
</div>
|
||||
<form method="POST" id="loginForm">
|
||||
<input id="dateTimeOffset" name="DateTimeOffset" hidden="hidden" />
|
||||
<div>
|
||||
<div>
|
||||
<label>@UI.UserLogin_Username</label>
|
||||
|
@ -24,7 +34,7 @@
|
|||
<label> @UI.UserLogin_Password </label>
|
||||
</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>
|
||||
<br />
|
||||
|
@ -36,15 +46,25 @@
|
|||
|
||||
<script>
|
||||
$(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();
|
||||
var $form = $("#loginForm");
|
||||
var formData = $form.serialize();
|
||||
var dtOffset = new Date().getTimezoneOffset();
|
||||
formData += ('&DateTimeOffset=' + dtOffset);
|
||||
|
||||
var url = createBaseUrl(base, '/search');
|
||||
$.ajax({
|
||||
type: $form.prop("method"),
|
||||
url: $form.prop("action"),
|
||||
|
@ -53,7 +73,6 @@
|
|||
success: function (response) {
|
||||
console.log(response);
|
||||
if (response.result === true) {
|
||||
|
||||
location.replace(response.message);
|
||||
|
||||
} else {
|
||||
|
@ -65,6 +84,7 @@
|
|||
generateNotify("@UI.Javascript_SomethingWentWrong", "danger");
|
||||
}
|
||||
});
|
||||
});
|
||||
});*@
|
||||
|
||||
});
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue