Compare commits

..

9 Commits

Author SHA1 Message Date
3dda2fefc2 feat: Create authorization 2026-01-18 22:16:50 +01:00
TeamCity
6b8488e7a4 ci: bump version to v0.23.0 2026-01-13 13:36:42 +00:00
6c914b1421 feat(ui): Tie selection (#26)
Added a minimal ui for the tie selection. Tie selection gets sent to the server via websocket and gets response from it.

Co-authored-by: LQ63 <lkhermann@web.de>
Reviewed-on: #26
2026-01-13 14:33:35 +01:00
TeamCity
8482aa8876 ci: bump version to v0.22.0 2026-01-07 21:37:08 +00:00
c6537467f8 feat: Update LobbyComponent to use icons for player removal buttons 2026-01-07 22:34:23 +01:00
TeamCity
3eb505806c ci: bump version to v0.21.0 2026-01-07 21:05:21 +00:00
058d232d2b feat: Implement PlayDogCard functionality in user session and update Vue component 2026-01-07 22:02:21 +01:00
TeamCity
67dcf6274c ci: bump version to v0.20.0 2026-01-07 20:45:36 +00:00
02869fff8b feat: Enhance user state management with polling and WebSocket connection handling 2026-01-07 21:43:17 +01:00
17 changed files with 970 additions and 32 deletions

View File

@@ -145,3 +145,23 @@
### Features
* Update joinGame endpoint to accept gameId as a path parameter ([92a7bc0](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Frontend/commit/92a7bc05866b77053ebb1d074ad207be8348f9d6))
## [0.0.0](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Frontend/compare/0.19.0...0.0.0) (2026-01-07)
### Features
* Enhance user state management with polling and WebSocket connection handling ([02869ff](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Frontend/commit/02869fff8b448cde73369679c9b38bc99fb771ff))
## [0.0.0](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Frontend/compare/0.20.0...0.0.0) (2026-01-07)
### Features
* Implement PlayDogCard functionality in user session and update Vue component ([058d232](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Frontend/commit/058d232d2ba00f33b1e658fc8a793dcd59018fa4))
## [0.0.0](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Frontend/compare/0.21.0...0.0.0) (2026-01-07)
### Features
* Update LobbyComponent to use icons for player removal buttons ([c653746](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Frontend/commit/c6537467f87d60aeece18f86f42c839d5437c18b))
## [0.0.0](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Frontend/compare/0.22.0...0.0.0) (2026-01-13)
### Features
* **ui:** Tie selection ([#26](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Frontend/issues/26)) ([6c914b1](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Frontend/commit/6c914b1421030897d47449087dd1694068e84436))

View File

@@ -1,8 +1,16 @@
<script setup lang="ts">
import { RouterView } from 'vue-router'
import { onMounted, onUnmounted } from 'vue';
import { useRoute } from 'vue-router';
import { onMounted, onUnmounted, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useUserInfo } from "@/composables/useUserInfo";
import { useIngame } from "@/composables/useIngame";
import { storeToRefs } from "pinia";
import { useWebSocket } from "@/composables/useWebsocket";
import { useQuasar } from "quasar";
const route = useRoute();
const router = useRouter();
const info = useUserInfo();
const handleOnlineStatusChange = () => {
if (navigator.onLine) {
@@ -11,12 +19,84 @@ const handleOnlineStatusChange = () => {
}
}
};
let interval: number | null = null;
onMounted(() => {
window.addEventListener('online', handleOnlineStatusChange);
// Continuously check user state every 10 seconds
interval = window.setInterval(async () => {
if (navigator.onLine && route.name !== 'login' && route.name !== 'offline') {
await info.requestState();
if (!info.username && route.name !== 'login') {
router.push({ name: 'login' });
}
}
}, 10000);
});
onUnmounted(() => {
window.removeEventListener('online', handleOnlineStatusChange);
if (interval) {
clearInterval(interval);
}
});
watch(() => info.gameId, (newGameId) => {
if (newGameId && route.name !== 'game') {
router.push({ name: 'game' });
}
});
const ig = useIngame()
const { isWsConnected } = storeToRefs(ig)
const wb = useWebSocket()
const $q = useQuasar();
watch(isWsConnected, (connected) => {
if (!connected && info.gameId && route.name === 'game') {
showReconnectDialog();
}
});
function showReconnectDialog() {
$q.dialog({
title: 'Connection Lost',
message: 'The connection to the game server was lost. Would you like to reconnect?',
persistent: true,
ok: {
label: 'Reconnect',
color: 'positive'
},
cancel: {
label: 'Quit',
color: 'negative'
}
}).onOk(() => {
reconnect();
}).onCancel(() => {
router.replace("/");
});
}
async function reconnect() {
try {
await wb.connect();
$q.notify({
message: 'Reconnected successfully!',
color: 'positive',
icon: 'check'
});
} catch (err) {
$q.notify({
message: 'Failed to reconnect. Please try again.',
color: 'negative',
icon: 'error'
});
showReconnectDialog();
}
}
</script>
<template>

View File

@@ -10,6 +10,7 @@ import TurnC from "@/components/ingame/TurnC.vue";
import TrumpC from "@/components/ingame/TrumpC.vue";
import {storeToRefs} from "pinia";
import {ref, toRefs, watch} from "vue";
import TieC from "@/components/ingame/TieC.vue";
const ig = useIngame()
const { state } = toRefs(ig)
@@ -45,6 +46,22 @@ watch(
<TrumpC />
</div>
</transition>
<transition
appear
enter-active-class="animate__animated animate__fadeInDown"
leave-active-class="animate__animated animate__fadeOutDown"
>
<div
v-if="state === 'TieBreak'"
class="full-overlay-blur"
style="z-index: 2000;"
>
<TieC />
</div>
</transition>
<div class="fit row wrap justify-center items-center content-start">
<div class="mt-5 ml-4 self-start col-2">
<TurnC v-if="(cachedGameInfo as GameInfo)?.playerQueue" :queue="(cachedGameInfo as GameInfo).playerQueue!"/>

View File

@@ -25,9 +25,8 @@ function triggerWiggle(index: number) {
function handlePlayCard(index: number | null) {
if (index === null) return
wb.sendAndWait("PlayCard", { cardindex: index }).catch((error) => {
wb.sendAndWait((<GameInfo>wi.data)?.self?.dogLife ? "PlayDogCard" : "PlayCard", { cardindex: index }).catch((error) => {
triggerWiggle(index)
$q.notify({
message: error.message,
color: "negative",
@@ -45,7 +44,13 @@ function onBeforeLeave(el: Element) {
element.style.height = height;
}
function handleSkipDogLife() {
//TODO: Add some animation or feedback for skipping turn
wb.sendAndWait("PlayDogCard", { cardindex: 'Skip' }).catch((error) => {
$q.notify({
message: error.message,
color: "negative",
position: "top"
})
})
}
function getCardImagePath(cardPath: string) {

View File

@@ -0,0 +1,98 @@
<script setup lang="ts">
import {useWebSocket} from "@/composables/useWebsocket.ts";
import {useIngame} from "@/composables/useIngame.ts";
import type {GameInfo, LobbyInfo, TieInfo, TrumpInfo} from "@/types/GameTypes.ts";
import {useQuasar} from "quasar";
import { ref } from 'vue';
import { computed } from 'vue'
const wb = useWebSocket()
const wi = useIngame()
const tieInf = computed(() => wi.data as TieInfo)
const tieBlankCard = [
"/images/cards/AS.png"
]
const $q = useQuasar();
function getCardImagePath(cardPath: string) {
if (!cardPath) return ''
if (cardPath.includes('://') || cardPath.startsWith('/')) return cardPath
return `/${cardPath}`
}
function selectTie(tieIndex: number) {
wb.sendAndWait("PickTie", { cardIndex: tieIndex }).then(
$q.notify({
message: "You've successfully picked your tieCard",
color: "positive",
position: "top"
})
).catch((error) => {
$q.notify({
message: error.message,
color: "negative",
position: "top"
})
})
}
const model = ref(1)
const options = computed(() => {
const list = []
const max = tieInf.value.highestAmount?.valueOf() || 0
for (let i = 1; i <= max; i++) {
list.push(i)
}
return list
})
</script>
<template>
<q-card v-if="tieInf.self?.name === tieInf.currentPlayer?.name" class="player-profile-card" flat bordered>
<q-card-section class="bg-white text-dark text-center q-py-lg">
<div class="text-h3 text-weight-bolder">
{{ tieInf.self?.name || "Loading Player..."}}
</div>
</q-card-section>
<q-card-section class="bg-dark text-dark text-center q-py-lg">
<div class="q-pa-md" style="max-width: 500px">
<div class="q-gutter-md">
<q-select
v-model="model"
:options="options"
label="Select Amount"
filled
bg-color="white"
label-color="primary"
color="primary"
popup-content-class="bg-white text-black"
/>
<q-btn
color="positive"
icon="sports_martial_arts"
@click="selectTie(model)"
class="full-width"
/>
</div>
</div>
</q-card-section>
</q-card>
<q-card
v-else
class="player-profile-card text-center"
flat
bordered
style="min-height: 200px; display: flex; flex-direction: column; justify-content: center;"
>
<q-card-section class="q-pa-lg">
<q-spinner-hourglass color="black" size="3em" class="q-mb-md" />
<div class="text-h5 text-grey-8">
Waiting for {{ tieInf.currentPlayer?.name || 'the other player' }} to select card for the tie...
</div>
</q-card-section>
</q-card>
</template>
<style scoped>
</style>

View File

@@ -103,14 +103,14 @@ const profileIcon = 'person';
<q-btn
v-if="player.id !== (<LobbyInfo>ig.data).self.id"
color="negative"
label="Remove"
icon="sports_martial_arts"
@click="handleKickPlayer(player)"
class="full-width"
/>
<q-btn
v-else
color="negative"
label="Remove (Cannot Kick Self)"
icon="sports_martial_arts"
disable
class="full-width"
/>

View File

@@ -9,12 +9,17 @@ const api = window?.__RUNTIME_CONFIG__?.API_URL;
export const useIngame = defineStore('ingame', () => {
const state: Ref<'Lobby' | 'InGame' | 'SelectTrump' | 'TieBreak' | 'FinishedMatch' | null> = ref(null);
const data: Ref<GameInfo | LobbyInfo | TieInfo | TrumpInfo | WonInfo | null> = ref(null);
const isWsConnected: Ref<boolean> = ref(false);
function setIngame(newState: 'Lobby' | 'InGame' | 'SelectTrump' | 'TieBreak' | 'FinishedMatch', newData: GameInfo | LobbyInfo | TieInfo | TrumpInfo | WonInfo) {
state.value = newState;
data.value = newData;
}
function setWsConnected(connected: boolean) {
isWsConnected.value = connected;
}
async function requestGame(gameId: string) {
await axios.get(`${api}/status/${gameId}`, {withCredentials: true}).then((response) => {
setIngame(response.data.state, response.data.data);
@@ -24,7 +29,8 @@ export const useIngame = defineStore('ingame', () => {
function clearIngame() {
state.value = null;
data.value = null;
isWsConnected.value = false;
}
return { state, data, requestGame, setIngame, clearIngame };
return { state, data, isWsConnected, requestGame, setIngame, clearIngame, setWsConnected };
});

View File

@@ -21,10 +21,19 @@ export const useUserInfo = defineStore('userInfo', () => {
async function requestState() {
await axios.get(`${api}/status`, {withCredentials: true}).then((response) => {
console.log("STATUS DATA:" + response.data.status + response.data.inGame)
if (response.data.status === 'authenticated') {
username.value = response.data.username;
userId.value = response.data.userId;
if (response.data.gameId) {
console.log("GAMEID:" + response.data.gameId)
gameId.value = response.data.gameId;
} else {
gameId.value = null;
}
} else {
username.value = null;
userId.value = null;
gameId.value = null;
}
})
}

View File

@@ -1,5 +1,7 @@
import { createRouter, createWebHistory } from 'vue-router'
import LoginView from '../views/LoginView.vue'
import RegisterView from '../views/RegisterView.vue'
import UsernameSelectionView from '../views/UsernameSelectionView.vue'
import MainMenuView from '../views/MainMenuView.vue'
import createGameView from '../views/CreateGame.vue'
import joinGameView from "@/views/JoinGameView.vue";
@@ -51,6 +53,18 @@ const router = createRouter({
component: LoginView,
meta: { requiresAuth: false }
},
{
path: '/register',
name: 'register',
component: RegisterView,
meta: { requiresAuth: false }
},
{
path: '/select-username',
name: 'select-username',
component: UsernameSelectionView,
meta: { requiresAuth: false }
},
{
path: '/game',
name: 'game',
@@ -73,8 +87,12 @@ router.beforeEach(async (to, from, next) => {
if (isOnline) {
try {
const response = await axios.get(`${api}/userInfo`, { withCredentials: true });
info.setUserInfo(response.data.username, response.data.userId);
await info.requestState();
if (!info.username) {
info.clearUserInfo();
return next('/login');
}
return next({ name: 'mainmenu' });
@@ -92,11 +110,17 @@ router.beforeEach(async (to, from, next) => {
if (!to.meta.requiresAuth) return next();
try {
await axios.get(`${api}/userInfo`, { withCredentials: true }).then(
res => {
info.setUserInfo(res.data.username, res.data.userId);
await info.requestState();
if (!info.username) {
info.clearUserInfo();
return next('/login');
}
);
if (info.gameId && to.name !== 'game') {
return next({ name: 'game' });
}
next();
} catch (err) {
info.clearUserInfo();

View File

@@ -160,14 +160,15 @@ function setupSocketHandlers(socket: WebSocket) {
stopHeartbeat();
failAllPending("WebSocket closed");
if (uState) {
uState.setWsConnected(false);
}
if (ev.wasClean) {
console.log(`[WS] Closed cleanly: code=${ev.code} reason=${ev.reason}`);
} else {
console.warn("[WS] Connection died");
}
// You redirect here — if you dont want auto reconnect, keep as is.
router.replace("/");
};
}
@@ -191,6 +192,9 @@ export function connectWebSocket(url?: string): Promise<void> {
const prevOnError = ws!.onerror;
ws!.onopen = (ev) => {
if (prevOnOpen) prevOnOpen.call(ws!, ev);
if (uState) {
uState.setWsConnected(true);
}
resolve();
};
ws!.onerror = (err) => {
@@ -207,6 +211,9 @@ export function connectWebSocket(url?: string): Promise<void> {
return new Promise((resolve, reject) => {
ws!.onopen = () => {
console.log("[WS] Connected");
if (uState) {
uState.setWsConnected(true);
}
startHeartbeat();
resolve();
};
@@ -224,6 +231,9 @@ export function disconnectWebSocket(code = 1000, reason = "Client disconnect") {
ws.close(code, reason);
} catch {}
ws = null;
if (uState) {
uState.setWsConnected(false);
}
}
}

View File

@@ -3,6 +3,7 @@ import { ref } from 'vue';
import { useQuasar } from 'quasar';
import { useRouter } from 'vue-router';
import axios from "axios";
import {useUserInfo} from "@/composables/useUserInfo";
const api = window?.__RUNTIME_CONFIG__?.API_URL;
const lobbyName = ref('');
@@ -11,13 +12,14 @@ const playerAmount = ref(2);
const $q = useQuasar();
const isLoading = ref(false);
const router = useRouter();
const info = useUserInfo();
const createGameQuasar = async () => {
if (!lobbyName.value) {
$q.notify({ message: 'Lobby-Name wird benötigt', color: 'red', position: 'top', icon: 'cancel' });
return;
}
isLoading.value = true;
axios.post(`${api}/createGame`, {lobbyname: lobbyName.value, playeramount: playerAmount.value.toString()}, {withCredentials: true}).then((response) => {
axios.post(`${api}/createGame`, {lobbyname: lobbyName.value, playeramount: playerAmount.value.toString()}, {withCredentials: true}).then(async (response) => {
const responseData = response.data
console.log("Response" + responseData.status)
$q.notify({
@@ -26,12 +28,12 @@ const createGameQuasar = async () => {
icon: 'check_circle',
position: 'top'
});
await info.requestState();
router.replace("/game")
}).catch((err) => {
console.log("ERROR:" + err)
}).finally(() =>
isLoading.value = false
)
})
}
</script>

View File

@@ -7,6 +7,7 @@ import LobbyComponent from "@/components/lobby/LobbyComponent.vue";
import {storeToRefs} from "pinia";
import {useQuasar} from "quasar";
import router from "@/router";
import {ref, watch} from "vue";
const wb = useWebSocket()
const ig = useIngame()
@@ -20,7 +21,6 @@ ui.requestState().then(() => {
$q.notify({
message: "You're not in any game!",
color: "negative"
})
router.replace("/")
} else {
@@ -33,7 +33,7 @@ ui.requestState().then(() => {
<template>
<div class="lobby-background">
<Ingame v-if="state === 'InGame' || state === 'SelectTrump'"/>
<Ingame v-if="state === 'InGame' || state === 'SelectTrump' || state === 'TieBreak'"/>
<lobby-component v-if="state === 'Lobby'"/>
</div>
</template>

View File

@@ -1,13 +1,24 @@
<script setup lang="ts">
import {ref} from "vue";
import {ref, onUnmounted} from "vue";
import { useRouter } from 'vue-router';
import {useQuasar} from "quasar";
import axios from "axios";
import {useUserInfo} from "@/composables/useUserInfo";
const router = useRouter();
const info = useUserInfo();
const lobbyCode = ref('');
const isLoading = ref(false);
const $q = useQuasar();
const api = window?.__RUNTIME_CONFIG__?.API_URL;
let pollInterval: number | null = null;
onUnmounted(() => {
if (pollInterval) {
clearInterval(pollInterval);
}
});
const startGameQuasar = async() => {
if (!lobbyCode.value) {
$q.notify({ message: 'Lobby-Name wird benötigt', color: 'red', position: 'top', icon: 'cancel' });
@@ -21,7 +32,18 @@ const startGameQuasar = async() => {
icon: 'check_circle',
position: 'top'
});
router.replace("/game")
// Start polling until gameId is set
pollInterval = window.setInterval(async () => {
await info.requestState();
if (info.gameId) {
if (pollInterval) {
clearInterval(pollInterval);
pollInterval = null;
}
}
}, 100);
}).catch(() => {
$q.notify({
message: `Lobby "${lobbyCode.value}" nicht gefunden`,
@@ -29,9 +51,8 @@ const startGameQuasar = async() => {
icon: 'cancel',
position: 'top'
})
}).finally(() =>
isLoading.value = false
)
})
}
</script>

View File

@@ -48,6 +48,42 @@
<div class="row justify-center">
<q-btn type="submit" label="Login" push color="dark" />
</div>
<div class="row justify-center q-mt-md">
<div class="text-center">
<p class="text-white text-caption">Or continue with:</p>
<div class="row q-gutter-sm justify-center">
<q-btn
@click="loginWithProvider('discord')"
color="#5865F2"
text-color="white"
icon="mdi-discord"
label="Discord"
outline
size="sm"
/>
<q-btn
@click="loginWithProvider('keycloak')"
color="#0088CC"
text-color="white"
icon="mdi-key"
label="Keycloak"
outline
size="sm"
/>
</div>
</div>
</div>
<div class="row justify-center q-mt-md">
<q-btn
flat
color="white"
label="Don't have an account? Register"
@click="goToRegister"
size="sm"
/>
</div>
</q-form>
</div>
<vue-particles
@@ -88,6 +124,14 @@ const onSubmit = () => {
)
}
const loginWithProvider = (provider: string) => {
window.location.href = `${api}/auth/${provider}`
}
const goToRegister = () => {
router.push('/register')
}
const options = {
"particles": {
"number": {

306
src/views/RegisterView.vue Normal file
View File

@@ -0,0 +1,306 @@
<template>
<div class="register-box q-col-gutter-sm">
<div class="text-h3 text-center row">
<img src="/logo.png" alt="Logo" style="height: 60px; margin-right: 10px;" />
</div>
<h1 class="text-h5 text-center text-white q-mb-md">Create Account</h1>
<q-form @submit.prevent="onSubmit"
class="q-gutter-md row justify-center"
style="width: 100%">
<div class="row q-col-gutter-sm" style="width: 100%">
<q-input
style="width: 100%"
filled
dark
label-color="white"
color="white"
v-model="username"
label="Username *"
:error="!!errorMessage"
:error-message="errorMessage"
lazy-rules
:rules="[
val => !!val && val.trim().length > 0 || 'Username is required',
val => val && val.trim().length >= 3 || 'Username must be at least 3 characters',
val => val && val.trim().length <= 30 || 'Username must be less than 30 characters',
val => /^[a-zA-Z0-9_-]+$/.test(val) || 'Username can only contain letters, numbers, underscores, and hyphens'
]"
/>
</div>
<div class="row q-col-gutter-sm" style="width: 100%">
<q-input
style="width: 100%"
filled
dark
type="password"
label-color="white"
color="white"
v-model="password"
label="Password *"
:error="!!errorMessage"
:error-message="errorMessage"
lazy-rules
:rules="[
val => !!val || 'Password is required',
val => val && val.length >= 6 || 'Password must be at least 6 characters'
]"
/>
</div>
<div class="row q-col-gutter-sm" style="width: 100%">
<q-input
style="width: 100%"
filled
dark
type="password"
label-color="white"
color="white"
v-model="confirmPassword"
label="Confirm Password *"
:error="!!errorMessage"
:error-message="errorMessage"
lazy-rules
:rules="[
val => !!val || 'Password confirmation is required',
val => val === password || 'Passwords do not match'
]"
/>
</div>
<div class="row justify-center">
<q-btn type="submit" label="Register" push color="dark" :loading="inProgress" />
</div>
<div class="row justify-center q-mt-md">
<div class="text-center">
<p class="text-white text-caption">Or register with:</p>
<div class="row q-gutter-sm justify-center">
<q-btn
@click="loginWithProvider('discord')"
color="#5865F2"
text-color="white"
icon="mdi-discord"
label="Discord"
outline
size="sm"
/>
<q-btn
@click="loginWithProvider('keycloak')"
color="#0088CC"
text-color="white"
icon="mdi-key"
label="Keycloak"
outline
size="sm"
/>
</div>
</div>
</div>
<div class="row justify-center">
<q-btn
flat
color="white"
label="Already have an account? Login"
@click="goToLogin"
size="sm"
/>
</div>
</q-form>
</div>
<vue-particles
id="particles-js"
:options='options'
/>
</template>
<script lang="ts" setup>
import { useQuasar } from 'quasar'
import { ref } from 'vue'
import axios from "axios"
import router from "@/router"
const api = window?.__RUNTIME_CONFIG__?.API_URL
const $q = useQuasar()
const username = ref('')
const password = ref('')
const confirmPassword = ref('')
const inProgress = ref(false)
const errorMessage = ref('')
const onSubmit = async () => {
if (inProgress.value) return
inProgress.value = true
errorMessage.value = ''
try {
const response = await axios.post(`${api}/register`, {
username: username.value.trim(),
password: password.value
})
if (response.status === 201) {
$q.notify({
type: 'positive',
message: 'Registration successful! Please login.',
position: 'top'
})
router.push('/login')
}
} catch (error: any) {
if (error.response?.status === 409) {
errorMessage.value = 'Username already taken'
} else if (error.response?.status === 400) {
errorMessage.value = error.response.data?.message || 'Invalid input'
} else {
errorMessage.value = 'Registration failed. Please try again.'
}
} finally {
inProgress.value = false
}
}
const goToLogin = () => {
router.push('/login')
}
const loginWithProvider = (provider: string) => {
window.location.href = `${api}/auth/${provider}`
}
const options = {
"particles": {
"number": {
"value": 80,
"density": {
"enable": true,
"area": 800
}
},
"color": {
"value": "#ffffff"
},
"shape": {
"type": "circle",
"stroke": {
"width": 0,
"color": "#000000"
},
"polygon": {
"sides": 5
}
},
"opacity": {
"value": 0.5,
"random": false,
"animation": {
"enable": false,
"speed": 1,
"minimumValue": 0.1,
"sync": false
}
},
"size": {
"value": 3,
"random": true,
"animation": {
"enable": false,
"speed": 40,
"minimumValue": 0.1,
"sync": false
}
},
"links": {
"enable": true,
"distance": 150,
"color": "#ffffff",
"opacity": 0.4,
"width": 1
},
"move": {
"enable": true,
"speed": 1,
"direction": "none",
"random": false,
"straight": false,
"outModes": {
"default": "out"
},
"attract": {
"enable": false,
"rotate": {
"x": 600,
"y": 1200
}
}
}
},
"interactivity": {
"detectsOn": "canvas",
"events": {
"onHover": {
"enable": false,
"mode": "repulse"
},
"onClick": {
"enable": false,
"mode": "push"
},
"resize": true
},
"modes": {
"grab": {
"distance": 400,
"links": {
"opacity": 1
}
},
"bubble": {
"distance": 400,
"size": 40,
"duration": 2,
"opacity": 8,
"speed": 3
},
"repulse": {
"distance": 200,
"duration": 0.4
},
"push": {
"quantity": 4
},
"remove": {
"quantity": 2
}
}
},
"detectRetina": true
}
</script>
<style scoped>
.register-box {
position: fixed;
align-items: center;
justify-content: center;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
width: 100%;
max-width: 420px;
padding: 1rem;
z-index: 2;
background-color: var(--color-background);
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}
</style>

View File

@@ -0,0 +1,296 @@
<template>
<div class="username-selection-box q-col-gutter-sm">
<div class="text-h3 text-center row">
<img src="/logo.png" alt="Logo" style="height: 60px; margin-right: 10px;" />
</div>
<h1 class="text-h5 text-center text-white q-mb-md">Choose Your Username</h1>
<p class="text-center text-white text-caption q-mb-lg">
You're signed in with {{ userInfo.provider }}. Please choose a username for your account.
</p>
<div class="user-info q-mb-lg">
<div class="row items-center q-gutter-md">
<div class="user-avatar">
<img v-if="userInfo.picture" :src="userInfo.picture" alt="Profile" class="avatar-img" />
<div v-else class="avatar-text">{{ userInfo.name?.charAt(0)?.toUpperCase() || 'U' }}</div>
</div>
<div class="user-details">
<div class="text-white text-weight-medium">{{ userInfo.name || 'Unknown User' }}</div>
<div class="text-white text-caption">Signed in with {{ userInfo.provider }}</div>
</div>
</div>
</div>
<q-form @submit.prevent="onSubmit" class="q-gutter-md">
<div class="row q-col-gutter-sm">
<q-input
style="width: 100%"
filled
dark
label-color="white"
color="white"
v-model="username"
label="Username *"
:error="!!errorMessage"
:error-message="errorMessage"
:loading="inProgress"
lazy-rules
:rules="[
val => !!val && val.trim().length > 0 || 'Username is required',
val => val && val.trim().length >= 3 || 'Username must be at least 3 characters',
val => val && val.trim().length <= 30 || 'Username must be less than 30 characters',
val => /^[a-zA-Z0-9_-]+$/.test(val) || 'Username can only contain letters, numbers, underscores, and hyphens'
]"
/>
</div>
<div class="row justify-center">
<q-btn type="submit" label="Complete Registration" push color="primary" :loading="inProgress" />
</div>
<div class="row justify-center">
<q-btn
flat
color="white"
label="Cancel"
@click="goToLogin"
size="sm"
/>
</div>
</q-form>
</div>
<vue-particles
id="particles-js"
:options='options'
/>
</template>
<script lang="ts" setup>
import { useQuasar } from 'quasar'
import { ref, onMounted } from 'vue'
import axios from "axios"
import router from "@/router"
import { useUserInfo } from "@/composables/useUserInfo"
const api = window?.__RUNTIME_CONFIG__?.API_URL
const $q = useQuasar()
const uInfo = useUserInfo()
const username = ref('')
const inProgress = ref(false)
const errorMessage = ref('')
const userInfo = ref({
id: '',
email: '',
name: '',
picture: '',
provider: ''
})
onMounted(async () => {
// Get user info from session storage or API
try {
const response = await axios.get(`${api}/select-username`, { withCredentials: true })
userInfo.value = response.data
} catch (error) {
console.error('Failed to get user info:', error)
router.push('/login')
}
})
const onSubmit = async () => {
if (inProgress.value) return
inProgress.value = true
errorMessage.value = ''
try {
const response = await axios.post(`${api}/submit-username`, {
username: username.value.trim()
}, { withCredentials: true })
if (response.status === 200) {
// User successfully created and logged in
await uInfo.requestState()
router.push('/')
}
} catch (error: any) {
if (error.response?.status === 409) {
errorMessage.value = 'Username already taken'
} else if (error.response?.status === 400) {
errorMessage.value = error.response.data?.message || 'Invalid username'
} else {
errorMessage.value = 'Registration failed. Please try again.'
}
} finally {
inProgress.value = false
}
}
const goToLogin = () => {
router.push('/login')
}
const options = {
"particles": {
"number": {
"value": 80,
"density": {
"enable": true,
"area": 800
}
},
"color": {
"value": "#ffffff"
},
"shape": {
"type": "circle",
"stroke": {
"width": 0,
"color": "#000000"
},
"polygon": {
"sides": 5
}
},
"opacity": {
"value": 0.5,
"random": false,
"animation": {
"enable": false,
"speed": 1,
"minimumValue": 0.1,
"sync": false
}
},
"size": {
"value": 3,
"random": true,
"animation": {
"enable": false,
"speed": 40,
"minimumValue": 0.1,
"sync": false
}
},
"links": {
"enable": true,
"distance": 150,
"color": "#ffffff",
"opacity": 0.4,
"width": 1
},
"move": {
"enable": true,
"speed": 1,
"direction": "none",
"random": false,
"straight": false,
"outModes": {
"default": "out"
},
"attract": {
"enable": false,
"rotate": {
"x": 600,
"y": 1200
}
}
}
},
"interactivity": {
"detectsOn": "canvas",
"events": {
"onHover": {
"enable": false,
"mode": "repulse"
},
"onClick": {
"enable": false,
"mode": "push"
},
"resize": true
},
"modes": {
"grab": {
"distance": 400,
"links": {
"opacity": 1
}
},
"bubble": {
"distance": 400,
"size": 40,
"duration": 2,
"opacity": 8,
"speed": 3
},
"repulse": {
"distance": 200,
"duration": 0.4
},
"push": {
"quantity": 4
},
"remove": {
"quantity": 2
}
}
},
"detectRetina": true
}
</script>
<style scoped>
.username-selection-box {
position: fixed;
align-items: center;
justify-content: center;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
width: 100%;
max-width: 420px;
padding: 1rem;
z-index: 2;
background-color: var(--color-background);
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}
.user-info {
background: rgba(255, 255, 255, 0.1);
border-radius: 12px;
padding: 1rem;
backdrop-filter: blur(10px);
}
.user-avatar {
min-width: 50px;
height: 50px;
border-radius: 50%;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
background: rgba(255, 255, 255, 0.2);
}
.avatar-img {
width: 100%;
height: 100%;
object-fit: cover;
}
.avatar-text {
color: white;
font-weight: 600;
font-size: 1.2rem;
}
.user-details {
flex: 1;
}
</style>

View File

@@ -1,3 +1,3 @@
MAJOR=0
MINOR=19
MINOR=23
PATCH=0