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

ImproperlyConfigured registration email verification #17

Closed
fessacchiotto opened this issue Mar 29, 2020 · 15 comments
Closed

ImproperlyConfigured registration email verification #17

fessacchiotto opened this issue Mar 29, 2020 · 15 comments

Comments

@fessacchiotto
Copy link

hi! when I try to access the following link in the email confirmation sent on user registration:

http://localhost:8000/dj-rest-auth/registration/account-confirm-email/MQ:1jIgPr:Ayckd0pouL4B-foYgl2wjdSCYOY/

I receive the following error:

ImproperlyConfigured
TemplateResponseMixin requires either a definition of 'template_name' or an implementation of 'get_template_names()'

Where should I create such a template? how should I name the template? it would be great if you could point me to some documentation or shed some light on how to proceed further. cheers!

@iMerica
Copy link
Owner

iMerica commented Mar 29, 2020

Hi 👋, thanks for creating this issue.

It looks like the issue you're describing was recorded in issue #290 of the upstream project.

Can you see if any of the workarounds in that issue work for you? If not, I'll investigate a fix.

@fessacchiotto
Copy link
Author

thanks for your pointer. unfortunately the workaround doesn't work for me... :-(
any help will be appreciated as the user registration is an important part of the process... thank you!

@anuj9196
Copy link
Contributor

@fessacchiotto You need to check endpoints In your case Django is trying to load the template.

You need to make a POST request to the /rest-auth/registration/verify-email/ with key in body.

What I'm doing is create custom adapter to change the verification domain from Site, thus user is redirected to frontend.

Then get the key from URL and make POST request to the endpoint.

It's working.

Here is the custom adapter

class CustomAccountAdapter(DefaultAccountAdapter):
    def get_email_confirmation_url(self, request, emailconfirmation):
        site = get_current_site(request)
        location = reverse("account_confirm_email", args=[emailconfirmation.key])

        bits = urlsplit(location)
        if not (bits.scheme and bits.netloc):
            uri = '{proto}://{domain}{url}'.format(
                proto=app_settings.DEFAULT_HTTP_PROTOCOL,
                domain=site.domain,
                url=location)
        else:
            uri = location

        return uri

@fessacchiotto
Copy link
Author

fessacchiotto commented Mar 30, 2020

hi! @anuj9196 thanks for your reply.
using postman I registered to the system:
Screenshot 2020-03-30 at 23 39 33
I've received a key (I suppose is the token to authenticate the next api call?)
and then I've received an email:

L'Utente maurizio@example.com di example.com ha registrato questo indirizzo e-mail.
Per confermare, clicca qui http://localhost:8000/dj-rest-auth/registration/account-confirm-email/Mg:1jJ1v6:xodPTPjGXR5VPpAapC6ADDFALcg/

I've tried to make a post request (with the key in the body--which one? the key I've received at registration, the key received in the mail link?--and without key), trough postman this time, not the browser, to the endpoint above found in the mail message, but I don't get anything good...

Screenshot 2020-03-30 at 23 48 24

shouldn't I get some kind of json response to process in my vue.js client? I'm afraid I'm missing something... thanks in advance for your help

@fessacchiotto
Copy link
Author

fessacchiotto commented Mar 31, 2020

I've looked at the source code and read the hint in the url file. I've managed to receive the email link through the vue.js client router (frontend), and from the receiving vue component immediately send an API call to the confirmation endpoint on the backend. thanks for your patience!

@anuj9196
Copy link
Contributor

The key you are getting while registration is the token key to be used for authentication. May be your email verification setting of allauth to set to OPTIONAL

You need to send the key received in the email addresses for verification.

The endpoint you are using to send verification key is not valid.

The link received in the email should be routed to the front-end application and from there get the key from the URL and make a POST request to rest-auth/registration/verify-email

@aijogja
Copy link

aijogja commented Jul 25, 2020

I have fixing this issue by override the account_confirm_email url name as mentioned at https://github.com/jazzband/dj-rest-auth/blob/master/dj_rest_auth/registration/urls.py

so in urls.py

from allauth.account.views import ConfirmEmailView
...
urlpatterns = [
    ...
    path('confirm-email/<str:key>/', ConfirmEmailView.as_view(),
         name='account_confirm_email'),
]

@Abishek05
Copy link

Hi 👋, thanks for creating this issue.

It looks like the issue you're describing was recorded in issue #290 of the upstream project.

Can you see if any of the workarounds in that issue work for you? If not, I'll investigate a fix.

@iMerica Don't you think there should be a separate API endpoint to verify email address instead of using a template configured from allauth as per Tivix#290 you suggested earlier for workarounds? I see there is an API http://127.0.0.1:8000/dj-rest-auth/registration/verify-email/ which returns ok and doesn't change the verification status.

@lapinvert
Copy link

Why is this closed? We still have the same issue in latest version.

@jerinpetergeorge
Copy link
Contributor

I think this issue is related to (or dup of) #180

@PeteAndersen
Copy link

This issue is due to django-allauth's default behavior of calling reverse(), but another solution to this issue is to change this behavior. I think it is a bit simpler this way if you want the URL in the email to point to your frontend app and/or a different domain than Django is being served.

  1. Implement a custom AccountAdapter which overrides the get_email_confirmation_url() method. I just hard-coded it.
from allauth.account.adapter import DefaultAccountAdapter

class AccountAdapter(DefaultAccountAdapter):
    def get_email_confirmation_url(self, request, emailconfirmation):
        return f'https://mywebsite.com/register/verify/{emailconfirmation.key}'
  1. Change the ACCOUNT_ADAPTER allauth setting to point to your custom adapter.

This avoids all of the need for fake URLs and serving HTML views from the API. This also makes it possible to have the email URL be for a different domain than the backend URL, which is not possible with the default allauth behavior.

@HappyNinja2
Copy link

HappyNinja2 commented May 9, 2021

Definitely need to put together an SPA sample for this project, there are many custom modifications needed to make it work with react!
I just had to spend couple of hours for making it work with Google registration before finding this tutorials:
https://medium.com/@pratique/social-login-with-react-and-django-i-c380fe8982e2
https://medium.com/@pratique/social-login-with-react-and-django-ii-39b8aa20cd27

I'll try to create a repo for the fronted.

@tarricsookdeo
Copy link

Definitely need to put together an SPA sample for this project, there are many custom modifications needed to make it work with react! I just had to spend couple of hours for making it work with Google registration before finding this tutorials: https://medium.com/@pratique/social-login-with-react-and-django-i-c380fe8982e2 https://medium.com/@pratique/social-login-with-react-and-django-ii-39b8aa20cd27

I'll try to create a repo for the fronted.

I know it's been a while but thanks for linking these and saving me a lot of time!

@duckheada
Copy link

So ant updates on this? the problem still persists...

@MuhammadAnas47
Copy link

I have fixing this issue by override the account_confirm_email url name as mentioned at https://github.com/jazzband/dj-rest-auth/blob/master/dj_rest_auth/registration/urls.py

so in urls.py

from allauth.account.views import ConfirmEmailView
...
urlpatterns = [
    ...
    path('confirm-email/<str:key>/', ConfirmEmailView.as_view(),
         name='account_confirm_email'),
]

it working for me

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

No branches or pull requests