Skip to content

Commit 3ba09b0

Browse files
committed
customize template when linking account
1 parent 40e5b1f commit 3ba09b0

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

crates/handlers/src/upstream_oauth2/link.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ pub(crate) async fn get(
487487
.with_code("User exists")
488488
.with_description(format!(
489489
r"Upstream account provider returned {localpart:?} as username,
490-
which is not linked to that upstream account"
490+
which is not linked to that upstream account. Homeserver does not allow linking existing account"
491491
))
492492
.with_language(&locale);
493493

@@ -509,7 +509,13 @@ pub(crate) async fn get(
509509
})
510510
.await?;
511511

512-
if res.valid() {
512+
if provider.allow_existing_users && maybe_existing_user.is_some(){
513+
// use existing user if allowed
514+
ctx
515+
.with_existing_user(maybe_existing_user.unwrap())
516+
.with_localpart(localpart, true)
517+
}
518+
else if res.valid() {
513519
// The username passes the policy check, add it to the context
514520
ctx.with_localpart(
515521
localpart,

crates/templates/src/context.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,7 @@ pub struct UpstreamRegister {
13661366
imported_email: Option<String>,
13671367
force_email: bool,
13681368
form_state: FormState<UpstreamRegisterFormField>,
1369+
existing_user: Option<User>,
13691370
}
13701371

13711372
impl UpstreamRegister {
@@ -1386,6 +1387,7 @@ impl UpstreamRegister {
13861387
imported_email: None,
13871388
force_email: false,
13881389
form_state: FormState::default(),
1390+
existing_user: None,
13891391
}
13901392
}
13911393

@@ -1447,6 +1449,15 @@ impl UpstreamRegister {
14471449
pub fn with_form_state(self, form_state: FormState<UpstreamRegisterFormField>) -> Self {
14481450
Self { form_state, ..self }
14491451
}
1452+
1453+
/// Set the imported email
1454+
#[must_use]
1455+
pub fn with_existing_user(self, user: User) -> Self {
1456+
Self {
1457+
existing_user: Some(user),
1458+
..self
1459+
}
1460+
}
14501461
}
14511462

14521463
impl TemplateContext for UpstreamRegister {

templates/pages/upstream_oauth2/do_register.html

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,24 @@
1111
{% from "components/idp_brand.html" import logo %}
1212

1313
{% block content %}
14-
{% if force_localpart %}
14+
{% if existing_user %}
15+
<header class="page-heading">
16+
<div class="icon">
17+
{{ icon.download() }}
18+
</div>
19+
20+
<div class="header">
21+
<h1 class="title">
22+
{# todo translate #}
23+
Link your existing account
24+
</h1>
25+
<p class="text">
26+
{# todo translate #}
27+
We have detected you have an existing account, confirm you want to use this account
28+
</p>
29+
</div>
30+
</header>
31+
{% elif force_localpart %}
1532
<header class="page-heading">
1633
<div class="icon">
1734
{{ icon.download() }}
@@ -188,8 +205,11 @@ <h3 class="provider">
188205
{% endcall %}
189206
{% endif %}
190207

191-
192-
{{ button.button(text=_("action.create_account")) }}
208+
{% if existing_user %}
209+
{{ button.button(text=_("mas.upstream_oauth2.register.link_existing")) }}
210+
{% else %}
211+
{{ button.button(text=_("action.create_account")) }}
212+
{% endif %}
193213
</form>
194214

195215
{# Leave this for now as we don't have that fully designed yet

0 commit comments

Comments
 (0)