mirror of
https://github.com/lantean-code/qbtmud.git
synced 2025-10-22 20:42:24 +00:00
57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
using Lantean.QBitTorrentClient;
|
|
using Lantean.QBTMud.Models;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Forms;
|
|
using System.Net;
|
|
|
|
namespace Lantean.QBTMud.Pages
|
|
{
|
|
public partial class Login
|
|
{
|
|
[Inject]
|
|
protected IApiClient ApiClient { get; set; } = default!;
|
|
|
|
[Inject]
|
|
protected NavigationManager NavigationManager { get; set; } = default!;
|
|
|
|
protected LoginForm Model { get; set; } = new LoginForm();
|
|
|
|
protected string? ApiError { get; set; }
|
|
|
|
protected Task LoginClick(EditContext context)
|
|
{
|
|
return DoLogin(Model.Username, Model.Password);
|
|
}
|
|
|
|
private async Task DoLogin(string username, string password)
|
|
{
|
|
try
|
|
{
|
|
await ApiClient.Login(username, password);
|
|
|
|
NavigationManager.NavigateTo("/");
|
|
}
|
|
catch (HttpRequestException exception) when (exception.StatusCode == HttpStatusCode.BadRequest)
|
|
{
|
|
ApiError = "Invalid username or password.";
|
|
}
|
|
catch (HttpRequestException exception) when (exception.StatusCode == HttpStatusCode.Forbidden)
|
|
{
|
|
ApiError = "Requests from this client are currently unavailable.";
|
|
}
|
|
catch
|
|
{
|
|
ApiError = "Unable to communicate with the qBittorrent API.";
|
|
}
|
|
}
|
|
|
|
#if DEBUG
|
|
|
|
protected override Task OnInitializedAsync()
|
|
{
|
|
return DoLogin("admin", "cIYfeJr49");
|
|
}
|
|
|
|
#endif
|
|
}
|
|
} |