django-allauth icon indicating copy to clipboard operation
django-allauth copied to clipboard

Get user in get_email_confirmation_redirect_url when no authenticated

Open abrange opened this issue 7 years ago • 5 comments

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:

  1. User signup using only email.
  2. User clicks on confirmation link from their email.
  3. User click on "confirm email" button.
  4. 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.:

  1. 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

abrange avatar Jan 21 '18 05:01 abrange

Instead of depending on regex match you can directly use request.resolver_match.kwargs['key']

SiddharthPant avatar Sep 26 '19 19:09 SiddharthPant

This is not an allauth issue.

  1. CLose as a discussion/support
  2. Users should look closely at django request/response docs.

derek-adair avatar Aug 30 '23 16:08 derek-adair

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.

pennersr avatar Aug 31 '23 18:08 pennersr

can that not be looked up in the request object?

derek-adair avatar Aug 31 '23 20:08 derek-adair

Not without resorting to hacks like duplicating the lookups that allauth already did.

pennersr avatar Sep 01 '23 07:09 pennersr

Fixed in 0c95626d -- there now is:

get_email_verification_redirect_url(self, email_address)

pennersr avatar May 05 '24 14:05 pennersr