Skip to content

Commit cba0cd6

Browse files
committed
test customization user journeu
1 parent 4f68dbc commit cba0cd6

File tree

7 files changed

+258
-21
lines changed

7 files changed

+258
-21
lines changed

crates/handlers/src/views/register/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ pub(crate) async fn get(
9494
println!("No ContinueAuthorizationGrant action found in query");
9595
}
9696
println!("Preparing to render registration template");
97+
9798
//:tchap:
98-
9999
let mut ctx = RegisterContext::new(providers);
100100
let post_action = query
101101
.load_context(&mut repo)
@@ -105,7 +105,7 @@ pub(crate) async fn get(
105105
ctx = ctx.with_post_action(action);
106106
}
107107

108-
let ctx = ctx.with_csrf(csrf_token.form_value()).with_language(locale);
108+
let ctx: mas_templates::WithLanguage<mas_templates::WithCsrf<RegisterContext>> = ctx.with_csrf(csrf_token.form_value()).with_language(locale);
109109

110110
let content = templates.render_register(&ctx)?;
111111

crates/handlers/src/views/register/password.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use mas_data_model::{BoxClock, BoxRng, CaptchaConfig};
2222
use mas_i18n::DataLocale;
2323
use mas_matrix::HomeserverConnection;
2424
use mas_policy::Policy;
25-
use mas_router::UrlBuilder;
25+
use mas_router::{PostAuthAction, UrlBuilder};
2626
use mas_storage::{
2727
BoxRepository, RepositoryAccess,
2828
queue::{QueueJobRepositoryExt as _, SendEmailAuthenticationCodeJob},
@@ -42,6 +42,9 @@ use crate::{
4242
views::shared::OptionalPostAuthAction,
4343
};
4444

45+
use tchap::email_to_mxid_localpart;
46+
47+
4548
#[derive(Debug, Deserialize, Serialize)]
4649
pub(crate) struct RegisterForm {
4750
username: String,
@@ -148,7 +151,8 @@ pub(crate) async fn post(
148151
return Ok(StatusCode::METHOD_NOT_ALLOWED.into_response());
149152
}
150153

151-
let form = cookie_jar.verify_form(&clock, form)?;
154+
//:tchap
155+
let mut form = cookie_jar.verify_form(&clock, form)?;
152156

153157
let (csrf_token, cookie_jar) = cookie_jar.csrf_token(&clock, &mut rng);
154158

@@ -165,6 +169,31 @@ pub(crate) async fn post(
165169
.await
166170
.is_ok();
167171

172+
173+
//test login_hint
174+
println!("Starting password post process");
175+
let maybe_login_hint = if let Some(PostAuthAction::ContinueAuthorizationGrant { id }) = &query.post_auth_action {
176+
repo.oauth2_authorization_grant()
177+
.lookup(*id)
178+
.await?
179+
.and_then(|grant| grant.login_hint)
180+
} else {
181+
None
182+
};
183+
184+
println!("login hint {:?}", maybe_login_hint);
185+
186+
//create a clone of the form with substitute for the username and email
187+
form = RegisterForm {
188+
username: maybe_login_hint.clone().map_or(form.username, |hint| email_to_mxid_localpart(&hint)),
189+
email: maybe_login_hint.clone().map_or(form.email, |hint| hint),
190+
password: form.password,
191+
password_confirm: form.password_confirm,
192+
accept_terms: form.accept_terms,
193+
captcha: form.captcha, // You may need to adjust this based on your captcha implementation
194+
};
195+
196+
168197
// Validate the form
169198
let state = {
170199
let mut state = form.to_form_state();
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{#
2+
Copyright 2024, 2025 New Vector Ltd.
3+
Copyright 2021-2024 The Matrix.org Foundation C.I.C.
4+
5+
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
6+
Please see LICENSE files in the repository root for full details.
7+
-#}
8+
9+
{% extends "base.html" %}
10+
11+
{% from "components/idp_brand.html" import logo %}
12+
13+
{% block content %}
14+
<form method="GET" class="flex flex-col gap-10" action="{{ '/register/password' | prefix_url }}">
15+
<header class="page-heading">
16+
<div class="icon">
17+
{{ icon.user_profile_solid() }}
18+
</div>
19+
20+
<div class="header">
21+
<h1 class="title">{{ _("create_account") }}</h1>
22+
23+
{% if features.password_registration and False %}
24+
<p class="text">{{ _("mas.register.create_account.description") }}</p>
25+
{% endif %}
26+
</div>
27+
</header>
28+
29+
<!-- #tchap# -->
30+
{% if features.password_registration and False %}
31+
<!-- #tchap# -->
32+
{% call(f) field.field(label=_("common.username"), name="username", form_state=form) %}
33+
<input {{ field.attributes(f) }} class="cpd-text-control" type="text" autocomplete="username" autocorrect="off" autocapitalize="off" />
34+
<div class="cpd-form-message cpd-form-help-message" id="{{ f.id }}-help">
35+
@username:{{ branding.server_name }}
36+
</div>
37+
{% endcall %}
38+
{% endif %}
39+
40+
<div class="cpd-form-root">
41+
{% for key, value in next["params"] | default({}) | items %}
42+
<input type="hidden" name="{{ key }}" value="{{ value }}" />
43+
{% endfor %}
44+
45+
{% if features.password_registration %}
46+
{{ button.button(text=_("mas.register.continue_with_email")) }}
47+
{% endif %}
48+
49+
{% if providers %}
50+
{% set params = next["params"] | default({}) | to_params(prefix="?") %}
51+
{% for provider in providers %}
52+
{% set name = provider.human_name or (provider.issuer | simplify_url(keep_path=True)) or provider.id %}
53+
<a class="cpd-button {%- if provider.brand_name %} has-icon {%- endif %}" data-kind="secondary" data-size="lg" href="{{ ('/upstream/authorize/' ~ provider.id ~ params) | prefix_url }}">
54+
{{ logo(provider.brand_name) }}
55+
{{ _("mas.login.continue_with_provider", provider=name) }}
56+
</a>
57+
{% endfor %}
58+
{% endif %}
59+
60+
{% set params = next["params"] | default({}) | to_params(prefix="?") %}
61+
{{ button.link_tertiary(text=_("mas.register.call_to_login"), href="/login" ~ params) }}
62+
</div>
63+
</form>
64+
{% endblock content %}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{#
2+
Copyright 2024, 2025 New Vector Ltd.
3+
Copyright 2021-2024 The Matrix.org Foundation C.I.C.
4+
5+
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
6+
Please see LICENSE files in the repository root for full details.
7+
-#}
8+
9+
{% extends "base.html" %}
10+
11+
{% from "components/password_field.html" import password_field %}
12+
13+
{% block content %}
14+
<header class="page-heading">
15+
<div class="icon">
16+
{{ icon.user_profile_solid() }}
17+
</div>
18+
19+
<div class="header">
20+
<h1 class="title">{{ _("mas.register.create_account.heading") }}</h1>
21+
</div>
22+
</header>
23+
24+
<form method="POST" class="cpd-form-root">
25+
{% for error in form.errors %}
26+
{# Special case for the captcha error, as we want to put it at the bottom #}
27+
{% if error.kind != "captcha" %}
28+
<div class="text-critical font-medium">
29+
{{ errors.form_error_message(error=error) }}
30+
</div>
31+
{% endif %}
32+
{% endfor %}
33+
34+
<input type="hidden" name="csrf" value="{{ csrf_token }}" />
35+
36+
<!-- :tchap: -->
37+
{% call(f) field.field(class="", label=_("common.username"), name="username", form_state=form) %}
38+
<input {{ field.attributes(f) }} class="cpd-text-control" type="text" autocomplete="username" autocorrect="off" autocapitalize="none" required value="MATRIX_ID_SHOULD_BE_POPULATED_HERE"/>
39+
{% endcall %}
40+
41+
{% call(f) field.field(label=_("common.email_address"), name="email", form_state=form) %}
42+
<input {{ field.attributes(f) }} class="cpd-text-control" type="email" autocomplete="email" required value="[email protected]"/>
43+
{% endcall %}
44+
<div class="hidden">
45+
</div>
46+
<!-- :tchap: -->
47+
48+
{% call(f) field.field(label=_("common.password"), name="password", form_state=form) %}
49+
<!--<input {{ field.attributes(f) }} class="cpd-text-control" type="password" autocomplete="new-password" required /> -->
50+
{{ password_field(input_attributes=field.attributes(f), input_autocomplete="new-password") }}
51+
{% endcall %}
52+
53+
{% call(f) field.field(label=_("common.password_confirm"), name="password_confirm", form_state=form) %}
54+
<!--<input {{ field.attributes(f) }} class="cpd-text-control" type="password" autocomplete="new-password" required /> -->
55+
{{ password_field(input_attributes=field.attributes(f), input_autocomplete="new-password") }}
56+
{% endcall %}
57+
{% if branding.tos_uri %}
58+
{% call(f) field.field(label=_("mas.register.terms_of_service", tos_uri=branding.tos_uri), name="accept_terms", form_state=form, inline=true, class="my-4") %}
59+
<div class="cpd-form-inline-field-control">
60+
<div class="cpd-checkbox-container">
61+
<input {{ field.attributes(f) }} class="cpd-checkbox-input" type="checkbox" required />
62+
<div class="cpd-checkbox-ui">
63+
{{ icon.check() }}
64+
</div>
65+
</div>
66+
</div>
67+
{% endcall %}
68+
{% endif %}
69+
70+
{{ captcha.form(class="mb-4 self-center") }}
71+
72+
{% for error in form.errors %}
73+
{# Special case for the captcha error #}
74+
{% if error.kind == "captcha" %}
75+
<div class="text-critical font-medium text-center -mt-4 mb-4">
76+
{{ errors.form_error_message(error=error) }}
77+
</div>
78+
{% endif %}
79+
{% endfor %}
80+
81+
{{ button.button(text=_("action.continue")) }}
82+
83+
{% set params = next["params"] | default({}) | to_params(prefix="?") %}
84+
{{ button.link_tertiary(text=_("mas.register.call_to_login"), href="/login" ~ params) }}
85+
</form>
86+
{% endblock content %}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{#
2+
Copyright 2025 New Vector Ltd.
3+
4+
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
5+
Please see LICENSE files in the repository root for full details.
6+
-#}
7+
8+
{% extends "base.html" %}
9+
10+
{% block content %}
11+
<header class="page-heading">
12+
<div class="icon">
13+
{{ icon.visibility_on() }}
14+
</div>
15+
<div class="header">
16+
<h1 class="title">{{ _("mas.choose_display_name.headline") }}</h1>
17+
<p class="text">{{ _("mas.choose_display_name.description") }}</p>
18+
</div>
19+
</header>
20+
21+
<div class="cpd-form-root">
22+
<form method="POST" class="cpd-form-root">
23+
{% if form.errors is not empty %}
24+
{% for error in form.errors %}
25+
<div class="text-critical font-medium">
26+
{{ errors.form_error_message(error=error) }}
27+
</div>
28+
{% endfor %}
29+
{% endif %}
30+
31+
<input type="hidden" name="csrf" value="{{ csrf_token }}" />
32+
<input type="hidden" name="action" value="set" />
33+
34+
{% call(f) field.field(label=_("common.display_name"), name="display_name", form_state=form, class="mb-4") %}
35+
<input {{ field.attributes(f) }}
36+
id="cpd-text-control"
37+
type="text"
38+
maxlength="256"
39+
class="cpd-text-control"
40+
required
41+
value="SHOULD_BE_POPULATED_HERE"
42+
/>
43+
{% endcall %}
44+
45+
{{ button.button(text=_("action.continue")) }}
46+
</form>
47+
48+
<form method="POST" class="cpd-form-root">
49+
<input type="hidden" name="csrf" value="{{ csrf_token }}" />
50+
<input type="hidden" name="action" value="skip" />
51+
{{ button.button(text=_("action.skip"), kind="tertiary") }}
52+
</form>
53+
</div>
54+
{% endblock content %}

0 commit comments

Comments
 (0)