-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic view for login page and signup page
- Loading branch information
Showing
4 changed files
with
149 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,59 @@ | ||
<script setup> | ||
import CustomInput from '@/components/CustomInput.vue'; | ||
import { ref, computed } from 'vue'; | ||
import { ref } from 'vue'; | ||
import APIClient from '@/api_client.js'; | ||
const username = ref(''); | ||
const updateUsername = (value) => { | ||
username.value = value; | ||
}; | ||
const password = ref(''); | ||
const updatePassword = (value) => { | ||
password.value = value; | ||
}; | ||
const validationMessage = ref(''); | ||
const submitForm = () => { | ||
console.log('Form submitted'); | ||
// TODO call api | ||
const clearForm = () => { | ||
username.value = ''; | ||
password.value = ''; | ||
}; | ||
const login = async () => { | ||
if (!username.value.trim() || !password.value.trim()) { | ||
validationMessage.value = 'Please fill in all fields.'; | ||
return; | ||
} | ||
try { | ||
const response = await APIClient.loginUser(username.value.trim(), password.value.trim()); | ||
console.log('Login successful:', response); | ||
validationMessage.value = 'Login successful.'; | ||
clearForm(); | ||
// Redirect or perform additional actions after successful login | ||
} catch (error) { | ||
console.error('Error logging in:', error); | ||
if (error instanceof ValidationError) { | ||
validationMessage.value = error.message; // Show detailed validation error message to user | ||
} else { | ||
validationMessage.value = 'Error logging in. Please try again.'; | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<template> | ||
<section class="login container"> | ||
<h1>This is login page</h1> | ||
<form @submit.prevent="submitForm"> | ||
{{ username }} <!-- TODO debug purpose remove this line --> | ||
<CustomInput label="Username" :value="username" @input="updateUsername" required /> | ||
{{ password }} <!-- TODO debug purpose remove this line --> | ||
<CustomInput label="Password" type="password" :value="password" @input="updatePassword" required /> | ||
<button type="submit" class="btn">Submit</button> | ||
</form> | ||
</section> | ||
</template> | ||
<div> | ||
<section class="login-form container"> | ||
<h1>Login</h1> | ||
<p :class="{ 'success-message': validationMessage === 'Login successful.' }">{{ validationMessage }}</p> | ||
<form @submit.prevent="login" @keyup.enter="login" style="text-align: center;"> | ||
<CustomInput label="Username" v-model="username" required /> | ||
<CustomInput label="Password" v-model="password" type="password" required/> | ||
<div style="margin-top: 20px;"> | ||
<button type="submit" class="btn">Login</button> | ||
</div> | ||
</form> | ||
</section> | ||
</div> | ||
</template> | ||
|
||
<style> | ||
.success-message { | ||
color: green; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,62 @@ | ||
<script setup> | ||
import CustomInput from '@/components/CustomInput.vue'; | ||
import { ref } from 'vue'; | ||
import APIClient from '@/api_client.js'; | ||
const username = ref(''); | ||
const password = ref(''); | ||
const confirmPassword = ref(''); | ||
const validationMessage = ref(''); | ||
const clearForm = () => { | ||
username.value = ''; | ||
password.value = ''; | ||
confirmPassword.value = ''; | ||
}; | ||
const register = async () => { | ||
if (!username.value.trim() || !password.value.trim() || !confirmPassword.value.trim()) { | ||
validationMessage.value = 'Please fill in all fields.'; | ||
return; | ||
} | ||
if (password.value !== confirmPassword.value) { | ||
validationMessage.value = 'Passwords do not match.'; | ||
return; | ||
} | ||
try { | ||
const response = await APIClient.registerUser(username.value.trim(), password.value.trim()); | ||
console.log('Registration successful:', response); | ||
validationMessage.value = 'Registration successful.'; | ||
clearForm(); | ||
} catch (error) { | ||
console.error('Error registering:', error); | ||
validationMessage.value = 'Error registering. Please try again.'; | ||
} | ||
}; | ||
</script> | ||
|
||
<template> | ||
<h1>This will be signup page</h1> | ||
</template> | ||
<div> | ||
<section class="register-form container"> | ||
<h1>Register</h1> | ||
<p :class="{ 'success-message': validationMessage === 'Registration successful.' }">{{ validationMessage }}</p> | ||
<form @submit.prevent="signUp" @keyup.enter="signUp" style="text-align: center;"> | ||
<CustomInput label="Username" v-model="username" required /> | ||
<CustomInput label="Password" v-model="password" type="password" required /> | ||
<CustomInput label="Confirm Password" v-model="confirmPassword" type="password" required /> | ||
<div style="margin-top: 20px;"> | ||
<button type="submit" class="btn">Register</button> | ||
</div> | ||
</form> | ||
</section> | ||
</div> | ||
</template> | ||
|
||
|
||
<style> | ||
.success-message { | ||
color: green; | ||
} | ||
</style> |