Changeset 9868304 for src/main/resources/static/UserLogin.html
- Timestamp:
- 02/17/25 01:39:28 (4 months ago)
- Branches:
- master
- Children:
- de83113
- Parents:
- a70b5a4
- git-author:
- ste08 <sjovanoska@…> (02/17/25 01:39:02)
- git-committer:
- ste08 <sjovanoska@…> (02/17/25 01:39:28)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/resources/static/UserLogin.html
ra70b5a4 r9868304 35 35 data: { 36 36 email: '', 37 password: '' 37 password: '', 38 userId:'' 38 39 }, 39 40 methods: { 40 loginUser() {41 async loginUser() { 41 42 if (this.email && this.password) { 42 window.location.href = '/flights'; 43 try{ 44 const response = await fetch('/api/user/login', { 45 method:'POST', 46 headers: { 47 'Content-Type':'application/json' 48 }, 49 body: JSON.stringify({ 50 email:this.email, 51 password:this.password 52 }) 53 }); 54 if(!response.ok){ 55 throw new Error('Login failed'); 56 } 57 const data = await response.json(); 58 console.log(data); 59 if(data.userId){ 60 console.log('Success'); 61 window.location.href = `/flights?userId=${encodeURIComponent(data.userId)}`; 62 }else { 63 alert('Invalid login credentials'); 64 } 65 } catch (error){ 66 console.error(error); 67 alert('Login failed. Please try again.'); 68 } 43 69 } 44 70 }
Note:
See TracChangeset
for help on using the changeset viewer.