Skip to content

Commit

Permalink
logins for auth servers work, pretty much nothing else
Browse files Browse the repository at this point in the history
  • Loading branch information
DEATHB4DEFEAT committed Jan 17, 2025
1 parent 345e0a9 commit 85f06af
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
8 changes: 7 additions & 1 deletion SS14.Launcher/Api/AuthApi.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
Expand Down Expand Up @@ -27,6 +28,11 @@ public async Task<AuthenticateResult> AuthenticateAsync(AuthenticateRequest requ
try
{
var authUrl = ConfigConstants.AuthUrls[request.Server ?? ConfigConstants.FallbackAuthServer].AuthAuthFullUrl;
if (request.Server == ConfigConstants.CustomAuthServer)
{
authUrl = request.ServerUrl ?? throw new ArgumentException("Custom server selected but no URL provided.");
authUrl += ConfigConstants.TemplateAuthServer.AuthAuthUrl;
}

using var resp = await _httpClient.PostAsJsonAsync(authUrl, request);

Expand All @@ -40,7 +46,7 @@ public async Task<AuthenticateResult> AuthenticateAsync(AuthenticateRequest requ
Token = token,
Username = respJson.Username,
Server = request.Server ?? ConfigConstants.FallbackAuthServer,
ServerUrl = request.Server,
ServerUrl = request.ServerUrl,
});
}

Expand Down
1 change: 1 addition & 0 deletions SS14.Launcher/Assets/Locale/en-US/text.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ login-login-title = Log in
login-login-username-watermark = Username or email
login-login-password-watermark = Password
login-login-show-password = Show Password
login-login-auth-server = Account Provider
login-login-button-log-in = Log in
login-login-button-forgot = Forgot your password?
login-login-button-resend = Resend email confirmation
Expand Down
6 changes: 5 additions & 1 deletion SS14.Launcher/ConfigConstants.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using SS14.Launcher.Utility;
using TerraFX.Interop.Windows;

namespace SS14.Launcher;

Expand Down Expand Up @@ -73,7 +74,10 @@ public class AuthServer(
public string AccountRegFullUrl { get; } = $"{accountSite}{accountRegUrl}";
public string AccountResendFullUrl { get; } = $"{accountSite}{accountResendUrl}";
}

public const string FallbackAuthServer = "Space-Wizards";
public const string CustomAuthServer = "Custom";
public static readonly AuthServer TemplateAuthServer = new(new("https://example.com/"), new("https://example.com/"));
public static readonly Dictionary<string, AuthServer> AuthUrls = new()
{
{
Expand All @@ -85,7 +89,7 @@ public class AuthServer(
new(new("https://auth.spacestation14.com/"), new("https://account.spacestation14.com/"), false)
},
{
"Custom",
CustomAuthServer,
new (new("https://example.com/"), new("https://example.com/"))
},
};
Expand Down
7 changes: 3 additions & 4 deletions SS14.Launcher/Models/Data/DataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,9 @@ public void RemoveEngineModule(InstalledEngineModule module)

public void AddLogin(LoginInfo login)
{
if (_logins.Lookup(login.UserId).HasValue)
{
throw new ArgumentException("A login with that UID already exists.");
}
if (_logins.KeyValues.FirstOrDefault(a =>
a.Key == login.UserId && a.Value.Server == login.Server && a.Value.ServerUrl == login.ServerUrl).Value != null)
throw new ArgumentException("That login already exists.");

_logins.AddOrUpdate(login);
}
Expand Down
13 changes: 10 additions & 3 deletions SS14.Launcher/ViewModels/Login/LoginViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public class LoginViewModel : BaseLoginViewModel
[Reactive] public string Server { get; set; } = ConfigConstants.AuthUrls.First().Key;
[Reactive] public List<string> Servers { get; set; } = ConfigConstants.AuthUrls.Keys.ToList();
[Reactive] public string? ServerUrl { get; set; }
[Reactive] public string ServerUrlPlaceholder { get; set; } = ConfigConstants.AuthUrls.First().Value.AuthUrl.ToString();
[Reactive] public bool IsCustom { get; set; } = false;

[Reactive] public string EditingUsername { get; set; } = "";
[Reactive] public string EditingPassword { get; set; } = "";

Expand All @@ -41,6 +44,8 @@ public LoginViewModel(MainWindowLoginViewModel parentVm, AuthApi authApi,
{
IsInputValid = !string.IsNullOrEmpty(s.Item1) && !string.IsNullOrEmpty(s.Item2)
&& !string.IsNullOrEmpty(s.Item3);
ServerUrlPlaceholder = ConfigConstants.AuthUrls[Server].AuthUrl.ToString();
IsCustom = Server == ConfigConstants.CustomAuthServer;
});
}

