@@ -38,7 +38,7 @@ <h3 class="font-weight-bolder text-info text-gradient">
3838 </ div >
3939 < div class ="card-body ">
4040
41- < form id ="login_form " role ="form text-left " method ="post " action ="{{ url_for('login') }} ">
41+ < form id ="login_form " role ="form text-left " method ="post " action ="{{ url_for('login') }} " data-successful_redirect =" {{ url_for('home') }} " >
4242
4343 < label > Username</ label >
4444 < div class ="mb-3 ">
@@ -67,7 +67,6 @@ <h3 class="font-weight-bolder text-info text-gradient">
6767
6868 let email = login_form . querySelector ( '#username' ) . value
6969 let password = login_form . querySelector ( '#password' ) . value
70- // let form_action = login_form.action
7170
7271 let bodyFormData = new FormData ( )
7372
@@ -85,41 +84,14 @@ <h3 class="font-weight-bolder text-info text-gradient">
8584 } )
8685
8786 if ( res . status == 200 ) {
88-
87+ login_form . reset ( )
88+ let data = await res . json ( )
89+ let access_token = data . access_token
90+ window . localStorage . setItem ( 'current_user' , access_token )
91+ window . location . href = login_form . dataset . successful_redirect
8992 }
90- console . log ( res )
91- console . log ( res . status )
92- // console.log(res.json())
93- console . log ( await res . json ( ) )
94-
95- // fetch(login_form.action, {
96- // method: "POST",
97- // body: bodyFormData
98- // }).then(res => {
99- // if (res.status==200){
100- // login_form.reset()
101- // // alert('successfully logged in')
102- // let access_token = res.json()
103- // console.log(access_token)
104- // // console.log(access_token.access_token)
105-
106- // let
107-
108-
109- // // window.location.href =
110- // } else {
111- // alert ('something went wrong')
112- // }
113- // })
114-
11593 } )
11694
117-
118- // fetch
119-
120-
121-
122-
12395 </ script >
12496 </ div >
12597 < div class ="card-footer text-center pt-0 px-lg-2 px-1 ">
0 commit comments