0

I am creating a rest API and using Django-rest-auth, and want to verify users' email. Everything works until I click the link to verify the user's email. earlier I got an error, but I eventually got it fixed, the problem was that the fix made it no longer restful.

I later found out in the documentation an idea to why I was getting this problem https://django-rest-auth.readthedocs.io/en/latest/faq.html after searching online I found some fixes that worked to some degree, BUT the email still did not verify after clicking the link, although I wasn't getting errors like before.

my settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.sites',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_framework.authtoken',
    'rest_auth',
    'rest_auth.registration',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.google',
    'allauth.socialaccount.providers.facebook',
    'users',
]


ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_LOGOUT_ON_GET = True

ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 1
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_LOGIN_ATTEMPTS_LIMIT = 5
ACCOUNT_LOGIN_ATTEMPTS_TIMEOUT = 86400 # 1 day in seconds
ACCOUNT_LOGOUT_REDIRECT_URL ='/accounts/login/'
LOGIN_REDIRECT_URL = '/accounts/profile'
SOCIALACCOUNT_EMAIL_VERIFICATION = 'none'

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'test'
DEFAULT_FROM_EMAIL = '[email protected]'
DEFAULT_TO_EMAIL = EMAIL_HOST_USER

EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL = '/'

my urls.py

from django.contrib import admin
from django.urls import path, re_path
from django.conf.urls import url, include
from rest_auth.registration.views import VerifyEmailView, RegisterView

from users.api.views import null_view


urlpatterns = [
    path('admin/', admin.site.urls),
    url(r'^api/rest-auth/registration/account-email-verification-sent/', null_view, name='account_email_verification_sent'),
    url(r'^api/rest-auth/registration/account-confirm-email/', null_view, name='account_confirm_email'),
    url(r'^password-reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', null_view, name='password_reset_confirm'),


    url('api/rest-auth/', include('rest_auth.urls')),
    url('api/account/', include('users.api.urls')),
    url('api/rest-auth/registration/', include('rest_auth.registration.urls')),
]

imported view

@api_view()
def null_view(request):
    return Response(status=status.HTTP_400_BAD_REQUEST)

I am getting the mail, and on click also getting the null_view response, but the email still isn't getting verified.

1 Answer 1

3

Shouldn't you pass the request to email verification view?

url(r'^api/rest-auth/registration/account-confirm-email/', VerifyEmailView.as_view(), name='account_confirm_email'),
Sign up to request clarification or add additional context in comments.

2 Comments

KeyError at /api/rest-auth/registration/account-confirm-email/
after adding the dollar sign which i think is missing i get ``` ImproperlyConfigured at /api/rest-auth/registration/account-confirm-email/NDI:1iQhdl:JW_CIVLlpSj62k5YMMuIWTlcBLk/ TemplateResponseMixin requires either a definition of 'template_name' or an implementation of 'get_template_names()' ```

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.