Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(account): Move RequestPasswordReset.save impl into account adapter #4034

Conversation

mecampbellsoup
Copy link
Contributor

Related to #4024.

@mecampbellsoup mecampbellsoup force-pushed the mc/account-adapter/request-password-reset branch 3 times, most recently from e1258a0 to 6bc0f43 Compare August 15, 2024 12:40
@coveralls
Copy link

coveralls commented Aug 15, 2024

Coverage Status

coverage: 96.117%. remained the same
when pulling f03eed7 on mecampbellsoup:mc/account-adapter/request-password-reset
into b8b06c3 on pennersr:main.

@mecampbellsoup mecampbellsoup force-pushed the mc/account-adapter/request-password-reset branch 2 times, most recently from d633579 to 1c3c049 Compare August 15, 2024 18:00
@mecampbellsoup
Copy link
Contributor Author

@pennersr would it be possible to get this one reviewed while you're at it?

allauth/account/adapter.py Outdated Show resolved Hide resolved
allauth/account/adapter.py Outdated Show resolved Hide resolved
@pennersr
Copy link
Owner

Must admit, I am still a bit at odds on how to proceed here. #4027 is starting to look more attractive given the impact of the change in this PR. WDYT?

@mecampbellsoup mecampbellsoup force-pushed the mc/account-adapter/request-password-reset branch 2 times, most recently from ec0f03d to 27910e1 Compare August 16, 2024 17:46
@mecampbellsoup
Copy link
Contributor Author

Must admit, I am still a bit at odds on how to proceed here. #4027 is starting to look more attractive given the impact of the change in this PR. WDYT?

I think I was able to improve this PR significantly after your review feedback - let me if the changes sway your opinion.

I'm also fine w/ #4027. If we go that route, would you want to also expand/extend #4027 to include the other forms with the ✅ in my comment here while we're at it?

@mecampbellsoup mecampbellsoup force-pushed the mc/account-adapter/request-password-reset branch 2 times, most recently from 372e22a to 6c6ae8a Compare August 16, 2024 18:03
@mecampbellsoup
Copy link
Contributor Author

@pennersr ping 😄

@@ -563,9 +563,20 @@ def is_safe_url(self, url):

return url_has_allowed_host_and_scheme(url, allowed_hosts=allowed_hosts)

def request_password_reset(self, users):
Copy link
Owner

Choose a reason for hiding this comment

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

Thoughts:

  • Naming -- it does not request the password reset
  • Behavior -- if you filter users here the emails are silently skipped which is not very obvious.

Wouldn't it make be more useful to add this method to the adapter?:

def send_password_reset_mail(self, user, email)

Then, you are free to implement that as you see fit (send real reset, skip the mail, or send another mail).

@mecampbellsoup mecampbellsoup force-pushed the mc/account-adapter/request-password-reset branch from 6c6ae8a to 35a6aac Compare August 20, 2024 22:52

def _send_password_reset_mail(self, request, email, users, **kwargs):
adapter: DefaultAccountAdapter = get_adapter()
Copy link
Owner

Choose a reason for hiding this comment

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

I think it would be good to either abort the method inside the if above by returning return email, or, to reintroduce the else. As is now, both cases are executed (the if and the else part), and while that works because users is empty it did trip me over while reviewing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good catch though!

allauth/account/forms.py Show resolved Hide resolved
This new adapter method can be used to apply custom logic regarding
whether a user should be able to initiate the reset password flow.
@mecampbellsoup mecampbellsoup force-pushed the mc/account-adapter/request-password-reset branch from 35a6aac to f03eed7 Compare August 22, 2024 15:29
@pennersr pennersr merged commit b242ded into pennersr:main Aug 22, 2024
37 checks passed
@mecampbellsoup mecampbellsoup deleted the mc/account-adapter/request-password-reset branch August 22, 2024 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants