Skip to content

Commit

Permalink
add some sunctionality for login form
Browse files Browse the repository at this point in the history
  • Loading branch information
ErfiDev committed Dec 1, 2021
1 parent ddabe6a commit 249d07e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions views/login.page.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,30 @@
<input type="submit" class="btn btn-primary mb-5" value="Log in">
</form>
</section>
<script defer>
const form = document.querySelector(".user-login-form")

form.addEventListener("submit" , (e)=> {
e.preventDefault()

let formValues = new FormData(form)

fetch("/user/login" , {
method: "POST",
body: formValues
}).then(res => res.json())
.then(json => {
if (json.status === 200) {
Notify("Log in successful!" , "success")
window.location.replace("http://localhost:3000/")
} else if (json.status === 403) {
Notify("Password is not correct!" , "error")
} else {
Notify("Server error!" , "error")
}
}).catch(err => Notify("Server error!" , "error"))
})
</script>
{{end}}

{{define "css"}}
Expand Down

0 comments on commit 249d07e

Please sign in to comment.