Skip to content

Commit

Permalink
Make login page nicer, and switch api urls
Browse files Browse the repository at this point in the history
  • Loading branch information
LucHeart committed Jun 6, 2024
1 parent 6fa72ed commit b7deb0c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 25 deletions.
2 changes: 1 addition & 1 deletion ShockOsc/Config/OpenShockConf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public sealed class OpenShockConf
{
public Uri Backend { get; set; } = new("https://api.shocklink.net");
public Uri Backend { get; set; } = new("https://api.openshock.app");
public string Token { get; set; } = "";
public IReadOnlyDictionary<Guid, ShockerConf> Shockers { get; set; } = new Dictionary<Guid, ShockerConf>();

Expand Down
4 changes: 2 additions & 2 deletions ShockOsc/ShockOsc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<AssemblyName>OpenShock.ShockOsc</AssemblyName>
<RootNamespace>OpenShock.ShockOsc</RootNamespace>
<Company>OpenShock</Company>
<AssemblyVersion>2.0.1</AssemblyVersion>
<Version>2.0.1</Version>
<AssemblyVersion>2.1.0</AssemblyVersion>
<Version>2.1.0-rc.1</Version>
<ApplicationIcon>Resources\openshock-icon.ico</ApplicationIcon>
<SelfContained>true</SelfContained>
<Product>ShockOsc</Product>
Expand Down
22 changes: 11 additions & 11 deletions ShockOsc/Ui/Pages/Authentication/Authenticate.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@

@page "/"

<MudContainer Class="d-flex align-content-center" Style="padding: 0 0 15px 0;">
<MudContainer Style="width: 600px; padding: 0;">
<MudImage Src="images/Icon.svg" Alt="Logo" Width="75" Height="75" Class="ma-4" Style="vertical-align: bottom;"/>
<MudContainer Class="d-inline-block" Style="width: 485px; padding: 0;">
<MudText Typo="Typo.h1">ShockOSC</MudText>
</MudContainer>
</MudContainer>
</MudContainer>



<MudContainer Class="align-content-center" MaxWidth="MaxWidth.Small" Style="padding-top: 30px">
<MudPaper Class="rounded-lg" Elevation="0" Style="padding: 40px 20px; text-align: center;" Outlined="true">
<MudText Typo="Typo.h2">Login</MudText>
<br/>
<MudPaper Class="rounded-lg" Elevation="0" Style="padding: 20px; text-align: center;" Outlined="true">

<MudContainer Class="d-flex" Style="padding: 0">
<MudImage Src="images/Icon.svg" Alt="Logo" Width="75" Height="75" Class="ma-4" Style="vertical-align: bottom;"/>
<MudText Class="d-inline-block flex-grow-1 pa-0" Style="font-size: 5em;">ShockOSC</MudText>
</MudContainer>

<div style="margin-top: 20px;">

@switch (_currentState)
{
case State.Login:
Expand All @@ -43,6 +42,7 @@
<MudText Typo="Typo.h6">Successful, redirecting...</MudText>
break;
}
</div>
</MudPaper>
</MudContainer>

Expand Down
41 changes: 30 additions & 11 deletions ShockOsc/Ui/Pages/Authentication/LoginPart.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
@using System.Net.Http.Json
@using System.Reflection
@using System.Runtime.InteropServices
@using Microsoft.Extensions.Logging
@using OneOf.Types
@using OpenShock.SDK.CSharp.Models
@using OpenShock.SDK.CSharp.Utils
@using OpenShock.ShockOsc.Backend
@using OpenShock.ShockOsc.Config
@using OpenShock.ShockOsc.Utils
Expand All @@ -12,13 +15,9 @@
@inject ILogger<LoginPart> Logger

<div class="d-flex">
<MudButton Class="get-token-button" Variant="Variant.Filled" Color="Color.Primary" OnClick="GetToken">Get Token</MudButton>
<MudTextField @bind-Value="ConfigManager.Config.OpenShock.Token" Label="API Token" Variant="Variant.Outlined"></MudTextField>
<MudButton Class="get-token-button" Style="width: 1000px; height: 100px; font-size: 2rem" Variant="Variant.Filled" Color="Color.Primary" OnClick="GetToken">Login with OpenShock</MudButton>
</div>
<br/>
<MudButton OnClick="Login" Variant="Variant.Filled" Color="Color.Primary">Continue</MudButton>
<br/>
<br/>
<br/>
<MudPaper Outlined="true" Class="rounded-lg mud-paper-padding d-flex" Style="flex-direction: column">
<div>
Expand All @@ -36,25 +35,30 @@
@if (!_useCustomServerDialog)
{
<MudSelect T="BackendServer" Label="Server" @bind-Value="Server" Variant="Variant.Outlined" AnchorOrigin="Origin.BottomCenter">
<MudSelectItem T="BackendServer" Value="BackendServer.Production"><span class="server-url-backdrop">https://api.shocklink.net/</span> (Production)</MudSelectItem>
<MudSelectItem T="BackendServer" Value="BackendServer.Staging"><span class="server-url-backdrop">https://api-staging.shocklink.net/</span> (Staging)</MudSelectItem>
<MudSelectItem T="BackendServer" Value="BackendServer.Production"><span class="server-url-backdrop">https://api.openshock.app/</span> (Production)</MudSelectItem>
<MudSelectItem T="BackendServer" Value="BackendServer.Staging"><span class="server-url-backdrop">https://api-staging.openshock.app/</span> (Staging)</MudSelectItem>
@if (_customServerUri != null)
{
<MudSelectItem T="BackendServer" Value="BackendServer.Custom"><span class="server-url-backdrop">@_customServerUri</span> (Custom)</MudSelectItem>
}
</MudSelect>

<br/>
<MudButton OnClick="() => _useCustomServerDialog = true" Color="Color.Primary">Use custom server</MudButton>
}
else
{
<MudTextField @bind-Value="_server" Error="@ValidateCustomServerBool()" Label="Custom Server" Variant="Variant.Outlined"></MudTextField>
<br/>

<MudButton OnClick="() => _useCustomServerDialog = false" Variant="Variant.Filled" Color="Color.Primary">Back</MudButton>
<MudButton OnClick="SaveCustomServer" Variant="Variant.Filled" Color="Color.Primary" Disabled="@ValidateCustomServerBool()">Save</MudButton>
}

<br/>
<MudTextField @bind-Value="ConfigManager.Config.OpenShock.Token" Label="API Token" Variant="Variant.Outlined"></MudTextField>
<br/>
<MudButton OnClick="Login" Color="Color.Primary">Continue with Token</MudButton>
</MudCollapse>

</MudPaper>
Expand Down Expand Up @@ -150,8 +154,8 @@

private struct UriIsNotValid;

private const string ProductionServerString = "https://api.shocklink.net/";
private const string StagingServerString = "https://staging-api.shocklink.net/";
private const string ProductionServerString = "https://api.openshock.app/";
private const string StagingServerString = "https://staging-api.openshock.app/";

private static Uri _productionServer = new(ProductionServerString);
private static Uri _stagingServer = new(StagingServerString);
Expand All @@ -165,10 +169,12 @@
{
Logger.LogTrace("Get API info");
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("User-Agent", "ShockOSC-Internal/1.0");
httpClient.BaseAddress = ConfigManager.Config.OpenShock.Backend;
var response = await httpClient.GetAsync("1");
if (!response.IsSuccessStatusCode)
{
Logger.LogError("Failed to reach API, status code: {StatusCode}", response.StatusCode);
Snackbar.Add("Failed to reach API", Severity.Error);
return;
}
Expand All @@ -186,6 +192,19 @@
var requestUri = new Uri(root.Data!.ShortLinkUrl, "/t/?name=ShockOSC&redirect_uri=shockosc:token/%&permissions=shockers.use");
UiUtils.OpenUrl(requestUri.ToString());
}

private string GetUserAgent()
{
var shockOscVersion = GetType().Assembly.GetName().Version!;


var runtimeVersion = RuntimeInformation.FrameworkDescription;
if (string.IsNullOrEmpty(runtimeVersion)) runtimeVersion = "Unknown Runtime";

return
$"OpenShock.ShockOsc/{shockOscVersion.Major}.{shockOscVersion.Minor}.{shockOscVersion.Build} " +
$"({runtimeVersion}; {UserAgentUtils.GetOs()}; ShockOscInternals)";
}

public sealed class RootResponse
{
Expand Down

0 comments on commit b7deb0c

Please sign in to comment.