18
  • If I've an emailadress only
  • If I don't care about a password atm (user will login through a "token link" later)

In pure Django I would just do it like:

from django.contrib.auth.models import User
user = User.objects.create_user(username=email, email=email)

But django allauth comes with this EmailAdress stuff. Do I just have to create one of these too and then I'm fine?

from allauth.account.models import EmailAddress
EmailAddress.objects.create(user=user, email=email, primary=True, verified=False)

I don't want to break some django allauth logic and the existing adapter methods doesn't suit my needs.

EDIT: replaced setup_user_email with EmailAddress

EDIT2: replaced add_email with create, want to set primary=True

sspross
  • 1,439
  • 1
  • 13
  • 22

1 Answers1

3

The canonical way to create a user seems to be stuck in the SignupForm.save() method:

https://github.com/pennersr/django-allauth/blob/6b2167ca245558317be1f8881f162f4d5312eb95/allauth/account/forms.py#L401-L408

Edit: It's actually one level higher in the SignupView, which first calls the SignupForm.save() and then calls account.utils.complete_signup(), which sends the user_signed_up signal:

https://github.com/pennersr/django-allauth/blob/6b2167ca245558317be1f8881f162f4d5312eb95/allauth/account/views.py#L227-L237

https://github.com/pennersr/django-allauth/blob/6b2167ca245558317be1f8881f162f4d5312eb95/allauth/account/utils.py#L171-L183

HostedMetrics.com
  • 3,525
  • 3
  • 26
  • 31
  • 1
    `complete_signup` is fine, but to add `EmailAddress` to your account, but you have to call `setup_user_email(request,user,[])`. – mka Jan 09 '22 at 19:06