arnaucube
arnaucube/gogame-old-frontendPublic Self-hosted repository
gogame-old-frontend/index.js
index.jsRaw
 1if (localStorage.getItem("token")!==null) {
 2  // redirect to dashboard
 3  window.location.href = "/dashboard.html";
 4}
 5
 6function register() {
 7  let email = document.getElementById("registerEmail").value;
 8  let name = document.getElementById("registerName").value;
 9  let password = document.getElementById("registerPassword").value;
10
11  let data = {
12    email: email,
13    name: name,
14    password: password
15  };
16  axios.post(url + "/register", data)
17    .then(function (res) {
18    console.log(res.data);
19  })
20  .catch(function (error) {
21    console.log(error);
22  });
23}
24
25function login() {
26  let email = document.getElementById("loginEmail").value;
27  let password = document.getElementById("loginPassword").value;
28
29  let data = {
30    email: email,
31    password: password
32  };
33  axios.post(url + "/login", data)
34    .then(function (res) {
35    console.log(res.data);
36    localStorage.setItem("token", res.data.token);
37    window.location.href = "/dashboard.html";
38  })
39  .catch(function (error) {
40    console.log(error);
41  });
42}