我有一个简单的类,用随机密码创建用户并使用电子邮件作为用户名,它可以工作。但是我注册了重复的用户。
if request.user.is_anonymous():
signup_form.save(request)
email = signup_form.cleaned_data.get('email')
pwd = get_random_string(length=16)
user = User.objects.create_user(email, email, pwd )
customer, created = Customer.objects.get_or_create(user=user)
customer.mobile = request.POST.get('mobile', '')
customer.save()
user = authenticate(username=user.username, password=pwd)
login(request, user)
user.first_name = extend_form.cleaned_data.get('name')
user.last_name = extend_form.cleaned_data.get('surname')
user.save()
示例,user@email.com
我注册了两个用户帐户:
exampleuser@email.com
注册了正确的客户对象关系,first_name
/ last_name
已填写exampleuser
电子邮件exampleuser@email.com
,但没有任何客户关系,空first_name/last_name