Skip to content

Commit d65286d

Browse files
committed
Implement email verification in the registration flow
1 parent 0bedaf3 commit d65286d

File tree

13 files changed

+320
-216
lines changed

13 files changed

+320
-216
lines changed

crates/handlers/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,9 @@ where
379379
get(self::views::register::password::get).post(self::views::register::password::post),
380380
)
381381
.route(
382-
mas_router::AccountVerifyEmail::route(),
383-
get(self::views::account::emails::verify::get)
384-
.post(self::views::account::emails::verify::post),
382+
mas_router::RegisterVerifyEmail::route(),
383+
get(self::views::register::steps::verify_email::get)
384+
.post(self::views::register::steps::verify_email::post),
385385
)
386386
.route(
387387
mas_router::AccountRecoveryStart::route(),

crates/handlers/src/views/account/emails/mod.rs

-7
This file was deleted.

crates/handlers/src/views/account/emails/verify.rs

-135
This file was deleted.

crates/handlers/src/views/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// SPDX-License-Identifier: AGPL-3.0-only
55
// Please see LICENSE in the repository root for full details.
66

7-
pub mod account;
87
pub mod app;
98
pub mod index;
109
pub mod login;

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

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use super::shared::OptionalPostAuthAction;
1818
use crate::{BoundActivityTracker, PreferredLanguage};
1919

2020
pub(crate) mod password;
21+
pub(crate) mod steps;
2122

2223
#[tracing::instrument(name = "handlers.views.register.get", skip_all, err)]
2324
pub(crate) async fn get(

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

+15-5
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,9 @@ pub(crate) async fn post(
354354

355355
repo.save().await?;
356356

357-
// TODO: redirect to the next step on the registration
358-
Ok(format!("{}", registration.id).into_response())
357+
Ok(url_builder
358+
.redirect(&mas_router::RegisterVerifyEmail::new(registration.id))
359+
.into_response())
359360
}
360361

361362
async fn render(
@@ -468,10 +469,19 @@ mod tests {
468469
let request = cookies.with_cookies(request);
469470
let response = state.request(request).await;
470471
cookies.save_cookies(&response);
471-
response.assert_status(StatusCode::OK);
472+
response.assert_status(StatusCode::SEE_OTHER);
473+
let location = response.headers().get(LOCATION).unwrap();
474+
475+
// The handler redirects with the ID as the last portion of the path
476+
let id = location
477+
.to_str()
478+
.unwrap()
479+
.rsplit('/')
480+
.next()
481+
.unwrap()
482+
.parse()
483+
.unwrap();
472484

473-
// The handler gives us the registration ID in the body for now
474-
let id = response.body().parse().unwrap();
475485
// There should be a new registration in the database
476486
let mut repo = state.repository().await.unwrap();
477487
let registration = repo.user_registration().lookup(id).await.unwrap().unwrap();
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
// Copyright 2024 New Vector Ltd.
2-
// Copyright 2021-2024 The Matrix.org Foundation C.I.C.
1+
// Copyright 2025 New Vector Ltd.
32
//
43
// SPDX-License-Identifier: AGPL-3.0-only
54
// Please see LICENSE in the repository root for full details.
65

7-
pub mod emails;
6+
pub(crate) mod verify_email;

0 commit comments

Comments
 (0)