-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
44 lines (38 loc) · 1.08 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { route } from "./router";
import axios from "axios";
let access = false;
let returned = false;
route("/", "home", function () {
if (returned) {
this.message = "Dostęp zabroniony, podaj login i hasło aby uzyskać dostęp";
} else {
this.message = "Podaj login i hasło";
}
this.$on("#loginForm", "submit", (e) => {
e.preventDefault();
const login = {
username: document.getElementById("user").value,
password: document.getElementById("password").value,
};
axios
.post("https://zwzt-zadanie.netlify.app/api/login", login)
.then((response) => {
access = true;
window.location.href = "#/success";
})
.catch((error) => {
this.message = "Błędne dane logowania";
access = false;
this.$refresh();
username: document.getElementById("user").value = login.username;
});
});
});
route("/success", "success", function () {
if (!access) {
returned = true;
window.location.href = "#";
}
this.message = "Zalogowano poprawnie";
});
route("*", "error404", function () {});