|
1 | 1 | <template> |
2 | | - <form id="register-form"> |
3 | | - <input type="text" id="register-username" name="username" placeholder="Username" required> |
4 | | - <input type="email" id="register-email" name="email" placeholder="Email" required> |
| 2 | + <form id="register-form" @submit.prevent="register"> |
| 3 | + <input type="text" id="register-username" name="username" v-model="username" placeholder="Username" required> |
| 4 | + <input type="email" id="register-email" name="email" v-model="email" placeholder="Email" required> |
5 | 5 |
|
6 | 6 | <div> |
7 | | - <input type="password" id="register-password" name="password" placeholder="Password" required> |
| 7 | + <input type="password" id="register-password" name="password" v-model="password" placeholder="Password" required> |
8 | 8 | <input class="show-password-check" id="show-password-input" type="checkbox" tabindex="-1"> |
9 | 9 | <label class="show-password" for="show-password-input" title="Show Password"></label> |
10 | 10 | <progress id="password-strength" class="hidden"></progress> |
11 | 11 | </div> |
12 | 12 |
|
13 | 13 | <div> |
14 | | - <input type="password" id="register-password-confirm" name="password-confirm" |
15 | | - placeholder="Confirm password" required> |
| 14 | + <input type="password" id="register-password-confirm" name="password-confirm" v-model="passwordConfirm" placeholder="Confirm password" required> |
16 | 15 | <input class="show-password-check" id="show-password-confirm-input" type="checkbox" tabindex="-1"> |
17 | 16 | <label class="show-password" for="show-password-confirm-input" title="Show Password"></label> |
18 | 17 | </div> |
|
21 | 20 | </form> |
22 | 21 | </template> |
23 | 22 |
|
| 23 | +<script> |
| 24 | +export default { |
| 25 | + data() { |
| 26 | + return { |
| 27 | + username: '', |
| 28 | + email: '', |
| 29 | + password: '', |
| 30 | + passwordConfirm: '' |
| 31 | + }; |
| 32 | + }, |
| 33 | + methods: { |
| 34 | + register() { |
| 35 | + if (this.password !== this.passwordConfirm) { |
| 36 | + console.error('Passwords do not match'); |
| 37 | + return; |
| 38 | + } |
| 39 | +
|
| 40 | + fetch('http://localhost:5000/auth/register', { |
| 41 | + method: 'POST', |
| 42 | + headers: { 'Content-Type': 'application/json' }, |
| 43 | + body: JSON.stringify({ |
| 44 | + username: this.username, |
| 45 | + email: this.email, |
| 46 | + password: this.password |
| 47 | + }), |
| 48 | + }) |
| 49 | + .then(response => { |
| 50 | + if (response.ok) { |
| 51 | + return response.json(); |
| 52 | + } else { |
| 53 | + throw new Error('Registration failed'); |
| 54 | + } |
| 55 | + }) |
| 56 | + .then(data => { |
| 57 | + console.log('Registration successful:', data); |
| 58 | + }) |
| 59 | + .catch(error => { |
| 60 | + console.error('Error:', error); |
| 61 | + }); |
| 62 | + } |
| 63 | + }, |
| 64 | +} |
| 65 | +</script> |
| 66 | + |
24 | 67 | <style scoped> |
25 | 68 | #password-strength { |
26 | 69 | appearance: none; |
|
0 commit comments