Check IGDB credentials are valid before allowing metadata lookup
Ref #26
This commit is contained in:
parent
6ebf79de8b
commit
a291462bde
4 changed files with 51 additions and 6 deletions
|
@ -6,6 +6,7 @@
|
|||
@inject CompanyService CompanyService
|
||||
@inject GenreService GenreService
|
||||
@inject TagService TagService
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
@{
|
||||
RenderFragment Footer =
|
||||
|
@ -35,8 +36,21 @@
|
|||
</Table>
|
||||
</Modal>
|
||||
|
||||
@if (IGDBService.Authenticated)
|
||||
{
|
||||
<Button OnClick="() => SearchForGame(GameTitle)" Type="@ButtonType.Primary" Disabled="@(String.IsNullOrWhiteSpace(GameTitle))">@ButtonText</Button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<Popconfirm OnConfirm="() => NavigateToSettings()" Title="Invalid IGDB credentials. Setup now?">
|
||||
<Button Type="@ButtonType.Primary">@ButtonText</Button>
|
||||
</Popconfirm>
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter] public EventCallback<GameLookupResult> OnResultSelected { get; set; }
|
||||
[Parameter] public string ButtonText { get; set; }
|
||||
[Parameter] public string GameTitle { get; set; }
|
||||
|
||||
ITable? ResultsTable;
|
||||
|
||||
|
@ -56,7 +70,7 @@
|
|||
ResultsTable.SetSelection(new string[] { row.Data.IGDBId.ToString() });
|
||||
}
|
||||
|
||||
public async Task SearchForGame(string title)
|
||||
private async Task SearchForGame(string title)
|
||||
{
|
||||
Loading = true;
|
||||
ModalVisible = true;
|
||||
|
@ -148,4 +162,9 @@
|
|||
|
||||
return multiplayerModes;
|
||||
}
|
||||
|
||||
private void NavigateToSettings()
|
||||
{
|
||||
NavigationManager.NavigateTo("/Settings/General", true);
|
||||
}
|
||||
}
|
|
@ -44,14 +44,12 @@
|
|||
<div data-panel="General">
|
||||
<Form Model="@Game" Layout="@FormLayout.Vertical">
|
||||
<FormItem Label="Title">
|
||||
<GameMetadataLookup @ref="GameMetadataLookup" OnResultSelected="OnGameLookupResultSelected" />
|
||||
|
||||
<Space Style="display: flex">
|
||||
<SpaceItem Style="flex-grow: 1">
|
||||
<Input @bind-Value="@context.Title" BindOnInput="true" />
|
||||
</SpaceItem>
|
||||
<SpaceItem>
|
||||
<Button OnClick="() => GameMetadataLookup.SearchForGame(context.Title)" Type="@ButtonType.Primary" Disabled="@(String.IsNullOrWhiteSpace(context.Title))">Lookup</Button>
|
||||
<GameMetadataLookup ButtonText="Lookup" GameTitle="@context.Title" OnResultSelected="OnGameLookupResultSelected" />
|
||||
</SpaceItem>
|
||||
</Space>
|
||||
</FormItem>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
@using LANCommander.Models;
|
||||
@layout SettingsLayout
|
||||
@inject SettingService SettingService
|
||||
@inject IGDBService IGDBService
|
||||
@inject IMessageService MessageService
|
||||
@attribute [Authorize(Roles = "Administrator")]
|
||||
|
||||
|
@ -47,6 +48,9 @@
|
|||
try
|
||||
{
|
||||
SettingService.SaveSettings(Settings);
|
||||
|
||||
IGDBService.Authenticate();
|
||||
|
||||
MessageService.Success("Settings saved!");
|
||||
}
|
||||
catch
|
||||
|
|
|
@ -5,17 +5,41 @@ namespace LANCommander.Services
|
|||
{
|
||||
public class IGDBService
|
||||
{
|
||||
private readonly IGDBClient Client;
|
||||
private readonly SettingService SettingService;
|
||||
private const string DefaultFields = "*";
|
||||
private IGDBClient Client;
|
||||
|
||||
public bool Authenticated = false;
|
||||
|
||||
private string ClientId { get; set; }
|
||||
private string ClientSecret { get; set; }
|
||||
|
||||
public IGDBService(SettingService settingService)
|
||||
{
|
||||
SettingService = settingService;
|
||||
|
||||
Authenticate();
|
||||
}
|
||||
|
||||
public void Authenticate()
|
||||
{
|
||||
var settings = SettingService.GetSettings();
|
||||
|
||||
Client = new IGDBClient(settings.IGDBClientId, settings.IGDBClientSecret);
|
||||
ClientId = settings.IGDBClientId;
|
||||
ClientSecret = settings.IGDBClientSecret;
|
||||
|
||||
try
|
||||
{
|
||||
if (String.IsNullOrWhiteSpace(ClientId) || String.IsNullOrWhiteSpace(ClientSecret))
|
||||
throw new Exception("Invalid IGDB credentials");
|
||||
|
||||
Client = new IGDBClient(ClientId, ClientSecret);
|
||||
Authenticated = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Authenticated = false;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Game> Get(long id, params string[] additionalFields)
|
||||
|
|
Loading…
Add table
Reference in a new issue