Files
bamort/frontend/src/components/RegisterForm.vue
T

68 lines
1.4 KiB
Vue
Raw Normal View History

2024-12-21 09:56:37 +01:00
<template>
<form @submit.prevent="register">
<h2>Register</h2>
<input v-model="username" placeholder="Username" required />
<input v-model="email" type="email" placeholder="Email" required />
<input v-model="password" type="password" placeholder="Password" required />
<button type="submit">Register</button>
<p v-if="error" class="error">{{ error }}</p>
<p v-if="success" class="success">{{ success }}</p>
2025-12-28 17:28:32 +01:00
<p class="back-to-login">
<router-link to="/">Back to Login</router-link>
</p>
2024-12-21 09:56:37 +01:00
</form>
</template>
<script>
import API from "../utils/api";
export default {
data() {
return {
username: "",
email: "",
password: "",
error: "",
success: "",
};
},
methods: {
async register() {
try {
2025-12-28 17:28:32 +01:00
const response = await API.post('/register', {
2024-12-21 09:56:37 +01:00
username: this.username,
2025-01-04 21:29:33 +01:00
password: this.password,
2025-07-24 07:39:43 +02:00
email: this.email
2024-12-21 09:56:37 +01:00
});
2025-07-24 07:39:43 +02:00
this.success = "Registration successful!";
2024-12-21 09:56:37 +01:00
this.error = "";
this.password = "";
} catch (err) {
this.error = err.response?.data?.error || "Registration failed.";
this.success = "";
}
},
},
};
</script>
<style>
.error {
color: red;
}
.success {
color: green;
}
2025-12-28 17:28:32 +01:00
.back-to-login {
margin-top: 15px;
text-align: center;
}
.back-to-login a {
color: #1da766;
text-decoration: none;
}
.back-to-login a:hover {
text-decoration: underline;
}
2024-12-21 09:56:37 +01:00
</style>