Skip to content

Commit

Permalink
Backport of commit 48a5685 bug fix for #348
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasstich committed Aug 18, 2023
1 parent 3836949 commit c15e5f5
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 5 deletions.
13 changes: 11 additions & 2 deletions BackendAccess/BackendServices/UserWebApiServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,17 @@ public async Task<UserInformationBE> GetUserInformationAsync(string token)
{ "WebServiceToken", token }
};

return await SendHttpGetRequestAsync<UserInformationBE>("Users/UserData",
parameters);
try
{
return await SendHttpGetRequestAsync<UserInformationBE>("Users/UserData",
parameters);
}
catch (HttpRequestException httpReqEx)
{
if (httpReqEx.Message == "The provided token is invalid")
throw new BackendInvalidTokenException(httpReqEx.Message, httpReqEx);
throw;
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace BusinessLogic.ErrorManagement.BackendAccess;

/// <summary>
/// This Exception is thrown when our saved token is invalid, indicating that we must log in again.
/// </summary>
public class BackendInvalidTokenException : Exception
{
public BackendInvalidTokenException() : base()
{
}

public BackendInvalidTokenException(string message) : base(message)
{
}

public BackendInvalidTokenException(string message, Exception innerException) : base(message, innerException)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace BusinessLogic.ErrorManagement.BackendAccess;

/**
* This exception is thrown when the entered URL is invalid
*/
/// <summary>
/// This exception is thrown when the entered URL is invalid
/// </summary>
public class BackendInvalidUrlException : Exception
{
public BackendInvalidUrlException()
Expand Down
28 changes: 28 additions & 0 deletions Presentation/Components/Dialogues/LmsLoginDialog.razor
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
}
else
{
@if (_spinnerActive)
{
<div class="w-full h-full absolute bg-adlergrey-100 bg-opacity-25 z-40">
</div>
<MudProgressCircular Indeterminate="true" Class="z-40 m-auto absolute top-0 bottom-0 left-0 right-0"
Color="Color.Primary" Size="Size.Large"/>
}
<div class="flex flex-col pb-3.5">
<MudForm>
<div class="flex flex-col">
Expand All @@ -46,6 +53,12 @@
@Localizer["DialogContent.Error.APIUnreachable"]
</MudText>
}
@if (_showErrorTokenInvalid)
{
<MudText Class="invalid-login-error" Color="Color.Error" Typo="Typo.subtitle2">
@Localizer["DialogContent.Error.TokenInvalid"]
</MudText>
}
</div>
<div class="flex flex-col">
<a href="https://demo.moodle.projekt-adler.eu/login/forgot_password.php" target="_blank" title="Lost password?" class="pb-2">
Expand Down Expand Up @@ -88,6 +101,8 @@
private bool _isLmsConnected = false;

private bool _isPasswordVisible = false;
private bool _showErrorTokenInvalid = false;
private bool _spinnerActive = false;
private InputType PasswordInputType => _isPasswordVisible ? InputType.Text : InputType.Password;
private string ShowPasswordIcon => _isPasswordVisible ? Icons.Material.Filled.Visibility : Icons.Material.Filled.VisibilityOff;

Expand All @@ -110,18 +125,28 @@
{
try
{
StartSpinner();
_isLmsConnected = await PresentationLogic.IsLmsConnected();
}
catch (BackendApiUnreachableException)
{
_showErrorApiUnreachable = true;
}
catch (BackendInvalidTokenException)
{
_showErrorTokenInvalid = true;
Logout();
}
finally
{
StopSpinner();
StateHasChanged();
}
}

private void StartSpinner() => _spinnerActive = true;
private void StopSpinner() => _spinnerActive = false;

private async void SubmitForm()
{
if (_backendUrl == "" || _username == "" || _password == "") return;
Expand All @@ -134,9 +159,11 @@
Configuration[IApplicationConfiguration.BackendUsername] = _username;
try
{
StartSpinner();
await PresentationLogic.Login(_username, _password);
_showErrorApiUnreachable = false;
_showErrorInvalidCredentials = false;
_showErrorTokenInvalid = false;
_errorInvalidUrlMessage = "";
CheckIfLmsIsConnected();
}
Expand All @@ -163,6 +190,7 @@
}
finally
{
StopSpinner();
await InvokeAsync(StateHasChanged);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,7 @@
<data name="DialogContent.Error.ProtocolMissing" xml:space="preserve">
<value>Die API URL muss mit "http://" oder "https://" beginnen.</value>
</data>
<data name="DialogContent.Error.TokenInvalid" xml:space="preserve">
<value>Bitte loggen Sie sich erneut ein.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,7 @@
<data name="DialogContent.Error.ProtocolMissing" xml:space="preserve">
<value>The API URL must start with either "http://" or "https://".</value>
</data>
<data name="DialogContent.Error.TokenInvalid" xml:space="preserve">
<value>Please log in again.</value>
</data>
</root>

0 comments on commit c15e5f5

Please sign in to comment.