pinax / django-user-accounts

User accounts for Django
MIT License
1.22k stars 356 forks source link

Sign up doesn't work out of the box #294

Open diegovargasf opened 6 years ago

diegovargasf commented 6 years ago

Hello, I followed the instructions here:http://pinaxproject.com/pinax/quick_start/ mainly: pip install virtualenv virtualenv mysiteenv source mysiteenv/bin/activate pip install pinax-cli pinax start account mysite

cd mysite npm install pip install -r requirements.txt ./manage.py migrate ./manage.py loaddata sites npm run dev

And when I tried to sign up a new user, after sending the form, I received this error: Exception Type: AttributeError at /account/signup/ Exception Value: 'AnonymousUser' object has no attribute '_meta'

---------------------------------STACKTRACE COPY------------------------------------- Environment: Request Method: POST Request URL: //localhost:3000/account/signup/

Django Version: 2.1.1 Python Version: 3.6.2 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.messages', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.staticfiles', 'bootstrapform', 'pinax.templates', 'account', 'pinax.eventlog', 'pinax.webanalytics', 'mysite'] Installed Middleware: ['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']

Traceback:

File "/Users/diegovargas/myproject/mysiteenv/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner

  1. response = get_response(request)

File "/Users/diegovargas/myproject/mysiteenv/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response

  1. response = self.process_exception_by_middleware(e, request)

File "/Users/diegovargas/myproject/mysiteenv/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response

  1. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/Users/diegovargas/myproject/mysiteenv/lib/python3.6/site-packages/django/views/generic/base.py" in view

  1. return self.dispatch(request, *args, **kwargs)

File "/Users/diegovargas/myproject/mysiteenv/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapper

  1. return bound_method(*args, **kwargs)

File "/Users/diegovargas/myproject/mysiteenv/lib/python3.6/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper

  1. return view(request, *args, **kwargs)

File "/Users/diegovargas/myproject/mysiteenv/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapper

  1. return bound_method(*args, **kwargs)

File "/Users/diegovargas/myproject/mysiteenv/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view

  1. response = view_func(request, *args, **kwargs)

File "/Users/diegovargas/myproject/mysiteenv/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapper

  1. return bound_method(*args, **kwargs)

File "/Users/diegovargas/myproject/mysiteenv/lib/python3.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func

  1. response = view_func(request, *args, **kwargs)

File "/Users/diegovargas/myproject/mysiteenv/lib/python3.6/site-packages/account/views.py" in dispatch

  1. return super(SignupView, self).dispatch(request, *args, **kwargs)

File "/Users/diegovargas/myproject/mysiteenv/lib/python3.6/site-packages/django/views/generic/base.py" in dispatch

  1. return handler(request, *args, **kwargs)

File "/Users/diegovargas/myproject/mysiteenv/lib/python3.6/site-packages/account/views.py" in post

  1. return super(SignupView, self).post(*args, **kwargs)

File "/Users/diegovargas/myproject/mysiteenv/lib/python3.6/site-packages/django/views/generic/edit.py" in post

  1. return self.form_valid(form)

File "/Users/diegovargas/myproject/mysiteenv/lib/python3.6/site-packages/account/views.py" in form_valid

  1. self.login_user()

File "/Users/diegovargas/myproject/mysiteenv/lib/python3.6/site-packages/account/views.py" in login_user

  1. auth.login(self.request, user)

File "/Users/diegovargas/myproject/mysiteenv/lib/python3.6/site-packages/django/contrib/auth/init.py" in login

  1. request.session[SESSION_KEY] = user._meta.pk.value_to_string(user)

File "/Users/diegovargas/myproject/mysiteenv/lib/python3.6/site-packages/django/utils/functional.py" in inner

  1. return func(self._wrapped, *args)

Exception Type: AttributeError at /account/signup/ Exception Value: 'AnonymousUser' object has no attribute '_meta' ---------------------------------STACKTRACE COPY END-------------------------------------

Am I missing something?

diegovargasf commented 6 years ago

Disregard, I just had to add: "django.contrib.auth.backends.ModelBackend" to my authentication backends

nstephenh commented 6 years ago

I'm fairly sure this should still be open, as its a bug that does need to be fixed with the template.

jacobwegner commented 3 years ago

I hit this as well on a project; I'm wondering if https://django-user-accounts.readthedocs.io/en/latest/usage.html#using-email-address-for-authentication needs to be updated to ensure that we are adding additional backends to AUTHENTICATION_BACKENDS, rather than overwriting the default setting (which has django.contrib.auth.backends.ModelBackend)