diff --git a/src/components/screens/Login.vue b/src/components/screens/Login.vue index 3242945..4e2313d 100644 --- a/src/components/screens/Login.vue +++ b/src/components/screens/Login.vue @@ -12,10 +12,13 @@ UI box inner - + - + + + + @@ -26,11 +29,13 @@ import { onMounted, ref } from 'vue' import { useGameStore } from '@/stores/gameStore' import { useCookies } from '@vueuse/integrations/useCookies' -import LoginForm from '@/components/screens/partials/login/LoginForm.vue' -import RegisterForm from '@/components/screens/partials/login/RegisterForm.vue' +import LoginForm from '@/components/screens/partials/LoginForm.vue' +import RegisterForm from '@/components/screens/partials/RegisterForm.vue' +import NewPasswordForm from '@/components/screens/partials/NewPasswordForm.vue' import ResetPassword from '@/components/utilities/ResetPassword.vue' const isPasswordResetFormShown = ref(false) +const doesUrlHaveToken = window.location.hash.includes('#') const gameStore = useGameStore() const currentForm = ref('login') diff --git a/src/components/screens/partials/login/NewPasswordForm.vue b/src/components/screens/partials/login/NewPasswordForm.vue index 2d9d05a..26457a5 100644 --- a/src/components/screens/partials/login/NewPasswordForm.vue +++ b/src/components/screens/partials/login/NewPasswordForm.vue @@ -2,15 +2,11 @@
- - -
- - -
+ + {{ newPasswordError }}
- +
@@ -20,7 +16,7 @@
-

+

@@ -34,9 +30,7 @@ import { useCookies } from '@vueuse/integrations/useCookies' const emit = defineEmits(['switchToLogin']) const gameStore = useGameStore() -const username = ref('') const password = ref('') -const email = ref('') const newPasswordError = ref('') const showPassword = ref(false) @@ -56,12 +50,19 @@ async function newPasswordFunc() { return } - // send new password event to server - const response = await newPassword(token, password.value) + const urlToken = window.location.hash.split('#')[1] + + // send new password event to server along with the token + const response = await newPassword(urlToken, password.value) if (response.success === undefined) { newPasswordError.value = response.error return } + window.location.href = '/' +} + +function cancelNewPassword() { + window.location.href = '/' } \ No newline at end of file diff --git a/src/components/utilities/ResetPassword.vue b/src/components/utilities/ResetPassword.vue index 68cb084..93f0db8 100644 --- a/src/components/utilities/ResetPassword.vue +++ b/src/components/utilities/ResetPassword.vue @@ -49,5 +49,7 @@ async function resetPasswordFunc() { resetPasswordError.value = response.error return } + + emit('close') } \ No newline at end of file diff --git a/src/services/authentication.ts b/src/services/authentication.ts index 47d0d6c..4aa053c 100644 --- a/src/services/authentication.ts +++ b/src/services/authentication.ts @@ -39,3 +39,15 @@ export async function resetPassword(email: string) { return { error: error.response.data.message } } } + +export async function newPassword(urlToken: string, password: string) { + try { + const response = await axios.post(`${config.server_endpoint}/new-password`, { urlToken, password }) + return { success: true, token: response.data.token } + } catch (error: any) { + if (typeof error.response.data === 'undefined') { + return { error: 'Could not connect to server' } + } + return { error: error.response.data.message } + } +}