-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Standartized external database access
Added GOG autht support Fixed back to X buttons
- Loading branch information
Showing
45 changed files
with
1,573 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using BUTR.Site.NexusMods.ServerClient; | ||
|
||
namespace BUTR.Site.NexusMods.Client.Models | ||
{ | ||
public sealed record GOGUserInfo2 | ||
{ | ||
public string Url { get; init; } | ||
public string Name { get; init; } | ||
|
||
public GOGUserInfo2(GOGUserInfo userInfo) | ||
{ | ||
Url = $"https://www.gog.com/u/{userInfo.Username}"; | ||
Name = userInfo.Username; | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
@attribute [Authorize] | ||
@page "/gog-linked-role" | ||
|
||
@inject IGOGClient _gogClient; | ||
@inject NavigationManager _navigationManager; | ||
|
||
<Container> | ||
@if (!string.IsNullOrEmpty(Url)) | ||
{ | ||
<br/> | ||
<Card> | ||
<CardBody> | ||
<Text>GOG auth is partially supported.</Text> | ||
<br/> | ||
<Text>Please login to GOG by clicking the Login button and paste the url after redirect to here</Text> | ||
<br/> | ||
<Button TextWeight="@TextWeight.Bold" | ||
Color="@Color.Primary" | ||
Type="@ButtonType.Link" | ||
To="@Url" | ||
Target="@Target.Blank"> | ||
Login | ||
</Button> | ||
<Divider/> | ||
<Field> | ||
<FieldLabel>Callback Url</FieldLabel> | ||
<TextEdit @bind-Text="@CallbackUrl" Placeholder="https://embed.gog.com/on_login_success?..."></TextEdit> | ||
</Field> | ||
<Button TextWeight="@TextWeight.Bold" | ||
Color="@Color.Primary" | ||
Clicked="Callback"> | ||
Confirm | ||
</Button> | ||
</CardBody> | ||
</Card> | ||
} | ||
</Container> | ||
|
||
@code { | ||
|
||
private string Url = string.Empty; | ||
private string CallbackUrl = string.Empty; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
await base.OnInitializedAsync(); | ||
|
||
var response = await _gogClient.GetOAuthUrlAsync(); | ||
|
||
Url = response.Data.Url; | ||
} | ||
|
||
private void Callback() | ||
{ | ||
var url = new Uri(CallbackUrl); | ||
_navigationManager.NavigateTo($"/gog-oauth-callback{url.Query}"); | ||
} | ||
|
||
} |
83 changes: 83 additions & 0 deletions
83
src/BUTR.Site.NexusMods.Client/Pages/GOG/OAuthCallback.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
@attribute [Authorize] | ||
@page "/gog-oauth-callback" | ||
|
||
@inject IGOGClient _gogClient; | ||
@inject AuthenticationProvider _authenticationProvider; | ||
@inject ILocalStorageService _localStorage; | ||
@inject NavigationManager _navigationManager; | ||
|
||
<Container> | ||
<Row Flex="@Flex.JustifyContent.Center"> | ||
<Column ColumnSize="@ColumnSize.Is7.OnWidescreen.IsAuto.OnDesktop"> | ||
<Card Margin="@Margin.Is5.OnDesktop.Is4.OnTablet.Is3.OnMobile" Border="@Border.Is0.Rounded" Shadow="@Shadow.Small"> | ||
<CardBody> | ||
<Heading Padding="@Padding.Is3" Size="@HeadingSize.Is5" TextAlignment="@TextAlignment.Center" TextTransform="@TextTransform.Uppercase" TextWeight="@TextWeight.Bold">@_status</Heading> | ||
<Divider/> | ||
@if (_userInfo is not null) | ||
{ | ||
<Row Margin="@Margin.Is2"> | ||
<Span><Anchor Style="text-decoration: none" To="@_userInfo.Url" Target="Target.Blank">@_userInfo.Name</Anchor> was successfully linked with the BUTR Site!</Span> | ||
</Row> | ||
} | ||
else | ||
{ | ||
<Row Margin="@Margin.Is2"> | ||
<Spinner/> | ||
</Row> | ||
} | ||
|
||
@if (!string.IsNullOrEmpty(_message)) | ||
{ | ||
<Row Margin="@Margin.Is2"> | ||
<Span>@_message</Span> | ||
</Row> | ||
} | ||
|
||
@if (!string.IsNullOrEmpty(_image)) | ||
{ | ||
<Row Margin="@Margin.Is2"> | ||
<FigureImage Margin="Margin.Is0" Source="@_image" AlternateText="A meme image displaying success or failure. Success is Brent Rambo giving a thumbs up. Failure is a horse failing to play with a gymnastics by kinda lying onto it ball and falling."></FigureImage> | ||
</Row> | ||
} | ||
</CardBody> | ||
</Card> | ||
</Column> | ||
</Row> | ||
</Container> | ||
|
||
@code { | ||
|
||
private const string Success = "images/success.gif"; | ||
private const string Failure = "images/failure.gif"; | ||
|
||
private string _status = string.Empty; | ||
private string _message = string.Empty; | ||
private string _image = string.Empty; | ||
private GOGUserInfo2? _userInfo; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
await base.OnInitializedAsync(); | ||
|
||
var queries = _navigationManager.QueryString(); | ||
var queryCode = queries["code"]; | ||
|
||
try | ||
{ | ||
await _gogClient.LinkAsync(queryCode); | ||
_ = await _authenticationProvider.ValidateAsync(); | ||
|
||
var userInfo = await _gogClient.GetUserInfoAsync(); | ||
_userInfo = new GOGUserInfo2(userInfo.Data); | ||
_status = "SUCCESS"; | ||
_image = Success; | ||
} | ||
catch (ApiException) | ||
{ | ||
_status = "FAILURE"; | ||
_message = "Failed to link!"; | ||
_image = Failure; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/BUTR.Site.NexusMods.Server/Contexts/Config/GOGLinkedRoleTokensEntityConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using BUTR.Site.NexusMods.Server.Models.Database; | ||
|
||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace BUTR.Site.NexusMods.Server.Contexts.Config; | ||
|
||
public class GOGLinkedRoleTokensEntityConfiguration : BaseEntityConfiguration<GOGLinkedRoleTokensEntity> | ||
{ | ||
protected override void ConfigureModel(EntityTypeBuilder<GOGLinkedRoleTokensEntity> builder) | ||
{ | ||
builder.ToTable("gog_linked_role_tokens").HasKey(p => p.UserId).HasName("gog_linked_role_tokens_pkey"); | ||
builder.Property(p => p.UserId).HasColumnName("user_id").ValueGeneratedNever().IsRequired(); | ||
builder.Property(p => p.RefreshToken).HasColumnName("refresh_token").IsRequired(); | ||
builder.Property(p => p.AccessToken).HasColumnName("access_token").IsRequired(); | ||
builder.Property(p => p.AccessTokenExpiresAt).HasColumnName("access_token_expires_at").IsRequired(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/BUTR.Site.NexusMods.Server/Contexts/Config/NexusModsUserToGOGEntityConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using BUTR.Site.NexusMods.Server.Models.Database; | ||
|
||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace BUTR.Site.NexusMods.Server.Contexts.Config | ||
{ | ||
public class NexusModsUserToGOGEntityConfiguration : BaseEntityConfiguration<NexusModsUserToGOGEntity> | ||
{ | ||
protected override void ConfigureModel(EntityTypeBuilder<NexusModsUserToGOGEntity> builder) | ||
{ | ||
builder.ToTable("nexusmods_to_gog").HasKey(p => p.NexusModsUserId).HasName("nexusmods_to_gog_pkey"); | ||
builder.Property(p => p.NexusModsUserId).HasColumnName("nexusmods_user_id").ValueGeneratedNever().IsRequired(); | ||
builder.Property(p => p.UserId).HasColumnName("gog_user_id").IsRequired(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.