diff options
Diffstat (limited to 'ShareGuard.Web.Client/Pages')
| -rw-r--r-- | ShareGuard.Web.Client/Pages/Redeem.razor | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/ShareGuard.Web.Client/Pages/Redeem.razor b/ShareGuard.Web.Client/Pages/Redeem.razor new file mode 100644 index 0000000..d6abc95 --- /dev/null +++ b/ShareGuard.Web.Client/Pages/Redeem.razor @@ -0,0 +1,53 @@ +@page "/redeem/{Token}/" +@using System.Net +@rendermode @(new InteractiveWebAssemblyRenderMode(false)) +@inject IJSRuntime Js +@inject NavigationManager navigation + +@if (_responseCode == null) +{ + <p>Loading...</p> +} +else if (_responseCode == HttpStatusCode.Forbidden) +{ + <b>Invalid invitation!</b> +} +else if (_responseCode == HttpStatusCode.NoContent) +{ + <b>No template providen by admin.</b> +} +else if (_responseCode == HttpStatusCode.BadRequest) +{ + <b>An internal error occured.</b> +} +else +{ + @foreach (var configLine in _config!.Split("\n")) + { + <p>@configLine</p> + } +} + +@code { + private readonly HttpClient _httpClient = new(); + [Parameter] public string Token { get; set; } + private HttpStatusCode? _responseCode; + private string? _config; + + protected override async Task OnInitializedAsync() + { + var keypair = await Js.InvokeAsync<Dictionary<string, string>>("wireguard.generateKeypair"); + var requestBody = new Dictionary<string, string> + { + { "PublicKey", keypair["publicKey"] } + }; + var response = await _httpClient.PostAsync($"{navigation.BaseUri}api/redeem/{Token}/", new FormUrlEncodedContent(requestBody)); + _responseCode = response.StatusCode; + var template = await response.Content.ReadAsStringAsync(); + + if (_responseCode == HttpStatusCode.OK) + _config = template.Replace("{publicKey}", keypair["publicKey"]) + .Replace("{privateKey}", keypair["privateKey"]); + } + +} |
