iMerica / dj-rest-auth

Authentication for Django Rest Framework
https://dj-rest-auth.readthedocs.io/en/latest/index.html
MIT License
1.67k stars 312 forks source link

Page not found while clicking on confirmation link #380

Closed roberthobblebottom closed 2 years ago

roberthobblebottom commented 2 years ago

This is a clone of my stackoverflow question. Hope someone out there could help me in this.

Via Postman I send POST http://127.0.0.1:8000/dj-rest-auth/password/reset/ with json: { "email" : "pyroclastic@protonmail.com" }

I received the email with the confirmation link:http://localhost:8000/dj-rest-auth/password/reset/confirm/3/b18epl-d065751bdebfd3abacd0ddd62c419877

However upon clicking on this link it shows

Page not found (404)

As you can see through my url.py, I tried other ways (including ones in the faq and the api endpoints and config pages and went through the source codes)

url.py

from django.contrib import admin
from dj_rest_auth.registration.views import VerifyEmailView
from django.urls import path
from django.urls import include, re_path
from django.conf.urls.static import static
from django.conf import settings
from dj_rest_auth.views import PasswordResetConfirmView, PasswordResetView
from allauth.account.views import ConfirmEmailView
from django.views.generic import TemplateView
from .router import router
from BackendApp.views import P2PListingModule, empty_view, GoogleLogin, FacebookLogin
urlpatterns = [ 
    path('admin/', admin.site.urls),
    path('dj-rest-auth/', include('dj_rest_auth.urls')),
    path('dj-rest-auth/registration/', include('dj_rest_auth.registration.urls')),
    path('entity/', include(router.urls)),
    path('enduser/<str:pk>/service/', P2PListingModule.userServiceListing),
    path('enduser/<str:pk>/request/', P2PListingModule.userRequestListing),
    path('enduser/<str:pk>/swap/', P2PListingModule.userSwapListing),
    path('enduser/<str:pk>/premade', P2PListingModule.userPremadeListing),
    path('entity/p2p_listing/order/', P2PListingModule.placeOrder),
    path('api/p2plisting/service', P2PListingModule.ServiceListingView.as_view()),
    path('api/p2plisting/request', P2PListingModule.RequestListingView.as_view()),
    path('api/p2plisting/swap', P2PListingModule.SwapListingView.as_view()),
    path('api/p2plisting/premade', P2PListingModule.PremadeListingView.as_view()),
    re_path(r'^', include('django.contrib.auth.urls')),
    path('dj-rest-auth/password/reset/', 
        PasswordResetView.as_view(), 
        name="rest_password_reset"),
    path(

        "dj-rest-auth/password/reset/confirm/",
        PasswordResetConfirmView.as_view(),
        name="rest_password_reset_confirm",
    ),  
    path(
   # path('/dj-rest-auth/password/reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,32})/$',
   "/dj-rest-auth/password/reset/confirm/<uuid:uidb64>/<slug:token>/",
        # PasswordResetConfirmView.as_view(),
        # ConfirmEmailView.as_view(),
        TemplateView.as_view(template_name="password_reset_confirm.html"),
        ),  
    path('auth/google/', GoogleLogin.GoogleLoginView.as_view(), name='google_login'),
    path('auth/facebook/', FacebookLogin.FacebookLoginView.as_view(), name='fb_login'),
    re_path(r'^accounts/', include('allauth.urls'), name='socialaccount_signup'),
    # path('dj-rest-auth/account-confirm-email/', ConfirmEmailView.as_view(), name='account_email_verification_sent'),
    # re_path(r'^password-reset/$',
    #     TemplateView.as_view(template_name="password_reset.html"),
    #     name='password-reset'),
    # re_path(r'^password-reset/confirm/$',
    #     TemplateView.as_view(template_name="password_reset_confirm.html"),
    #     name='password-reset-confirm'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
# urlpatterns = [
#     url(r'^admin/', include(admin.site.urls)),
# ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

settings.py

...
# from Backend.custom_dj_rest_auth_serializers import LoginSerializer, UserDetailsSerializer, RegisterSerializer
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-vs)652$=8ke3goozo9jar#t$ictvc-i_xy&noj@yd6+w5vod%v'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*']

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.IsAuthenticated',
    ],
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.TokenAuthentication',
    ]
}

