feat: Improve registration UI in first-run mode

This commit is contained in:
Ginger
2026-05-07 13:33:35 -04:00
committed by Ellis Git
parent 1af52f8610
commit dcb38d0bb1
3 changed files with 40 additions and 11 deletions
+10 -2
View File
@@ -37,6 +37,7 @@ pub(crate) fn build() -> Router<crate::State> {
template! {
struct Register use "register.html.j2" {
server_name: OwnedServerName,
is_first_run: bool,
body: RegisterBody
}
}
@@ -171,6 +172,7 @@ async fn route_register(
return response!(Register::new(
context,
services.globals.server_name().to_owned(),
services.firstrun.is_first_run(),
RegisterBody::Unavailable
));
}
@@ -195,6 +197,7 @@ async fn route_register(
return response!(Register::new(
context,
services.globals.server_name().to_owned(),
services.firstrun.is_first_run(),
RegisterBody::UsernamePrompt {
allow_federation: services.config.allow_federation,
trusted_flow_status,
@@ -245,7 +248,12 @@ async fn route_register(
}
};
response!(Register::new(context, services.globals.server_name().to_owned(), body))
response!(Register::new(
context,
services.globals.server_name().to_owned(),
services.firstrun.is_first_run(),
body
))
}
template! {
@@ -555,7 +563,7 @@ pub(super) async fn registration_flow_status(
.as_ref()
.is_some_and(|smtp| smtp.require_email_for_registration);
if !allow_registration {
if !allow_registration || services.firstrun.is_first_run() {
UntrustedFlowStatus::Unavailable
} else if services.config.recaptcha_private_site_key.is_some() || require_email {
UntrustedFlowStatus::Available { require_email }
+8 -1
View File
@@ -13,7 +13,7 @@
extract::{Expect, PostForm},
pages::{
GET_POST, Result, TemplateContext,
account::register::RegisterQuery,
account::register::{RegisterQuery, RequestedRegistrationFlow},
components::{Avatar, AvatarType, ClientScopes},
},
response,
@@ -49,17 +49,24 @@ async fn route_authorization_code(
let user_id = if let Some(user) = user.into_session() {
user.user_id
} else {
let is_first_run = services.firstrun.is_first_run();
let next = LoginTarget::AuthorizationCode(query.clone());
let uri = if query
.prompt
.is_some_and(|prompt| matches!(prompt, Prompt::Create))
|| is_first_run
{
format!(
"{}/account/register/?{}",
ROUTE_PREFIX,
serde_urlencoded::to_string(RegisterQuery {
next: Some(next),
flow: if is_first_run {
Some(RequestedRegistrationFlow::Trusted)
} else {
None
},
..Default::default()
})
.unwrap()
+22 -8
View File
@@ -12,7 +12,9 @@ Sign up
{%- block content -%}
<div class="panel narrow">
<h1 class="with-matrix-icon">
{% if let RegisterBody::UsernamePrompt { next, .. } = body && next.is_some() %}
{% if is_first_run %}
Finish setting up
{% else if let RegisterBody::UsernamePrompt { next, .. } = body && next.is_some() %}
Sign up to continue
{% else %}
Sign up
@@ -80,6 +82,11 @@ Sign up
{% let validation_errors = validation_errors.clone() %}
{% let field_errors = validation_errors.field_errors() %}
<form method="post">
{% if is_first_run %}
<p>
To finish setting up your server, choose a username and password for your account.
</p>
{% endif %}
<p>
<label for="username">Username</label>
<span class="username-input">
@@ -94,9 +101,11 @@ Sign up
{{ form::errors(field_errors, std::borrow::Cow::Borrowed("username")) }}
<small><b>Note:</b> Your username cannot be changed after you create your account.</small>
</p>
<p>
Just a few more details to finish creating your account.
</p>
{% if !is_first_run %}
<p>
Just a few more details to finish creating your account.
</p>
{% endif %}
<p>
<label for="password">Password</label>
<input type="password" name="password" autocomplete="new-password" required>
@@ -140,6 +149,9 @@ Sign up
<p>
<label for="username">Registration token</label>
<input type="text" name="registration_token" autocomplete="none" required>
{% if is_first_run %}
<small>Check the server console to find the registration token.</small>
{% endif %}
{{ form::errors(field_errors, std::borrow::Cow::Borrowed("registration_token")) }}
</p>
{% endif %}
@@ -157,14 +169,16 @@ Sign up
I agree to the <a target="_blank" href="{{ document.url }}">{{ document.name }}</a>
</label>
{% endfor %}
<small><i>All policy links will open in a new tab.</i></small>
<small>All policy links will open in a new tab.</small>
</p>
{% endif %}
<button type="submit">Continue</button>
</form>
{% endmatch %}
<div class="centered-links">
<a href="{{ crate::ROUTE_PREFIX }}/account/login">I already have an account</a>
</div>
{% if !is_first_run %}
<div class="centered-links">
<a href="{{ crate::ROUTE_PREFIX }}/account/login">I already have an account</a>
</div>
{% endif %}
</div>
{%- endblock -%}