Skip to content

Commit 88bed70

Browse files
update to login, auth token is now being written to local browser
1 parent 0f5449a commit 88bed70

File tree

3 files changed

+79
-3
lines changed

3 files changed

+79
-3
lines changed

src/sql_app.db

0 Bytes
Binary file not shown.

src/templates/accounts/login.html

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ <h3 class="font-weight-bolder text-info text-gradient">
3838
</div>
3939
<div class="card-body">
4040

41-
<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') }}">
4242

4343
<label>Username</label>
4444
<div class="mb-3">
@@ -59,7 +59,68 @@ <h3 class="font-weight-bolder text-info text-gradient">
5959
</div>
6060

6161
</form>
62+
<script>
63+
let login_form = document.querySelector('#login_form')
6264

65+
login_form.addEventListener('submit', async function(event){
66+
event.preventDefault()
67+
68+
let email = login_form.querySelector('#username').value
69+
let password = login_form.querySelector('#password').value
70+
// let form_action = login_form.action
71+
72+
let bodyFormData = new FormData()
73+
74+
bodyFormData.append(
75+
'username', email
76+
)
77+
78+
bodyFormData.append(
79+
'password', password
80+
)
81+
82+
let res = await fetch(login_form.action, {
83+
method: "POST",
84+
body: bodyFormData
85+
})
86+
87+
if (res.status == 200){
88+
89+
}
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+
115+
})
116+
117+
118+
// fetch
119+
120+
121+
122+
123+
</script>
63124
</div>
64125
<div class="card-footer text-center pt-0 px-lg-2 px-1">
65126
<p class="mb-4 text-sm mx-auto">

src/templates/accounts/register.html

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,31 @@ <h5>Sign UP</h5>
110110
body: JSON.stringify(new_user)
111111

112112
}).then(res => {
113-
console.log(res.status)
114113
if (res.status==201){
115114
register_form.reset()
116115
alert('success, now signin')
117116
window.location.href = register_form.dataset.successful_redirect
118117
} else {
119-
alert('something went wrong')
118+
alert('bad credentials')
120119
}
121120

122121
})
122+
123+
// fetch(form_action, {
124+
// method: "POST",
125+
// headers: {'Content-Type' : 'application/json'},
126+
// body: JSON.stringify(new_user)
127+
128+
// }).then(res => {
129+
// if (res.status==201){
130+
// register_form.reset()
131+
// alert('success, now signin')
132+
// window.location.href = register_form.dataset.successful_redirect
133+
// } else {
134+
// alert('bad credentials')
135+
// }
136+
137+
// })
123138

124139
})
125140

0 commit comments

Comments
 (0)