@@ -74,34 +74,33 @@ <h2>Create an Account or Sign In</h2>
74
74
75
75
< script src ="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js "> </ script >
76
76
< script >
77
- // Fetch interests and populate the dropdown
77
+
78
78
axios . get ( 'http://localhost:8000/api/interest' )
79
79
. then ( response => {
80
80
const interestsSelect = document . querySelector ( 'select[name="interests"]' ) ;
81
81
const interests = response . data ;
82
82
83
83
interests . forEach ( interest => {
84
84
const option = document . createElement ( 'option' ) ;
85
- option . value = interest . interestName ; // Get only the interest name
86
- option . textContent = interest . interestName ; // Display only the interest name
85
+ option . value = interest . interestName ;
86
+ option . textContent = interest . interestName ;
87
87
interestsSelect . appendChild ( option ) ;
88
88
} ) ;
89
89
} )
90
90
. catch ( error => {
91
91
console . error ( error ) ;
92
92
} ) ;
93
93
94
- // Handle form submission for Sign Up
94
+
95
95
document . getElementById ( 'register-form' ) . addEventListener ( 'submit' , function ( event ) {
96
96
event . preventDefault ( ) ;
97
97
const form = event . target ;
98
98
const formData = new FormData ( form ) ;
99
99
100
- // Get all selected interest options
100
+
101
101
const selectedOptions = form . elements [ 'interests' ] . selectedOptions ;
102
102
const selectedInterests = Array . from ( selectedOptions ) . map ( option => option . value ) ;
103
103
104
- // Create the payload object
105
104
const payload = {
106
105
firstName : formData . get ( 'firstName' ) ,
107
106
lastName : formData . get ( 'lastName' ) ,
@@ -113,38 +112,37 @@ <h2>Create an Account or Sign In</h2>
113
112
114
113
axios . post ( 'http://localhost:8000/api/user' , payload )
115
114
. then ( response => {
116
- // Handle the response, e.g., show a success message or redirect to the dashboard
115
+
117
116
console . log ( 'User registered successfully!' ) ;
118
- // Redirect to dashboard.html
117
+
119
118
window . location . href = 'event.html' ;
120
119
} )
121
120
. catch ( error => {
122
- // Handle the error, e.g., display an error message
121
+
123
122
console . error ( error ) ;
124
123
} ) ;
125
124
} ) ;
126
125
127
- // Handle form submission for Sign In
126
+
128
127
document . getElementById ( 'login-form' ) . addEventListener ( 'submit' , function ( event ) {
129
128
event . preventDefault ( ) ;
130
129
const form = event . target ;
131
130
const formData = new FormData ( form ) ;
132
131
133
- // Create the payload object
134
132
const payload = {
135
133
email : formData . get ( 'your_email_1' ) ,
136
134
password : formData . get ( 'password_1' )
137
135
} ;
138
136
139
137
axios . post ( 'http://localhost:8000/api/login' , payload )
140
138
. then ( response => {
141
- // Handle the response, e.g., show a success message or redirect to the dashboard
139
+
142
140
console . log ( 'User logged in successfully!' ) ;
143
- // Redirect to dashboard.html
141
+
144
142
window . location . href = 'dashboard.html' ;
145
143
} )
146
144
. catch ( error => {
147
- // Handle the error, e.g., display an error message
145
+
148
146
console . error ( error ) ;
149
147
} ) ;
150
148
} ) ;
0 commit comments