Skip to content

Commit f4b5f7d

Browse files
committed
Use 6-digit code to add MC accounts instead of usernames
1 parent d0bd9d2 commit f4b5f7d

File tree

3 files changed

+112
-19
lines changed

3 files changed

+112
-19
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch"
1212
},
1313
"devDependencies": {
14+
"@jimmyverburgt/svelte-input-otp": "^0.0.3",
1415
"@paypal/paypal-js": "^5.1.4",
1516
"@sveltejs/adapter-node": "^1.1.0",
1617
"@sveltejs/kit": "^1.0.7",

src/routes/account/+page.svelte

+3-19
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
88
$: if (browser && !$token) goto("/login");
99
10-
let username: string;
1110
let linkToken: string | null = null;
1211
1312
function unlinkDiscord() {
@@ -25,16 +24,6 @@
2524
.then(() => refreshUser());
2625
}
2726
28-
function addMcAccount() {
29-
if (username === "") return;
30-
31-
api("account/mcAccount?username=" + username, true, "POST")
32-
.then(() => {
33-
username = "";
34-
refreshUser();
35-
});
36-
}
37-
3827
function selectCape(id: string) {
3928
api("account/selectCape?cape=" + id, true, "POST")
4029
.then(() => refreshUser());
@@ -102,10 +91,9 @@
10291
{/await}
10392
{/each}
10493
</ul>
105-
<form class="buttons add-account" on:submit|preventDefault={addMcAccount}>
106-
<input type="text" placeholder="Username" bind:value={username}>
107-
<button type="button" on:click={addMcAccount}>Add Account</button>
108-
</form>
94+
<div class="buttons">
95+
<a class="button" href="/addMcAccount">Add Account</a>
96+
</div>
10997
</div>
11098

11199
<!-- Cape -->
@@ -210,8 +198,4 @@
210198
padding: 0.5rem;
211199
font-size: 1rem;
212200
}
213-
214-
.add-account {
215-
gap: 0;
216-
}
217201
</style>

src/routes/addMcAccount/+page.svelte

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<script lang="ts">
2+
import { browser } from "$app/environment";
3+
import { goto } from "$app/navigation";
4+
import { refreshUser, token } from "$lib/user";
5+
import Navbar from "$lib/components/navbar.svelte";
6+
import { OTPRoot, OTPInput } from "@jimmyverburgt/svelte-input-otp";
7+
import { api } from "$lib/api";
8+
9+
$: if (browser && !$token) goto("/login");
10+
11+
let errorEl: HTMLSpanElement;
12+
let value = "";
13+
14+
function onComplete(code: string) {
15+
errorEl.textContent = "";
16+
17+
api("account/mcAccount?code=" + code, true, "POST")
18+
.then(() => {
19+
refreshUser();
20+
goto("/account");
21+
})
22+
.catch(error => {
23+
value = "";
24+
errorEl.textContent = error;
25+
});
26+
}
27+
</script>
28+
29+
<Navbar />
30+
31+
<div class="container">
32+
<div>
33+
<h1>Add MC account</h1>
34+
35+
<ol>
36+
<li>Launch your Minecraft client and join our server with the IP <span class="ip">mcauth.meteorclient.com</span></li>
37+
<li>You will be immediatelly kicked with a one-time 6-digit code</li>
38+
<li>Write the code into the input box below</li>
39+
</ol>
40+
41+
<OTPRoot maxLength={6} autoFocus={true} inputMode="numeric" onComplete={onComplete} bind:value className="otp-root">
42+
<OTPInput index={0} className="otp-input" focusClassName="focused" />
43+
<OTPInput index={1} className="otp-input" focusClassName="focused" />
44+
<OTPInput index={2} className="otp-input" focusClassName="focused" />
45+
<OTPInput index={3} className="otp-input" focusClassName="focused" />
46+
<OTPInput index={4} className="otp-input" focusClassName="focused" />
47+
<OTPInput index={5} className="otp-input" focusClassName="focused" />
48+
</OTPRoot>
49+
50+
<span class="error" bind:this={errorEl}></span>
51+
</div>
52+
</div>
53+
54+
<style>
55+
.container > div {
56+
display: flex;
57+
flex-direction: column;
58+
}
59+
60+
h1 {
61+
color: black;
62+
}
63+
64+
ol {
65+
margin: 2rem 0;
66+
}
67+
68+
li {
69+
text-align: left;
70+
}
71+
72+
li::marker {
73+
font-weight: bold;
74+
}
75+
76+
.ip {
77+
background-color: rgb(190, 190, 190);
78+
padding: 0.2rem 0.4rem;
79+
border-radius: 0.375rem;
80+
box-shadow: inset 0 -3px 0 rgb(99 110 123 / 40%);
81+
}
82+
83+
:global(.otp-root) {
84+
display: flex;
85+
justify-content: center;
86+
gap: 0.25rem;
87+
88+
color: black;
89+
font-size: 2rem;
90+
}
91+
92+
:global(.otp-input) {
93+
width: 1em;
94+
height: 1.4em;
95+
96+
border: 1px rgb(80, 80, 80) solid;
97+
border-radius: 0.325rem;
98+
}
99+
100+
:global(.otp-input.focused) {
101+
border-width: 2px;
102+
border-color: black;
103+
}
104+
105+
.error {
106+
color: red;
107+
}
108+
</style>

0 commit comments

Comments
 (0)