add migrate
This commit is contained in:
parent
bb96baaf4f
commit
1bf37fb564
7 changed files with 159 additions and 115 deletions
|
|
@ -32,7 +32,6 @@ export default defineConfig({
|
||||||
autogenerate: { directory: "services" },
|
autogenerate: { directory: "services" },
|
||||||
},
|
},
|
||||||
{ slug: "donate" },
|
{ slug: "donate" },
|
||||||
{ slug: "change-password" },
|
|
||||||
{ slug: "tos" },
|
{ slug: "tos" },
|
||||||
{ slug: "code" },
|
{ slug: "code" },
|
||||||
{ slug: "privacy-policy" },
|
{ slug: "privacy-policy" },
|
||||||
|
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
---
|
|
||||||
title: How to Change Your Password
|
|
||||||
---
|
|
||||||
|
|
||||||
You can change your account's password at https://matrix.federated.nexus/_continuwuity/account/password/change, or your favorite Matrix client.
|
|
||||||
Any other page will not correctly change your password.
|
|
||||||
|
|
@ -49,7 +49,3 @@ From there, accept the invitation to the "Federated Nexus Community" room, and y
|
||||||
Federated Nexus runs [Continuwuity](https://continuwuity.org/), a Rust implementation of the Matrix specification. This means it doesn't quite have all the features of [Synapse](https://element-hq.github.io/synapse/latest/), but it's much more performant. Some features that Continuwuity lack include:
|
Federated Nexus runs [Continuwuity](https://continuwuity.org/), a Rust implementation of the Matrix specification. This means it doesn't quite have all the features of [Synapse](https://element-hq.github.io/synapse/latest/), but it's much more performant. Some features that Continuwuity lack include:
|
||||||
|
|
||||||
- Rooms older than v3: In Matrix, each room follows a certain version of the Matrix spec. Continuwuity currently supports room versions v3 to v12, covering the vast majority of rooms. Room version v2 is _very very_ old, and should never be used, but some rooms still use it. With Federated Nexus, you won't be able to join these rooms, sorry.
|
- Rooms older than v3: In Matrix, each room follows a certain version of the Matrix spec. Continuwuity currently supports room versions v3 to v12, covering the vast majority of rooms. Room version v2 is _very very_ old, and should never be used, but some rooms still use it. With Federated Nexus, you won't be able to join these rooms, sorry.
|
||||||
|
|
||||||
## Authentication
|
|
||||||
|
|
||||||
[Matrix](https://matrix.org) is the hub of Federated Nexus, everything else authenticates against Matrix. This means that when you change your password on Matrix, you'll need to log into everything else with the new password.
|
|
||||||
|
|
|
||||||
|
|
@ -1,100 +0,0 @@
|
||||||
---
|
|
||||||
import StarlightPage from "@astrojs/starlight/components/StarlightPage.astro"
|
|
||||||
import "../styles/page.css"
|
|
||||||
---
|
|
||||||
|
|
||||||
<StarlightPage
|
|
||||||
frontmatter={{ title: "Sign In to Federated Nexus", template: "splash" }}
|
|
||||||
>
|
|
||||||
<form method="post" action="https://auth.federated.nexus/login">
|
|
||||||
<input type="hidden" name="state" />
|
|
||||||
<input type="hidden" name="nonce" />
|
|
||||||
<input type="hidden" name="user_id" />
|
|
||||||
<input type="hidden" name="access_token" />
|
|
||||||
<input type="hidden" name="redirect_uri" />
|
|
||||||
|
|
||||||
<label>
|
|
||||||
Username
|
|
||||||
<input type="text" />
|
|
||||||
</label>
|
|
||||||
<label>
|
|
||||||
Password
|
|
||||||
<input type="password" />
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<noscript class="error">
|
|
||||||
This form will not function without JavaScript.
|
|
||||||
</noscript>
|
|
||||||
<span id="error" class="error"> </span>
|
|
||||||
<button type="submit"><span>Submit</span></button>
|
|
||||||
|
|
||||||
<a href="/register/">Don't have an account? Sign up now!</a>
|
|
||||||
</form>
|
|
||||||
</StarlightPage>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
const params = new URLSearchParams(window.location.search)
|
|
||||||
for (const name of ["redirect_uri", "state", "nonce"]) {
|
|
||||||
const input = document.querySelector(
|
|
||||||
`input[name="${name}"]`,
|
|
||||||
) as HTMLInputElement
|
|
||||||
if (input && params.has(name)) input.value = params.get(name)!
|
|
||||||
}
|
|
||||||
|
|
||||||
const form = document.querySelector("form")!
|
|
||||||
const error = document.querySelector("#error")! as HTMLSpanElement
|
|
||||||
form.addEventListener("submit", async (e) => {
|
|
||||||
e.preventDefault()
|
|
||||||
|
|
||||||
error.style.display = "none"
|
|
||||||
|
|
||||||
try {
|
|
||||||
const username = (
|
|
||||||
form.querySelector('[type="text"]') as HTMLInputElement
|
|
||||||
).value
|
|
||||||
const password = (
|
|
||||||
form.querySelector('[type="password"]') as HTMLInputElement
|
|
||||||
).value
|
|
||||||
|
|
||||||
const session =
|
|
||||||
localStorage.getItem("session") ?? crypto.randomUUID()
|
|
||||||
localStorage.setItem("session", session)
|
|
||||||
|
|
||||||
const res = await fetch(
|
|
||||||
"https://matrix.federated.nexus/_matrix/client/v3/login",
|
|
||||||
{
|
|
||||||
method: "POST",
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({
|
|
||||||
type: "m.login.password",
|
|
||||||
device_id: session,
|
|
||||||
initial_device_display_name: `Federated Nexus Login from ${navigator.userAgent}`,
|
|
||||||
identifier: { type: "m.id.user", user: username },
|
|
||||||
password,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!res.ok) {
|
|
||||||
throw new Error((await res.json())["error"])
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await res.json()
|
|
||||||
|
|
||||||
const id = form.querySelector(
|
|
||||||
'input[name="user_id"]',
|
|
||||||
) as HTMLInputElement
|
|
||||||
id.value = data.user_id
|
|
||||||
|
|
||||||
const token = form.querySelector(
|
|
||||||
'input[name="access_token"]',
|
|
||||||
) as HTMLInputElement
|
|
||||||
token.value = data.access_token
|
|
||||||
|
|
||||||
form.submit()
|
|
||||||
} catch (err: any) {
|
|
||||||
error.style = ""
|
|
||||||
error.textContent = err.message || "Login failed"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
155
src/pages/migrate.astro
Normal file
155
src/pages/migrate.astro
Normal file
|
|
@ -0,0 +1,155 @@
|
||||||
|
---
|
||||||
|
import StarlightPage from "@astrojs/starlight/components/StarlightPage.astro"
|
||||||
|
import "../styles/page.css"
|
||||||
|
---
|
||||||
|
|
||||||
|
<StarlightPage
|
||||||
|
frontmatter={{ title: "Migrate Your Account", template: "splash" }}
|
||||||
|
>
|
||||||
|
<section id="login">
|
||||||
|
<p>
|
||||||
|
Log in with your old Federated Nexus username and password to move
|
||||||
|
your account to <a href="https://account.federated.nexus"
|
||||||
|
>account.federated.nexus</a
|
||||||
|
>. Your username, rooms and messages stay the same.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<form>
|
||||||
|
<label>
|
||||||
|
Username
|
||||||
|
<input
|
||||||
|
name="username"
|
||||||
|
type="text"
|
||||||
|
autocomplete="username"
|
||||||
|
autocapitalize="none"
|
||||||
|
spellcheck="false"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
Password
|
||||||
|
<input
|
||||||
|
name="password"
|
||||||
|
type="password"
|
||||||
|
autocomplete="current-password"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<noscript class="error">
|
||||||
|
This form will not function without JavaScript.
|
||||||
|
</noscript>
|
||||||
|
<span class="error"></span>
|
||||||
|
<button type="submit"><span>Continue</span></button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Forgot your password? Email <a href="mailto:info@federated.nexus"
|
||||||
|
>info@federated.nexus</a
|
||||||
|
>.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="email" hidden>
|
||||||
|
<p>
|
||||||
|
You're migrating <strong id="user-id"></strong>. Enter your email
|
||||||
|
address. We'll send you a link to set up how you log in, and it's
|
||||||
|
where account recovery emails will go.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<form>
|
||||||
|
<input type="hidden" name="session" />
|
||||||
|
<label>
|
||||||
|
Email
|
||||||
|
<input
|
||||||
|
name="email"
|
||||||
|
type="email"
|
||||||
|
autocomplete="email"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<span class="error"></span>
|
||||||
|
<button type="submit"><span>Send link</span></button>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="done" hidden>
|
||||||
|
<p>
|
||||||
|
We've sent a link to <strong id="sent-to"></strong> to set up how you
|
||||||
|
log in. It expires in an hour.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Didn't get it? Check your spam folder, or start again from the
|
||||||
|
<a href="https://account.federated.nexus">login page</a>.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
</StarlightPage>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const api = "https://auth.federated.nexus"
|
||||||
|
|
||||||
|
const login = document.querySelector("#login") as HTMLElement
|
||||||
|
const email = document.querySelector("#email") as HTMLElement
|
||||||
|
const done = document.querySelector("#done") as HTMLElement
|
||||||
|
|
||||||
|
for (const error of document.querySelectorAll<HTMLElement>("span.error")) {
|
||||||
|
error.style.display = "none"
|
||||||
|
}
|
||||||
|
|
||||||
|
const submit = async (step: HTMLElement, path: string) => {
|
||||||
|
const form = step.querySelector("form")!
|
||||||
|
const error = form.querySelector("span.error") as HTMLSpanElement
|
||||||
|
const button = form.querySelector("button")!
|
||||||
|
error.style.display = "none"
|
||||||
|
button.disabled = true
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(api + path, {
|
||||||
|
method: "POST",
|
||||||
|
body: new URLSearchParams(
|
||||||
|
new FormData(form) as unknown as Record<string, string>,
|
||||||
|
),
|
||||||
|
})
|
||||||
|
const data = await res.json().catch(() => ({}))
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(
|
||||||
|
data.error ?? "Something went wrong. Try again later.",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
} catch (err: any) {
|
||||||
|
error.style.display = ""
|
||||||
|
error.textContent =
|
||||||
|
err instanceof TypeError
|
||||||
|
? "Couldn't connect. Try again later."
|
||||||
|
: err.message
|
||||||
|
return null
|
||||||
|
} finally {
|
||||||
|
button.disabled = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
login.querySelector("form")!.addEventListener("submit", async (e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
const data = await submit(login, "/migrate/login")
|
||||||
|
if (!data) return
|
||||||
|
|
||||||
|
email.querySelector<HTMLInputElement>('[name="session"]')!.value =
|
||||||
|
data.session
|
||||||
|
document.querySelector("#user-id")!.textContent = data.userId
|
||||||
|
login.hidden = true
|
||||||
|
email.hidden = false
|
||||||
|
email.querySelector<HTMLInputElement>('[name="email"]')!.focus()
|
||||||
|
})
|
||||||
|
|
||||||
|
email.querySelector("form")!.addEventListener("submit", async (e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
const data = await submit(email, "/migrate")
|
||||||
|
if (!data) return
|
||||||
|
|
||||||
|
document.querySelector("#sent-to")!.textContent = data.email
|
||||||
|
email.hidden = true
|
||||||
|
done.hidden = false
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
@ -8,12 +8,12 @@ import "../styles/page.css"
|
||||||
>
|
>
|
||||||
<form method="post" action="https://register.federated.nexus">
|
<form method="post" action="https://register.federated.nexus">
|
||||||
<label>
|
<label>
|
||||||
Username (alphanumeric only, no spaces)
|
Username (letters, numbers, _ . and -, starting with a letter)
|
||||||
<input
|
<input
|
||||||
name="username"
|
name="username"
|
||||||
type="text"
|
type="text"
|
||||||
required
|
required
|
||||||
pattern="^[A-Za-z0-9]+$"
|
pattern="[A-Za-z][A-Za-z0-9_.\-]{0,63}"
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,6 @@ import "../styles/page.css"
|
||||||
template: "splash",
|
template: "splash",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Once approved, you will receive an email with a username and password.
|
Once approved, you will receive an email with your username and a link to
|
||||||
Approval usually takes less than two business days.
|
set your password. Approval usually takes less than two business days.
|
||||||
</StarlightPage>
|
</StarlightPage>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue