diff --git a/LANCommander/Pages/Games/Components/GameMetadataLookup.razor b/LANCommander/Pages/Games/Components/GameMetadataLookup.razor index 0ffb4fb..59c8110 100644 --- a/LANCommander/Pages/Games/Components/GameMetadataLookup.razor +++ b/LANCommander/Pages/Games/Components/GameMetadataLookup.razor @@ -6,6 +6,7 @@ @inject CompanyService CompanyService @inject GenreService GenreService @inject TagService TagService +@inject NavigationManager NavigationManager @{ RenderFragment Footer = @@ -35,8 +36,21 @@ +@if (IGDBService.Authenticated) +{ + +} +else +{ + + + +} + @code { [Parameter] public EventCallback 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); + } } \ No newline at end of file diff --git a/LANCommander/Pages/Games/Edit.razor b/LANCommander/Pages/Games/Edit.razor index aa9a325..c98f809 100644 --- a/LANCommander/Pages/Games/Edit.razor +++ b/LANCommander/Pages/Games/Edit.razor @@ -44,14 +44,12 @@
- - - + diff --git a/LANCommander/Pages/Settings/General.razor b/LANCommander/Pages/Settings/General.razor index e2e5f6d..b61d8a8 100644 --- a/LANCommander/Pages/Settings/General.razor +++ b/LANCommander/Pages/Settings/General.razor @@ -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 diff --git a/LANCommander/Services/IGDBService.cs b/LANCommander/Services/IGDBService.cs index e21919a..5cb9624 100644 --- a/LANCommander/Services/IGDBService.cs +++ b/LANCommander/Services/IGDBService.cs @@ -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 Get(long id, params string[] additionalFields)