Ignore:
Timestamp:
02/17/25 01:39:28 (4 months ago)
Author:
ste08 <sjovanoska@…>
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)
Message:

Frontend + some backend changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/resources/static/UserLogin.html

    ra70b5a4 r9868304  
    3535        data: {
    3636            email: '',
    37             password: ''
     37            password: '',
     38            userId:''
    3839        },
    3940        methods: {
    40             loginUser() {
     41            async loginUser() {
    4142                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                    }
    4369                }
    4470            }
Note: See TracChangeset for help on using the changeset viewer.