From c97cfabfa4c802fbc2c3738c0691a648dafa8891 Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Wed, 2 Jul 2025 11:59:22 +0200 Subject: [PATCH] feat: add user authentication flow and configuration management --- src/lib/config.ts | 6 +- src/lib/userAuthentication.ts | 7 +-- src/lib/userSettings.ts | 2 +- src/pages/Launch.svelte | 19 +++--- src/pages/Loading.svelte | 26 ++++++++ src/pages/Login.svelte | 109 ++++++++++++++++++++++++++++++---- src/routes/+layout.svelte | 2 + 7 files changed, 145 insertions(+), 26 deletions(-) diff --git a/src/lib/config.ts b/src/lib/config.ts index 03da831..27034f9 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -4,12 +4,14 @@ import { invoke } from '@tauri-apps/api/core'; import { Crypto } from './crypto'; export class Config { + private fileName: string; private config: Record = {}; private crypto: Crypto | undefined; private configFilePath: string | undefined; private encrypt: boolean; - constructor(encrypt?: boolean) { + constructor(fileName: string, encrypt?: boolean) { + this.fileName = fileName; this.encrypt = encrypt ?? false; } @@ -20,7 +22,7 @@ export class Config { const homeDir = await path.homeDir(); const folderPath = await path.join(homeDir, '.ezpplauncher'); - this.configFilePath = await path.join(folderPath, 'user_settings'); + this.configFilePath = await path.join(folderPath, this.fileName); const createFolder = !(await exists(folderPath)); if (createFolder) await mkdir(folderPath); diff --git a/src/lib/userAuthentication.ts b/src/lib/userAuthentication.ts index c74c681..3d2a068 100644 --- a/src/lib/userAuthentication.ts +++ b/src/lib/userAuthentication.ts @@ -1,7 +1,6 @@ import { writable } from 'svelte/store'; import { Config } from './config'; +import type { EZPPUser } from './types'; -export const userAuth = writable(new Config(true)); - -export const username = writable(""); -export const password = writable("") +export const userAuth = writable(new Config("user_auth", true)); +export const currentUser = writable(undefined); diff --git a/src/lib/userSettings.ts b/src/lib/userSettings.ts index aad5757..f6c1fe8 100644 --- a/src/lib/userSettings.ts +++ b/src/lib/userSettings.ts @@ -1,7 +1,7 @@ import { writable } from 'svelte/store'; import { Config } from './config'; -export const userSettings = writable(new Config(false)); +export const userSettings = writable(new Config('user_settings', false)); export const customCursor = writable(true); export const cursorSmoothening = writable(true); diff --git a/src/pages/Launch.svelte b/src/pages/Launch.svelte index a556575..1b61350 100644 --- a/src/pages/Launch.svelte +++ b/src/pages/Launch.svelte @@ -4,14 +4,12 @@ import Badge from '@/components/ui/badge/badge.svelte'; import Button from '@/components/ui/button/button.svelte'; import * as Select from '@/components/ui/select'; - import { beatmap_sets, online_friends, server_connection_fails, server_ping } from '@/global'; - import { WebviewWindow } from '@tauri-apps/api/webviewWindow'; + import { beatmap_sets, current_view, server_connection_fails, server_ping } from '@/global'; import { LoaderCircle, Logs, Music2, Play, - Users, Wifi, Gamepad2, WifiOff, @@ -22,7 +20,7 @@ import * as AlertDialog from '@/components/ui/alert-dialog'; import Progress from '@/components/ui/progress/progress.svelte'; import { numberHumanReadable } from '@/utils'; - import { fade, fly, scale } from 'svelte/transition'; + import { scale } from 'svelte/transition'; import { Checkbox } from '@/components/ui/checkbox'; import Label from '@/components/ui/label/label.svelte'; import { @@ -36,6 +34,8 @@ import { open } from '@tauri-apps/plugin-dialog'; import { invoke } from '@tauri-apps/api/core'; import { toast } from 'svelte-sonner'; + import Login from './Login.svelte'; + import { currentUser } from '@/userAuthentication'; let selectedTab = $state('home'); let launching = $state(false); @@ -85,14 +85,17 @@
- + - Quetzalcoatl + {$currentUser?.name ?? 'Guest'}
- Owner + + {#if !$currentUser} + + {/if}
@@ -402,7 +405,7 @@ }} >
- EZPPLauncher Settings + osu! Settings
{ await calculateCursorSmoothness(); + + const username = $userAuth.value('username').get(''); + const password = $userAuth.value('password').get(''); + + try { + const loginResult = await ezppfarm.login(username, password); + if (loginResult && loginResult.user) { + toast.success('Login successful!', { + description: `Welcome back, ${loginResult.user.name}!`, + }); + + currentUser.set(loginResult.user); + } else { + toast.error('Login failed!', { + description: 'Please check your username and password.', + }); + } + } catch { + toast.error('Server error occurred during login.', { + description: 'There was an issue connecting to the server. Please try again later.', + }); + } + animate(ezppLogo, { opacity: [1, 0], scale: [1, 1.05], diff --git a/src/pages/Login.svelte b/src/pages/Login.svelte index 4c4344c..c25b009 100644 --- a/src/pages/Login.svelte +++ b/src/pages/Login.svelte @@ -1,28 +1,115 @@ + +
+
+ EZPPLauncher Logo +
+
+ + +
+
+ + +
+ +
+
+
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 63065dd..56b7e98 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -13,6 +13,7 @@ } from '@/userSettings'; import { Buffer } from 'buffer'; import { Toaster } from '@/components/ui/sonner'; + import { userAuth } from '@/userAuthentication'; let { children } = $props(); function disableReload() { @@ -68,6 +69,7 @@ disableReload(); setupValues(); const firstStartup = await $userSettings.init(); + $userAuth.init(); const config_custom_cursor = $userSettings.value('custom_cursor'); const config_cursor_smoothening = $userSettings.value('cursor_smoothening');