diff --git a/src/app/account/change-password/page.tsx b/src/app/account/change-password/page.tsx new file mode 100644 index 0000000..b95f375 --- /dev/null +++ b/src/app/account/change-password/page.tsx @@ -0,0 +1,106 @@ +'use client' + +import { DiscordButton } from '@/app/components/DiscordButton' +import axios from 'axios' +import { BackButton } from '@/app/components/BackButton' +import { useEffect, useState } from 'react' +import { useRouter } from 'next/navigation' +import { getCookie, setCookie } from '@/util/cookie' + +export default function AccountChangePasswordPage () { + const [loading, setLoading] = useState(true) + const router = useRouter() + + const [newPassword, setNewPassword] = useState('') + const [retypeNewPassword, setRetypeNewPassword] = useState('') + + useEffect(() => { + document.title = 'Lncvrt Games - Change Account Password' + + const token = getCookie('accountToken', '-1') + if (token === '-1') { + router.push('/account/login') + } else setLoading(false) + }, [router]) + + return ( +
+ + +

+ {loading ? 'Loading...' : 'Change Lncvrt Games Account Password'} +

+ {!loading && ( +
{ + e.preventDefault() + + if (newPassword !== retypeNewPassword) { + alert('Passwords must match') + return + } + + try { + const result = await axios.post( + '/api/account/change-password', + { + newPassword + }, + { + headers: { + authorization: getCookie('accountToken', '-1') + } + } + ) + if (result.data.success) { + if (result.data.data) + setCookie('accountToken', result.data.data) + router.push('/account') + } else { + alert( + 'Failed to change password, error: ' + + (result.data.message || 'n/a') + ) + } + } catch (e: any) { + if (e.response) { + alert( + 'Failed to change password, error: ' + + (e.response.data?.message || + JSON.stringify(e.response.data)) + ) + } else if (e.request) { + alert('Failed to change password, no response from server.') + } else { + alert('Failed to change password, error: ' + e.message) + } + } + }} + > + setNewPassword(e.target.value)} + required + /> + setRetypeNewPassword(e.target.value)} + required + /> + +
+ )} +
+ ) +} diff --git a/src/app/account/change-username/page.tsx b/src/app/account/change-username/page.tsx new file mode 100644 index 0000000..d9aa293 --- /dev/null +++ b/src/app/account/change-username/page.tsx @@ -0,0 +1,90 @@ +'use client' + +import { DiscordButton } from '@/app/components/DiscordButton' +import axios from 'axios' +import { BackButton } from '@/app/components/BackButton' +import { useEffect, useState } from 'react' +import { useRouter } from 'next/navigation' +import { getCookie, setCookie } from '@/util/cookie' + +export default function AccountChangeUsernamePage () { + const [loading, setLoading] = useState(true) + const router = useRouter() + + const [newUsername, setNewUsername] = useState('') + + useEffect(() => { + document.title = 'Lncvrt Games - Change Account Username' + + const token = getCookie('accountToken', '-1') + if (token === '-1') { + router.push('/account/login') + } else setLoading(false) + }, [router]) + + return ( +
+ + +

+ {loading ? 'Loading...' : 'Change Lncvrt Games Account Username'} +

+ {!loading && ( +
{ + e.preventDefault() + + try { + const result = await axios.post( + '/api/account/change-username', + { + newUsername + }, + { + headers: { + authorization: getCookie('accountToken', '-1') + } + } + ) + if (result.data.success) { + if (result.data.data) + setCookie('accountToken', result.data.data) + setCookie('accountUsername', newUsername) + router.push('/account') + } else { + alert( + 'Failed to change username, error: ' + + (result.data.message || 'n/a') + ) + } + } catch (e: any) { + if (e.response) { + alert( + 'Failed to change username, error: ' + + (e.response.data?.message || + JSON.stringify(e.response.data)) + ) + } else if (e.request) { + alert('Failed to change username, no response from server.') + } else { + alert('Failed to change username, error: ' + e.message) + } + } + }} + > + setNewUsername(e.target.value)} + required + /> + +
+ )} +
+ ) +} diff --git a/src/app/account/page.tsx b/src/app/account/page.tsx index deb8eee..afc80f4 100644 --- a/src/app/account/page.tsx +++ b/src/app/account/page.tsx @@ -27,36 +27,43 @@ export default function AccountPage () {

{loading ? 'Loading...' : 'Account'}

-
- - Change username - - - Change password - - - Refresh login - - -
+ {!loading && ( + <> +

+ Logged in as: {getCookie('accountUsername', 'N/A')} +

+
+ + Change username + + + Change password + + + Refresh login + + +
+ + )} ) }