1 | <script>
|
---|
2 |
|
---|
3 |
|
---|
4 | import { userStore } from '@/PiniaStores/UserStore.js'
|
---|
5 | import {useRouter} from 'vue-router'
|
---|
6 | import router from '@/router/index.js'
|
---|
7 |
|
---|
8 | export default {
|
---|
9 | data() {
|
---|
10 | return {
|
---|
11 | path: '',
|
---|
12 | url: 'http://localhost:8080/api/auth/register/',
|
---|
13 |
|
---|
14 | form_info:{
|
---|
15 | firstName: '',
|
---|
16 | lastName: '',
|
---|
17 | email: '',
|
---|
18 | password: '',
|
---|
19 | phoneNumber: '',
|
---|
20 |
|
---|
21 | },
|
---|
22 | /* data: {
|
---|
23 | id: 0,
|
---|
24 | firstName: "",
|
---|
25 | lastName: "",
|
---|
26 | email: "",
|
---|
27 | phoneNumber: "",
|
---|
28 | role: "",
|
---|
29 | token: ""
|
---|
30 | },*/
|
---|
31 | userStore_: userStore(),
|
---|
32 | router: useRouter()
|
---|
33 |
|
---|
34 | }
|
---|
35 | },
|
---|
36 |
|
---|
37 | methods: {
|
---|
38 | async register() {
|
---|
39 | await fetch(this.wholeUrl, {
|
---|
40 | method: 'POST',
|
---|
41 | headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
---|
42 | body: new URLSearchParams({
|
---|
43 | firstName: this.form_info.firstName,
|
---|
44 | lastName: this.form_info.lastName,
|
---|
45 | email: this.form_info.email,
|
---|
46 | password: this.form_info.password,
|
---|
47 | phoneNumber: this.form_info.phoneNumber})
|
---|
48 | }).then((response) => response.json())
|
---|
49 | .then((json) => {this.userStore_.setLocalStorage(json);
|
---|
50 | router.push('/')})
|
---|
51 | //console.log("Data received:", this.data);
|
---|
52 | //this.userStore_.setLocalStorage(json)
|
---|
53 | //console.log(json)
|
---|
54 |
|
---|
55 | //console.log(this.userStore_.data)
|
---|
56 | }
|
---|
57 |
|
---|
58 | },
|
---|
59 | computed: {
|
---|
60 | wholeUrl(){
|
---|
61 | return this.url+this.path;
|
---|
62 | },
|
---|
63 | testJson(){
|
---|
64 | return JSON.stringify({
|
---|
65 | firstName: this.form_info.firstName,
|
---|
66 | lastName: this.form_info.lastName,
|
---|
67 | email: this.form_info.email,
|
---|
68 | password: this.form_info.password,
|
---|
69 | phoneNumber: this.form_info.phoneNumber})
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 |
|
---|
74 | }
|
---|
75 |
|
---|
76 |
|
---|
77 |
|
---|
78 | </script>
|
---|
79 |
|
---|
80 | <template>
|
---|
81 | <div class="container-xxl">
|
---|
82 | <div class="row justify-content-center">
|
---|
83 |
|
---|
84 | <!-- <form @submit.prevent="register" method="POST">-->
|
---|
85 | <!-- <form v-bind:action="wholeUrl" method="POST">-->
|
---|
86 |
|
---|
87 | <div class="col-3">
|
---|
88 | <form @submit.prevent="register" method="POST">
|
---|
89 | <label for="name" class="form-label" >Name</label>
|
---|
90 | <input v-model="this.form_info.firstName" type="text" id="name" name="firstName" class="form-control" placeholder="Name" required>
|
---|
91 |
|
---|
92 | <label for="surname" class="form-label">Surname</label>
|
---|
93 | <input v-model="form_info.lastName" type="text" id="surname" name="lastName" class="form-control" placeholder="Surname" required>
|
---|
94 |
|
---|
95 | <label for="phone_number" class="form-label">Phone Number</label>
|
---|
96 | <input v-model="form_info.phoneNumber" type="text" id="phone_number" name="phoneNumber" class="form-control" required>
|
---|
97 |
|
---|
98 | <label for="email" class="form-label">Email Address</label>
|
---|
99 | <input v-model="form_info.email" type="email" id="email" name="email" class="form-control" placeholder="someone@example.com" required>
|
---|
100 |
|
---|
101 | <label for="password" class="form-label">Password</label>
|
---|
102 | <input v-model="form_info.password" type="password" id="password" name="password" class="form-control">
|
---|
103 |
|
---|
104 | <label for="role" class="form-label">Role</label>
|
---|
105 | <select class="form-control" id="role" v-model="path">
|
---|
106 |
|
---|
107 | <option value="customer">Customer</option>
|
---|
108 |
|
---|
109 | <option value="local-worker">Local Worker</option>
|
---|
110 |
|
---|
111 | <option value="local-manager">Local Manager</option>
|
---|
112 |
|
---|
113 | </select>
|
---|
114 |
|
---|
115 | <button type="submit" class="btn btn-dark">Register</button>
|
---|
116 | </form>
|
---|
117 | </div>
|
---|
118 |
|
---|
119 | </div>
|
---|
120 |
|
---|
121 |
|
---|
122 | </div>
|
---|
123 |
|
---|
124 | </template>
|
---|
125 |
|
---|
126 | <style scoped>
|
---|
127 |
|
---|
128 | </style>
|
---|