django-allauth
django-allauth copied to clipboard
Get user in get_email_confirmation_redirect_url when no authenticated
I am trying to redirect a user to a specific URL based on the user, but I can't find a way to know which is the user or email within
def get_email_confirmation_redirect_url(self, request)
that just has confirmed their email in order to prepare the URL.
As additional information, my complete flow is:
- User signup using only email.
- User clicks on confirmation link from their email.
- User click on "confirm email" button.
- Now, I would like to show a set password form (with a Name field too).
In (3), I using get_email_confirmation_redirect_url to get the URL used by SetPassword, so it could be the next page shown.
Edit: I have figure out a way to get the user, it's working but not sure if its the best way.:
- get key in URL and 2) get the user using EmailConfirmationHMAC.from_key
key_ = re.match(r"/accounts/confirm-email/(.+)/.*", request.path).group(1)
user = EmailConfirmationHMAC.from_key(key_).email_address.user
Thanks, Alvaro
Instead of depending on regex match you can directly use request.resolver_match.kwargs['key']
This is not an allauth issue.
- CLose as a discussion/support
- Users should look closely at django request/response docs.
It would definitely make sense to pass along the email that is being confirmed to get_email_confirmation_redirect_url()
. Though, that is a backwards incompatible change to the adapter.
can that not be looked up in the request object?
Not without resorting to hacks like duplicating the lookups that allauth already did.
Fixed in 0c95626d -- there now is:
get_email_verification_redirect_url(self, email_address)