Fixed: Don't Error to New Page on Failed Login

pull/6/head
Qstick 6 years ago
parent d81b063388
commit 9d27fff825

@ -4,6 +4,7 @@ using Nancy.Authentication.Forms;
using Nancy.Extensions; using Nancy.Extensions;
using Nancy.ModelBinding; using Nancy.ModelBinding;
using NzbDrone.Common.EnsureThat; using NzbDrone.Common.EnsureThat;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Authentication; using NzbDrone.Core.Authentication;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
@ -24,16 +25,19 @@ namespace Lidarr.Http.Authentication
private Response Login(LoginResource resource) private Response Login(LoginResource resource)
{ {
Ensure.That(resource.Username, () => resource.Username).IsNotNullOrWhiteSpace(); var username = resource.Username;
var password = resource.Password;
Ensure.That(resource.Password, () => resource.Password).IsNotNullOrWhiteSpace(); if (username.IsNullOrWhiteSpace() || password.IsNullOrWhiteSpace())
{
return LoginFailed();
}
var user = _userService.FindUser(resource.Username, resource.Password); var user = _userService.FindUser(username, password);
if (user == null) if (user == null)
{ {
var returnUrl = (string)Request.Query.returnUrl; return LoginFailed();
return Context.GetRedirect($"~/login?returnUrl={returnUrl}&loginFailed=true");
} }
DateTime? expiry = null; DateTime? expiry = null;
@ -50,5 +54,11 @@ namespace Lidarr.Http.Authentication
{ {
return this.LogoutAndRedirect(_configFileProvider.UrlBase + "/"); return this.LogoutAndRedirect(_configFileProvider.UrlBase + "/");
} }
private Response LoginFailed()
{
var returnUrl = (string)Request.Query.returnUrl;
return Context.GetRedirect($"~/login?returnUrl={returnUrl}&loginFailed=true");
}
} }
} }

Loading…
Cancel
Save