feat: WG auth dialog

This commit is contained in:
Mikhail Shabanov committed 2021-07-02 14:37:47 +02:00
1 parent 5d66c3641f
commit 83681c6b42
9 files changed
+287 -97

No files matched your search

@@ -95,5 +95,9 @@ namespace WotBlitzStatisticsPro.Blazor.Services
}
}
public Task<string> GetWgLoginUrl(RealmType realmType)
{
throw new System.NotImplementedException();
}
}
}
@@ -17,5 +17,7 @@ namespace WotBlitzStatisticsPro.Blazor.Services
Task<(IAccount accountInfo, IReadOnlyList<ISection> achievementsBySection)> GetPlayerInfo(
long accountId,
RealmType realmType);
Task<string> GetWgLoginUrl(RealmType realmType);
}
}
@@ -196,6 +196,12 @@ namespace WotBlitzStatisticsPro.Blazor.Services.Mock
return (player, achievements?.Sections);
}
public Task<string> GetWgLoginUrl(RealmType realmType)
{
return Task.FromResult(
"https://api.worldoftanks.eu/wot/auth/login/?application_id=adc1387489cf9fc8d9a1d85dbd27763d");
}
private string FakerLanguage(RequestLanguage language)
{
switch (language)
@@ -0,0 +1,43 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using Microsoft.Extensions.Localization;
using Radzen;
using WotBlitzStatisticsPro.Blazor.Messages;
using WotBlitzStatisticsPro.Blazor.Pages;
namespace WotBlitzStatisticsPro.Blazor.Services
{
public class WargamingLoginService: INotificationHandler<LoginToWgMessage>, INotificationHandler<RedirectToWgLoginMessage>
{
private readonly IGraphQlBackendService _graphQlBackendService;
private readonly DialogService _dialogService;
private readonly IStringLocalizer<App> _localizer;
public WargamingLoginService(
IGraphQlBackendService graphQlBackendService,
DialogService dialogService,
IStringLocalizer<App> localizer)
{
_graphQlBackendService = graphQlBackendService;
_dialogService = dialogService;
_localizer = localizer;
}
public async Task Handle(LoginToWgMessage notification, CancellationToken cancellationToken)
{
await _dialogService.OpenAsync<WgLoginDialog>(_localizer.GetString("You're about to login"),
null,
new DialogOptions() { Width = "310px", Height = "530px" });
}
public async Task Handle(RedirectToWgLoginMessage notification, CancellationToken cancellationToken)
{
var url = await _graphQlBackendService.GetWgLoginUrl(notification.Realm);
// ToDo: take a look to redirect message in previous app reincarnation
url = $"{url}&redirect_uri=https://developers.wargaming.net/reference/all/wot/auth/login/";
}
}
}