apragacz / django-rest-registration

User-related REST API based on the awesome Django REST Framework
https://django-rest-registration.readthedocs.io/
MIT License
544 stars 84 forks source link

'VerifyRegistrationView' should either include a `serializer_class` attribute, or override the `get_serializer_class()` method #225

Closed doukasd closed 1 year ago

doukasd commented 1 year ago

Checklist

Optional checklist

Describe the bug

On the latest stable version of Django, DRF and this package, registration verification does not work. When I try to access the verify-registration endpoint, I get this error:

'VerifyRegistrationView' should either include a `serializer_class` attribute, or override the `get_serializer_class()` method

Expected behavior

Instead I would expect that API view not to throw an error.

Actual behavior

Error is thrown and endpoint is broken, meaning the whole registration flow is blocked.

Steps to reproduce

Steps to reproduce the behavior:

  1. install latest stable versions of django, djangorestframework and django-rest-registration on python 3.9
  2. add these apps to the settings and enable the verification flow
  3. go to the /api/v1/accounts/verify-registration/ endpoint and observe than an error is shown

Diagnostic info

My settings.py:

"""
Django settings for mysite project.

Generated by 'django-admin startproject' using Django 4.2.1.

For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""

from pathlib import Path

# 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.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-autogenerated^-whatever'

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

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_registration',
]

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 = 'mysite.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',
            ],
        },
    },
]

WSGI_APPLICATION = 'mysite.wsgi.application'

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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

# Password validation
# https://docs.djangoproject.com/en/4.2/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.2/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.2/howto/static-files/

STATIC_URL = 'static/'

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

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

REST_REGISTRATION = {
    'REGISTER_VERIFICATION_URL': 'https://frontend-host/verify-user/',
    'RESET_PASSWORD_VERIFICATION_URL': 'https://frontend-host/reset-password/',
    'REGISTER_EMAIL_VERIFICATION_URL': 'https://frontend-host/verify-email/',

    'VERIFICATION_FROM_EMAIL': 'no-reply@your-domain.com',
}

EMAIL_BACKEND = 'django_ses.SESBackend'
AWS_ACCESS_KEY_ID="add you details here for quick testing"
AWS_SECRET_ACCESS_KEY="add you details here for quick testing"
AWS_SES_REGION_NAME = 'eu-west-2'

Additional context

Using these versions of the frameworks (currently the stable defaults)

Django==4.2.1
django-rest-registration==0.8.0
djangorestframework==3.14.0

Full pip freeze dump of the new project I made to verify this:

pip freeze                                                            
asgiref==3.6.0
boto3==1.26.126
botocore==1.29.126
Django==4.2.1
django-rest-registration==0.8.0
django-ses==3.4.1
djangorestframework==3.14.0
jmespath==1.0.1
python-dateutil==2.8.2
pytz==2023.3
s3transfer==0.6.0
six==1.16.0
sqlparse==0.4.4
urllib3==1.26.15
doukasd commented 1 year ago

Hmm, I just did the following:

And now the endpoint works. So maybe this is not a code issue but a release issue with version django-rest-registration==0.8.0

apragacz commented 1 year ago

Hi @doukasd, thanks for raising the issue.

It is possible that your issue was already fixed via #215 / #216 .

I'm gonna release new version soon (0.8.1) which will contain the fix.

apragacz commented 1 year ago

@doukasd I've just released new version v0.8.1. Could you double-check if the same problem persist with the latest version?

doukasd commented 1 year ago

Yes @apragacz it seems that verify-registration works now on 0.8.1. I tested locally.

I will deploy to our dev environment so it will be tested by everyone. So if I don't report back in a few days that it is broken, you can assume it's fixed.

(I will close this ticket and re-open it if any issues come up).