Expand Down Expand Up @@ -79,8 +84,10 @@ public static async Task<bool> DoLogin<T>(
if (resp.IsSuccess)
{
var loginInfo = resp.LoginInfo;
var oldLogin = loginMgr.Logins.Lookup(loginInfo.UserId);
if (oldLogin.HasValue)
var oldLogin = loginMgr.Logins.KeyValues.FirstOrDefault(a =>
a.Key == loginInfo.UserId && a.Value.Server == loginInfo.Server
&& a.Value.ServerUrl == loginInfo.ServerUrl).Value;
if (oldLogin != null)
{
// Already had this login, apparently.
// Thanks user.
Expand All @@ -89,7 +96,7 @@ public static async Task<bool> DoLogin<T>(
// This also has the upside of re-available-ing the account
// if the user used the main login prompt on an account we already had, but as expired.

await authApi.LogoutTokenAsync(oldLogin.Value.Server, oldLogin.Value.LoginInfo.Token.Token);
await authApi.LogoutTokenAsync(oldLogin.Server, oldLogin.LoginInfo.Token.Token);
loginMgr.ActiveAccountId = loginInfo.UserId;
loginMgr.UpdateToNewToken(loginMgr.ActiveAccount!, loginInfo.Token);
return true;
Expand Down
25 changes: 15 additions & 10 deletions SS14.Launcher/Views/Login/LoginView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
<DockPanel LastChildFill="False">
<TextBlock HorizontalAlignment="Center" DockPanel.Dock="Top" Classes="NanoHeadingMedium" Text="{loc:Loc login-login-title}" />

<TextBox DockPanel.Dock="Top" Name="NameBox" MaxWidth="300" Margin="0, 10, 0, 0"
<TextBox DockPanel.Dock="Top" Name="NameBox" MaxWidth="500" Margin="0, 10, 0, 0"
Watermark="{loc:Loc login-login-username-watermark}"
Text="{Binding EditingUsername, Mode=TwoWay}" IsEnabled="{Binding !Busy}" />

<TextBox DockPanel.Dock="Top" Name="PasswordBox" MaxWidth="300" Margin="0, 4, 0, 0"
<TextBox DockPanel.Dock="Top" Name="PasswordBox" MaxWidth="500" Margin="0, 4, 0, 0"
Watermark="{loc:Loc login-login-password-watermark}"
Text="{Binding EditingPassword, Mode=TwoWay}" RevealPassword="{Binding IsPasswordVisible}"
PasswordChar=""
Expand All @@ -27,8 +27,11 @@
<CheckBox DockPanel.Dock="Top" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="4"
IsChecked="{Binding IsPasswordVisible}" Content="{loc:Loc login-login-show-password}" />

<!-- Dropdown button that lets you pick between auth servers, plus a custom option -->
<ComboBox DockPanel.Dock="Top" MaxWidth="300" Margin="0, 4, 0, 0"
<TextBlock DockPanel.Dock="Top" HorizontalAlignment="Center" Margin="0, 4, 0, 0"
Text="{loc:Loc login-login-auth-server}" />

<!-- Dropdown button that lets you pick between auth servers, with a Custom option that makes an editable text box appear -->
<ComboBox DockPanel.Dock="Top" MaxWidth="500" Margin="0, 0, 0, 0"
ItemsSource="{Binding Servers}"
SelectedItem="{Binding Server}"
IsEnabled="{Binding !Busy}">
Expand All @@ -39,10 +42,12 @@
</ComboBox.ItemTemplate>
</ComboBox>

<TextBlock DockPanel.Dock="Top" HorizontalAlignment="Center" Margin="0, 4, 0, 0"
Text="{loc:Loc login-login-auth-server}" />
<TextBox DockPanel.Dock="Top" Name="CustomServerBox" MaxWidth="500" Margin="0, 4, 0, 0"
Watermark="{Binding ServerUrlPlaceholder}"
Text="{Binding ServerUrl, Mode=TwoWay}"
IsEnabled="{Binding IsCustom, Mode=OneWay}" />

<DockPanel DockPanel.Dock="Top" LastChildFill="False" MaxWidth="300" Margin="0 20 0 0">
<DockPanel DockPanel.Dock="Top" LastChildFill="False" MaxWidth="500" Margin="0 20 0 0">
<Button DockPanel.Dock="Right" HorizontalAlignment="Center"
Content="{loc:Loc login-login-button-log-in}" Command="{Binding OnLogInButtonPressed}">
<Button.IsEnabled>
Expand All @@ -53,13 +58,13 @@
</Button.IsEnabled>
</Button>

<Button DockPanel.Dock="Left" HorizontalAlignment="Center" Content="{loc:Loc login-login-button-forgot}"
<Button DockPanel.Dock="Left" HorizontalAlignment="Center" Content="{loc:Loc login-login-button-forgot}" Classes="OpenLeft"
Command="{Binding ParentVM.SwitchToForgotPassword}" IsEnabled="{Binding !Busy}" />
</DockPanel>

<DockPanel DockPanel.Dock="Top" LastChildFill="False" MaxWidth="300">
<DockPanel DockPanel.Dock="Top" LastChildFill="False" MaxWidth="500">
<Button DockPanel.Dock="Left" HorizontalAlignment="Center" Content="{loc:Loc login-login-button-resend}"
Command="{Binding ResendConfirmationPressed}"/>
Command="{Binding ResendConfirmationPressed}" />
</DockPanel>

<Button DockPanel.Dock="Bottom" Classes="BigButton" Margin="0 4" HorizontalAlignment="Center"
Expand Down

0 comments on commit 85f06af

Please sign in to comment.