Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Forgot password flow #2866

Merged
merged 12 commits into from
Jun 28, 2024
Merged

Forgot password flow #2866

merged 12 commits into from
Jun 28, 2024

Conversation

sandhose
Copy link
Member

@sandhose sandhose commented Jun 21, 2024

Fixes #13

This implements the password recovery flow as designed here.

The feature is disabled by default.

A few things to do still to exactly match the designs:

  • The password form isn't interactive at all
  • The recovery email is missing the 'user box'. This is mostly because querying the displayname was potentially annoying here, and I'm not sure about implementing that box in an email (<table> maybe?)
  • We're not sending a confirmation email once the password has been changed. I think we should do this separately to also add the same notification to the password change flow

Open questions:

  • Should the initial form have a CAPTCHA? It's basically an open form to spam someone's email
  • I wonder if we should move that page to the React app? That would work by extending the setPassword API to accept a recovery 'ticket', and make it easier to have the same form validation logic

I made it so that it's reviewable commit by commit

Copy link

cloudflare-workers-and-pages bot commented Jun 21, 2024

Deploying matrix-authentication-service-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: a792639
Status: ✅  Deploy successful!
Preview URL: https://a5e908fd.matrix-authentication-service-docs.pages.dev
Branch Preview URL: https://quenting-forgot-password.matrix-authentication-service-docs.pages.dev

View logs

@sandhose sandhose force-pushed the quenting/forgot-password branch 12 times, most recently from 8631ed9 to b32c534 Compare June 27, 2024 11:49
@sandhose sandhose requested a review from reivilibre June 27, 2024 11:56
@sandhose sandhose marked this pull request as ready for review June 27, 2024 11:56
Copy link
Contributor

@reivilibre reivilibre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems reasonable to me overall. I'll spin it up in a browser tomorrow but ran out of time today

crates/data-model/src/users.rs Outdated Show resolved Hide resolved
crates/data-model/src/users.rs Show resolved Hide resolved
crates/storage-pg/src/user/recovery.rs Show resolved Hide resolved
crates/storage-pg/src/user/recovery.rs Show resolved Hide resolved
translations/en.json Outdated Show resolved Hide resolved
translations/en.json Show resolved Hide resolved
Comment on lines +95 to +121
// XXX: is that the right thing to do?
return Ok((
cookie_jar,
url_builder.redirect(&mas_router::AccountRecoveryStart),
)
.into_response());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should say the link 'expired' or something. I guess.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean it's really that you got to the wrong place, as lookup_session will give you even consumed/expired sessions. A 404 would be better, but we don't have a nice way to display that page.

I think we should track in a separate issue to have nice 404 pages for when you go to pages with an unknown ID, because we have many cases like that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well this kind of raises another Q to me: Do we really want to keep old expired sessions around in the DB forever?

I can't say I see much reason to keep them for a very long time, because it's just going to be ever-growing cruft.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally we don't cleanup most things in the database. I rather soft-delete stuff and keep things for now, and introduce maintenance/cleanup tasks later once we have a nice way of doing this?

Copy link
Contributor

@reivilibre reivilibre Jun 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cynical take: that's how you get Synapse ;-)

but fine

crates/handlers/src/views/recovery/finish.rs Show resolved Hide resolved
.with_language(&locale),
)?;
return Ok((cookie_jar, Html(rendered)).into_response());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the logic above this seems to be in common with the get route; wonder if can we pull this out into a separate function without it being too awkward?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that's a thing I haven't really figured out how to do nicely, that wouldn't be the only place having this issue :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any insight why this is hard? what happens if you try it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such a function would have to return either

  • an error
  • a response
  • the user + the repository because passing it as a &mut won't work because of Send/Sync shenanigans…

Which means a custom enum for the return type of such a method? or at least a Result<Either<Response, (User, BoxRepository)>, FancyError>, which isn't exactly pretty?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok for now

@sandhose sandhose requested a review from reivilibre June 28, 2024 12:26
@sandhose sandhose force-pushed the quenting/forgot-password branch from c401045 to a792639 Compare June 28, 2024 13:51
@sandhose sandhose enabled auto-merge (rebase) June 28, 2024 13:51
@sandhose sandhose merged commit 756f2c0 into main Jun 28, 2024
16 checks passed
@sandhose sandhose deleted the quenting/forgot-password branch July 29, 2024 12:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Password recovery
2 participants