@page "/redeem/{Token}/" @using System.Net @rendermode @(new InteractiveWebAssemblyRenderMode(false)) @inject IJSRuntime Js @inject NavigationManager navigation @if (_responseCode == null) {

Loading...

} else if (_responseCode == HttpStatusCode.Forbidden) { Invalid invitation! } else if (_responseCode == HttpStatusCode.NoContent) { No template providen by admin. } else if (_responseCode == HttpStatusCode.BadRequest) { An internal error occured. } else { @foreach (var configLine in _config!.Split("\n")) {

@configLine

} } @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>("wireguard.generateKeypair"); var requestBody = new Dictionary { { "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"]); } }