writing the stub js to authenticate against the back end
This commit is contained in:
parent
846282db74
commit
aab0ef380a
@ -5,8 +5,8 @@ Login
|
|||||||
{{ define "content" }}
|
{{ define "content" }}
|
||||||
<form action=""
|
<form action=""
|
||||||
method="post"
|
method="post"
|
||||||
name=""
|
name="login-form"
|
||||||
id=""
|
id="login-form"
|
||||||
class="d-blick needs-validation"
|
class="d-blick needs-validation"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
novalidate="">
|
novalidate="">
|
||||||
@ -31,8 +31,14 @@ Login
|
|||||||
class="form-control">
|
class="form-control">
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
<a href="javascript:void(0)" class="btn btn-primary">Login</a>
|
<a href="javascript:void(0)" id="login-btn" class="btn btn-primary">Login</a>
|
||||||
</form>
|
</form>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{define "js"}}
|
{{define "js"}}
|
||||||
|
<script type="module">
|
||||||
|
import {val} from "/static/js/login.js"
|
||||||
|
document.getElementById("login-btn").addEventListener("click", () => {
|
||||||
|
val({{.API}});
|
||||||
|
})
|
||||||
|
</script>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
33
static/js/login.js
Normal file
33
static/js/login.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
export function val(api) {
|
||||||
|
let form = document.getElementById("login_form");
|
||||||
|
|
||||||
|
if (form.checkValidity() === false) {
|
||||||
|
this.event.preventDefault();
|
||||||
|
this.event.stopPropagation();
|
||||||
|
form.classList.add("was-validated");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
form.classList.add("was-validated");
|
||||||
|
|
||||||
|
let payload = {
|
||||||
|
email: document.getElementById("email").value,
|
||||||
|
password: document.getElementById("password").value,
|
||||||
|
};
|
||||||
|
|
||||||
|
const requestOptions = {
|
||||||
|
method: 'post',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
};
|
||||||
|
|
||||||
|
fetch(api + "/api/authenticate", requestOptions)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(response => {
|
||||||
|
console.log(response)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user