# Application definition

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

SITE_ID = 1

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'Backend.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]
REST_AUTH_SERIALIZERS = {
    'LOGIN_SERIALIZER': 'BackendApp.auth_serializers.LoginSerializer',
    'TOKEN_SERIALIZER': 'dj_rest_auth.serializers.TokenSerializer',
    "PASSWORD_RESET_SERIALIZER": "BackendApp.auth_serializers.PasswordResetSerializer",
}
REST_AUTH_REGISTER_SERIALIZERS = {
    'REGISTER_SERIALIZER': 'BackendApp.auth_serializers.RegisterSerializer',
}
# Provider specific settings
SOCIALACCOUNT_PROVIDERS = {
    'google': {
        # For each OAuth based provider, either add a ``SocialApp``
        # (``socialaccount`` app) containing the required client
        # credentials, or list them here:
        'APP': {
            'client_id': '986666561005-49aa5ralo3ro80dh1tfnh6gjgcpuulvp.apps.googleusercontent.com',
            'secret': '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',
            'key': 'AIzaSyCSZFYhEM4ZGUUagVsfBB_mwdHjp8t1vWw'
        }
    },

    'facebook': {
        'APP':{
            'client_id': "1006083210330915",
            'secret': "de3a2eb8a8067b5b66f24ec1c8da90c3",
        },
        'METHOD': 'oauth2',
        'SDK_URL': '//connect.facebook.net/{locale}/sdk.js',
        'SCOPE': ['email', 'public_profile'],
        'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
        'INIT_PARAMS': {'cookie': True},
        'FIELDS': [
            'id',
            'first_name',
            'last_name',
            'middle_name',
            'name',
            'name_format',
            'picture',
            'short_name'
        ],
        'EXCHANGE_TOKEN': True,
        'LOCALE_FUNC': 'path.to.callable',
        'VERIFIED_EMAIL': False,
        'VERSION': 'v7.0',
    }
}
WSGI_APPLICATION = 'Backend.wsgi.application'

# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases

DATABASES = {
    # 'default': {
    #     'ENGINE': 'django.db.backends.postgresql',
    #     'NAME': 'd44c8on3oloent',
    #     'USER': 'jeskpxbodxwhyn',
    #     'PASSWORD': '28849aeb692b38fc627ef384545b5a44574b95646dbb593199f7c94af352173a',
    #     'HOST': 'ec2-34-193-235-32.compute-1.amazonaws.com',
    #     'PORT': '5432',
    #     'TEST':{
    #     }
    # },
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'postgres',
        'USER': 'postgres',
        'PASSWORD': 'password',
        'HOST': 'localhost',
        'PORT': '5432',
        'TEST': {
            'DEPENDENCIES': []
        }
    }

}

# Password validation
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

# OLD: API-based sendgrid
# ANYMAIL = {
#     "SENDGRID_API_KEY": "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",
#     "SENDGRID_API_URL": "https://api.sendgrid.com/v3",
# }
# EMAIL_BACKEND = "anymail.backends.sendgrid.EmailBackend"

# NEW: SMTP
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
SENDGRID_API_KEY = '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'
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'apikey'
EMAIL_HOST_PASSWORD = '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'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'is4103.altnative@gmail.com'

# Following is added to enable registration with email instead of username
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
AUTHENTICATION_BACKENDS = (
    "django.contrib.auth.backends.ModelBackend",
    "allauth.account.auth_backends.AuthenticationBackend",
)

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_true': {
            '()': 'django.utils.log.RequireDebugTrue',
        },
    },
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
            'filters': ['require_debug_true'],
        },
    },
    'loggers': {
        'mylogger': {
            'handlers': ['console'],
            'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
            'propagate': True,
        },
    },
}                                                                                                                                   
roberthobblebottom commented 2 years ago

Circumstances has changed but I do not know why. But still this problems isn't what I am facing right now