aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/src/DBInput.svelte
blob: f520014c306de3eedcb9e5bf92cebffd50b387ca (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
<script lang="ts">
  import { postToServer } from "./utils";

  export let whereami: string;

  let pt: string;

  async function sendData() {
    const ids = ["server", "port", "database", "user", "password"];
    const body: any = {};
    for (const id of ids) {
      body[id] = (document.getElementById(id) as HTMLInputElement).value;
    }
    body["port"] = parseInt(body["port"]);

    const res = await postToServer("/check-db", body, true);
    if (res === "ok") {
      whereami = "login";
    } else {
      pt = "Error, your database credentials are wrong";
    }
  }
</script>

<main>
  <label for="server">Server:</label>
  <input type="text" id="server" value="127.0.0.1" /><br /><br />
  <label for="port">Port:</label>
  <input type="number" min="1" max="65535" id="port" value="3306" /><br /><br />
  <label for="database">Database:</label>
  <input type="text" id="database" value="aitp" /><br /><br />
  <label for="user">User:</label>
  <input type="text" id="user" value="admin" /><br /><br />
  <label for="password">Password:</label>
  <input type="password" id="password" value="qwerty" /><br /><br />
  <button type="button" on:click={sendData}>Connect</button>
  <p contenteditable="true" bind:innerHTML={pt} />
</main>

<style>
  :root {
    font-family: "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell;
  }

  main {
    text-align: center;
    padding: 1em;
    margin: 0 auto;
    font-size: 2em;
  }
  input,
  button {
    font-size: 1em;
    margin-left: 10px;
  }

  p {
    color: red;
  }
</style>