aboutsummaryrefslogtreecommitdiffstats
path: root/res/setup.html
blob: 8068a9d42f0123e14ba045e7260535383aa72cf8 (plain) (blame)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!-- localization-template -->
<!DOCTYPE html>
<html>

<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <link rel="manifest" href="manifest.json">
  <title>SyncTube</title>
  <link rel="icon" href="img/favicon.svg" type="image/svg+xml">
  <link id="usertheme" href="css/des.css" rel="stylesheet">
  <link id="usertheme" href="css/setup.css" rel="stylesheet">
  <link id="customcss" href="css/custom.css" rel="stylesheet">

</head>

<body>
  <main class="setup">
    <h1 class="setup-title">SyncTube</h1>
    <p>Create your admin account</p>

    <form id="setup-form" class="setup-form" action="/setup" method="POST">
      <input type="text" name="name" placeholder="Name">
      <input type="password" name="password" placeholder="Password">
      <input type="password" name="confirmation" placeholder="Repeat password">

      <div id="form-errors" class="form-errors"></div>

      <button type="submit">Create</button>
    </form>
  </main>

  <script>
    const formElement = document.getElementById("setup-form");
    const errorsElement = document.getElementById("form-errors");

    formElement.addEventListener("submit", function (e) {
      e.preventDefault();

      const { name, password, confirmation } = formElement.elements;
      const payload = {
        name: name.value,
        password: password.value,
        passwordConfirmation: confirmation.value,
      }

      fetch("/setup", { method: "POST", body: JSON.stringify(payload) })
        .then(res => res.json())
        .then(response => handleResponse(response))
        .catch(() => handleResponse(null));
    }, true);


    function handleResponse(response) {
      if (response.success) {
        return window.location.reload();
      }

      const errors = !response
        ? ["Unknown error"]
        : (response.errors ?? []).map(item => item.error);

      showErrors(errorsElement, errors);
    }

    function showErrors(container, errors) {
      container.innerHTML = "";

      errors.forEach((message) => {
        const errorEl = document.createElement("div");
        errorEl.innerText = message;
        container.appendChild(errorEl);
      });
    }
  </script>
</body>

</html>
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage