Skip to content
Snippets Groups Projects
Commit 526315b9 authored by Gia Hy Nguyen's avatar Gia Hy Nguyen
Browse files

Added login and signup validation

parent 72f2863f
Branches
No related tags found
1 merge request!8Updates to the history view
...@@ -10,6 +10,16 @@ import { useRouter } from 'vue-router'; ...@@ -10,6 +10,16 @@ import { useRouter } from 'vue-router';
let loginStatus = ref(''); let loginStatus = ref('');
const customLoginFunction = async (username: string, password: string) => { const customLoginFunction = async (username: string, password: string) => {
if (!username) {
loginStatus.value = 'Please enter a username';
return;
}
if (!password) {
loginStatus.value = 'Please enter a password';
return;
}
try { try {
const response = await fetch('http://localhost:8080/users/login', { const response = await fetch('http://localhost:8080/users/login', {
method: 'POST', method: 'POST',
......
...@@ -14,6 +14,22 @@ import router from '@/router' ...@@ -14,6 +14,22 @@ import router from '@/router'
let loginStatus = ref(''); let loginStatus = ref('');
const customLoginFunction = async (username: string, password: string, email: string) => { const customLoginFunction = async (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;
}
const apiUrl = 'http://localhost:8080/users/create'; const apiUrl = 'http://localhost:8080/users/create';
try { try {
const response = await fetch(apiUrl, { const response = await fetch(apiUrl, {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment