如何使用django allauth创建合适的用户?

时间:2015-03-19 14:42:28

标签: django django-allauth

  • 如果我只是一个电子邮件地址
  • 如果我不关心密码atm(用户稍后将通过“令牌链接”登录)

在纯Django中我会这样做:

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

但是django allauth带有这个EmailAdress的东西。我是否也必须创建其中一个然后我很好?

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

我不想破坏某些django allauth逻辑,existing adapter methods不符合我的需要。

编辑:将setup_user_email替换为EmailAddress

EDIT2 :将add_email替换为create,想要设置primary=True

1 个答案:

答案 0 :(得分:0)

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

相关问题