1
1
< html >
2
2
< head >
3
- < link href ="
https://cdn.jsdelivr.net/npm/[email protected] /dist/css/bootstrap.min.css "
rel ="
stylesheet "
integrity ="
sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC "
crossorigin ="
anonymous "
>
4
- < script src ="
https://cdn.jsdelivr.net/npm/[email protected] /dist/js/bootstrap.bundle.min.js "
integrity ="
sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM "
crossorigin ="
anonymous "
> </ script >
5
- < link rel ="stylesheet " href ="static/style.css ">
6
- < link rel ="stylesheet " href ="static/bootstrap.min.css ">
3
+ < link href ="
https://cdn.jsdelivr.net/npm/[email protected] /dist/css/bootstrap.min.css "
rel ="
stylesheet "
integrity ="
sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC "
crossorigin ="
anonymous "
>
4
+ < script src ="
https://cdn.jsdelivr.net/npm/[email protected] /dist/js/bootstrap.bundle.min.js "
integrity ="
sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM "
crossorigin ="
anonymous "
> </ script >
5
+ < link rel ="stylesheet " href ="static/style.css ">
6
+ < link rel ="stylesheet " href ="static/bootstrap.min.css ">
7
7
< script >
8
8
9
- const logout = async ( e ) => {
10
- //Include the code for logout here.
11
- } ;
9
+ const logout = async ( e ) => { // This function should contain the logout logic
10
+ // Build logout URL and Make GET request to logout endpoint
11
+ let logout_url = window . location . origin + "/djangoapp/logout" ;
12
+ const res = await fetch ( logout_url , {
13
+ method : "GET" ,
14
+ } ) ;
12
15
13
- let checkSession = ( ) => {
14
- let curr_user = sessionStorage . getItem ( "username" ) ;
15
-
16
- if ( curr_user && curr_user !== "" ) {
17
- document . getElementById ( "loginlogout" ) . innerHTML =
18
- '<span class="homepage_links">' + curr_user + '</span>' +
19
- '<a class="homepage_links" onclick="logout()" href="/">Logout</a>'
20
- } else {
21
- document . getElementById ( "loginlogout" ) . innerHTML =
22
- '<a class="homepage_links" href="/login">Login</a>' +
23
- '<a class="homepage_links" href="/register">Register</a>'
24
- }
25
- }
16
+ const json = await res . json ( ) ;
17
+ if ( json ) {
18
+ // Clear session storage and reload page
19
+ let username = sessionStorage . getItem ( 'username' ) ; // Get username before removing it
20
+ sessionStorage . removeItem ( 'username' ) ;
21
+ window . location . href = window . location . origin ; // Redirect to home page
22
+ window . location . reload ( ) ; // Reload the page to update UI
23
+ // Notify user of logout
24
+ alert ( "Logging out " + username + "..." )
25
+ }
26
+ else {
27
+ alert ( "The user could not be logged out." )
28
+ }
29
+ } ; // End of the logout function
26
30
31
+ let checkSession = ( ) => {
32
+ let curr_user = sessionStorage . getItem ( "username" ) ;
27
33
28
- // Build logout URL and Make GET request to logout endpoint
29
- let logout_url = window . location . origin + "/djangoapp/logout" ;
30
- const res = await fetch ( logout_url , {
31
- method : "GET" ,
32
- } ) ;
33
-
34
- const json = await res . json ( ) ;
35
- if ( json ) {
36
- // Clear session storage and reload page
37
- let username = sessionStorage . getItem ( 'username' ) ;
38
- sessionStorage . removeItem ( 'username' ) ;
39
- window . location . href = window . location . origin ;
40
- window . location . reload ( ) ;
41
- // Notify user of logout
42
- alert ( "Logging out " + username + "..." )
43
- }
44
- else {
45
- alert ( "The user could not be logged out." )
46
- }
34
+ if ( curr_user && curr_user !== "" ) {
35
+ document . getElementById ( "loginlogout" ) . innerHTML =
36
+ '<span class="homepage_links">' + curr_user + '</span>' +
37
+ '<a class="homepage_links" onclick="logout()" href="#">Logout</a>' // Changed href to # since JS handles navigation
38
+ } else {
39
+ document . getElementById ( "loginlogout" ) . innerHTML =
40
+ '<a class="homepage_links" href="/login">Login</a>' +
41
+ '<a class="homepage_links" href="/register">Register</a>'
42
+ }
43
+ }
47
44
48
45
49
46
</ script >
50
47
</ head >
51
48
< body onload ="checkSession() ">
52
49
< nav class ="navbar navbar-expand-lg navbar-light " style ="background-color:darkturquoise; height: 1in; ">
53
- < div class ="container-fluid ">
54
- < h2 style ="padding-right: 5%; "> Dealerships</ h2 >
55
- < button class ="navbar-toggler " type ="button " data-bs-toggle ="collapse " data-bs-target ="#navbarText " aria-controls ="navbarText " aria-expanded ="false " aria-label ="Toggle navigation ">
56
- < span class ="navbar-toggler-icon "> </ span >
57
- </ button >
58
- < div class ="collapse navbar-collapse " id ="navbarText ">
59
- < ul class ="navbar-nav me-auto mb-2 mb-lg-0 ">
60
- < li class ="nav-item ">
61
- < a class ="nav-link active " style ="font-size: larger; " aria-current ="page " href ="# "> Home</ a >
62
- </ li >
63
- < li class ="nav-item ">
64
- < a class ="nav-link " style ="font-size: larger; " href ="/about "> About Us</ a >
65
- </ li >
66
- < li class ="nav-item ">
67
- < a class ="nav-link " style ="font-size: larger; " href ="/contact "> Contact Us</ a >
68
- </ li >
69
- </ ul >
70
- < span class ="navbar-text ">
71
- < div class ="loginlink " id ="loginlogout ">
72
- </ div >
73
- </ span >
74
- </ div >
75
- </ div >
50
+ < div class ="container-fluid ">
51
+ < h2 style ="padding-right: 5%; "> Dealerships</ h2 >
52
+ < button class ="navbar-toggler " type ="button " data-bs-toggle ="collapse " data-bs-target ="#navbarText " aria-controls ="navbarText " aria-expanded ="false " aria-label ="Toggle navigation ">
53
+ < span class ="navbar-toggler-icon "> </ span >
54
+ </ button >
55
+ < div class ="collapse navbar-collapse " id ="navbarText ">
56
+ < ul class ="navbar-nav me-auto mb-2 mb-lg-0 ">
57
+ < li class ="nav-item ">
58
+ < a class ="nav-link active " style ="font-size: larger; " aria-current ="page " href ="# "> Home</ a >
59
+ </ li >
60
+ < li class ="nav-item ">
61
+ < a class ="nav-link " style ="font-size: larger; " href ="/about "> About Us</ a >
62
+ </ li >
63
+ < li class ="nav-item ">
64
+ < a class ="nav-link " style ="font-size: larger; " href ="/contact "> Contact Us</ a >
65
+ </ li >
66
+ </ ul >
67
+ < span class ="navbar-text ">
68
+ < div class ="loginlink " id ="loginlogout ">
69
+ </ div >
70
+ </ span >
71
+ </ div >
72
+ </ div >
76
73
</ nav >
77
74
< div style ="display: flex;flex-direction: column; ">
78
75
< div class ="card " style ="width: 50%;margin-top: 50px;align-self: center; ">
79
- < img src ="static/car_dealership.jpg " class ="card-img-top " alt ="... ">
80
- < div class ="banner ">
81
- < h5 > Welcome to our Dealerships!</ h5 >
82
- < a href ="/dealers " class ="btn " style ="background-color: aqua;margin:10px "> View Dealerships</ a >
83
- </ div >
76
+ < img src ="static/car_dealership.jpg " class ="card-img-top " alt ="... ">
77
+ < div class ="banner ">
78
+ < h5 > Welcome to our Dealerships!</ h5 >
79
+ < a href ="/dealers " class ="btn " style ="background-color: aqua;margin:10px "> View Dealerships</ a >
80
+ </ div >
84
81
</ div >
85
82
</ div >
86
83
</ body >
87
- </ html >
84
+ </ html >
0 commit comments