From 43f0e3823da6e674266e20860fc0e5df902b3871 Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Tue, 14 Mar 2023 01:10:02 -0500 Subject: [PATCH] Handle invalid logins properly --- LANCommander.Playnite.Extension/LANCommanderClient.cs | 4 +--- .../Views/Authentication.xaml.cs | 6 ++++++ LANCommander/Controllers/Api/AuthController.cs | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/LANCommander.Playnite.Extension/LANCommanderClient.cs b/LANCommander.Playnite.Extension/LANCommanderClient.cs index 5105445..c65d21d 100644 --- a/LANCommander.Playnite.Extension/LANCommanderClient.cs +++ b/LANCommander.Playnite.Extension/LANCommanderClient.cs @@ -70,9 +70,6 @@ namespace LANCommander.PlaynitePlugin Password = password })); - if (String.IsNullOrWhiteSpace(response.Data.AccessToken)) - throw new WebException("Invalid username or password"); - switch (response.StatusCode) { case HttpStatusCode.OK: @@ -80,6 +77,7 @@ namespace LANCommander.PlaynitePlugin case HttpStatusCode.Forbidden: case HttpStatusCode.BadRequest: + case HttpStatusCode.Unauthorized: throw new WebException("Invalid username or password"); default: diff --git a/LANCommander.Playnite.Extension/Views/Authentication.xaml.cs b/LANCommander.Playnite.Extension/Views/Authentication.xaml.cs index 2366f81..1ea4545 100644 --- a/LANCommander.Playnite.Extension/Views/Authentication.xaml.cs +++ b/LANCommander.Playnite.Extension/Views/Authentication.xaml.cs @@ -113,6 +113,12 @@ namespace LANCommander.PlaynitePlugin.Views catch (Exception ex) { Plugin.PlayniteApi.Dialogs.ShowErrorMessage(ex.Message); + + LoginButton.Dispatcher.Invoke(new System.Action(() => + { + LoginButton.IsEnabled = true; + LoginButton.Content = "Login"; + })); } } } diff --git a/LANCommander/Controllers/Api/AuthController.cs b/LANCommander/Controllers/Api/AuthController.cs index 0782fb8..4bf74a4 100644 --- a/LANCommander/Controllers/Api/AuthController.cs +++ b/LANCommander/Controllers/Api/AuthController.cs @@ -75,7 +75,7 @@ namespace LANCommander.Controllers.Api }); } - return RedirectToAction("Index", "Home"); + return Unauthorized(); } [HttpPost("Validate")]