Skip to content
Snippets Groups Projects
Commit cc2bfc09 authored by Tini Tran's avatar Tini Tran
Browse files

Fixed the sign-up function. when the user creates user, they get pushed in to...

Fixed the sign-up function. when the user creates user, they get pushed in to the site, instead of logging in again.
parent c47c0aae
Branches
No related tags found
2 merge requests!8Updates to the history view,!6Implementation of images in history view and edit view. including token stuffs hehe
......@@ -242,3 +242,121 @@ export const getPicture = async (imageName: String, token: String) => {
// Handle the error, display a message to the user, etc.
}
};
export const createUser = async (username: string, password: string, email: string) => {
try {
const data= {
username: username,
password: password,
email: email
}
return await axios.post('http://localhost:8080/signup', data);
} catch (e) {
return "Failed to create user in backend"
}
}
<template>
<div class="signup">
<UserSchema buttonText="Create Account" header-text="Create Account" :status="loginStatus"
:customLogin="customLoginFunction"></UserSchema>
:customLogin="handleLoginClick"></UserSchema>
</div>
</template>
......@@ -10,9 +10,11 @@
import { ref } from 'vue';
import UserSchema from '@/components/UserSchema.vue';
import router from '@/router'
import {useTokenStore} from "@/stores/token";
import {createUser} from "@/utils/httputils";
let loginStatus = ref('');
const tokenStore = useTokenStore()
const customLoginFunction = async (username: string, password: string, email: string) => {
if (!username) {
loginStatus.value = 'Please enter a username';
......@@ -51,4 +53,31 @@ const customLoginFunction = async (username: string, password: string, email: st
loginStatus.value = err.message;
}
}
async function handleLoginClick(username: string, password: string, email: string) {
if (!username) {
loginStatus.value = 'Please enter a username';
return;
}
if (!password) {
loginStatus.value = 'Please enter a password';
return;
}
const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
if (!emailRegex.test(email)) {
loginStatus.value = 'Please enter a valid email address';
return;
}
try{
await createUser(username, password, email)
await tokenStore.getTokenAndSaveInStore(username, password)
if(tokenStore.jwtToken) {
await router.push("/homepage/discovery")
} else {
loginStatus.value = "Failed to retrieve token!"
}
} catch (err: any) {
loginStatus.value = err
}
}
</script>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment