aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/Password.svelte
blob: dc77c0d3b965a81b0218d04b798376fc2d05564c (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
82
<script lang="ts">
  import { t } from "$lib/translations";
  import { preventDefault } from "svelte/legacy";

  import Icon from "$comp/Icon.svelte";
  import { focus, fail, post } from "$lib/utils";
  import { password as pw, passwordPrompt } from "$lib/store";

  let { user } = $props();

  let password = $state();
  let { username } = user;
  let revealPassword = $state(false);

  let cancel = () => ($passwordPrompt = false);

  let submit = async () => {
    try {
      await post("/password", { password });
      $passwordPrompt = false;
      $pw = password;
    } catch (e) {
      fail("Invalid password, try again");
    }
  };
</script>

<div
  class="fixed inset-0 bg-base-100 bg-opacity-90 overflow-y-auto h-full w-full z-50"
>
  <div
    class="relative top-1/3 mx-auto p-5 border w-96 shadow-lg rounded-md bg-base-100 space-y-5"
  >
    <h1 class="text-center text-2xl font-semibold">
      {$t("user.settings.pleaseEnterYourPassword")}
    </h1>
    <form onsubmit={preventDefault(submit)} class="space-y-2">
      <label
        for="password"
        class="input flex items-center justify-center gap-2 w-full"
      >
        {#if revealPassword}
          <input
            class="clean"
            name="password"
            type="text"
            required
            bind:value={password}
            autocapitalize="none"
            use:focus
          />
        {:else}
          <input
            class="clean"
            name="password"
            type="password"
            required
            bind:value={password}
            autocapitalize="none"
            use:focus
          />
        {/if}
        <iconify-icon
          class="cursor-pointer"
          onclick={() => (revealPassword = !revealPassword)}
          icon={revealPassword ? "ph:eye-bold" : "ph:eye-slash-bold"}
          width="32"
        ></iconify-icon>
      </label>
      <div class="w-full flex gap-2">
        <button
          type="button"
          class="btn !w-auto grow"
          onclick={cancel}
          onkeydown={cancel}>Cancel</button
        >
        <button type="submit" class="btn btn-accent !w-auto grow">Submit</button
        >
      </div>
    </form>
  </div>
</div>