我想介绍一个流程,我们已经在使用allauth并希望尝试使用allauth(可能添加另一个包):
答案 0 :(得分:0)
django-invitations是一个通用的邀请解决方案,曾经是django-allauth的一个插件,但现在却是独立的。
account_signup
的网址是用户指向您需要实施的网址第3步,您需要自己实施
答案 1 :(得分:0)
这是旧文章,但我认为它将在将来对其他人有所帮助。
我一直在努力,找不到稳定的库或实际上在做我要寻找的库。但是,我研究了rest_auth
中的RegisterSerializer的代码,然后创建了自己的代码来覆盖RegisterSerializer中的特定方法。
这是我的最终代码:
class UserInviteSerializer(RegisterSerializer):
# first_name and last_name were required for my case but they are not necessary.
first_name = serializers.CharField(required=True)
last_name = serializers.CharField(required=True)
email = serializers.EmailField(required=True)
# override password1 and password2 to not be required.
password1 = serializers.CharField(write_only=True, required=False)
password2 = serializers.CharField(write_only=True, required=False)
# override validate so that you don't get the error that
# password1 and password2 are required.
def validate(self, data):
return data
def get_cleaned_data(self):
super(UserInviteSerializer, self).get_cleaned_data()
return {
'first_name': self.validated_data.get('first_name', ''),
'last_name': self.validated_data.get('last_name', ''),
'email': self.validated_data.get('email', ''),
}
# create your own create method.
def create(self, validated_data):
user = models.User(**validated_data)
# this is really important because password is required
# by the User model. So you need to use the django method
# `set_unusable_password`
user.set_unusable_password()
# username was not being generated by AllAuth so I had to set it.
user.username = user.email
user.save()
return user
现在,您可以创建其他视图来让用户设置密码,并且可以使用django用户方法has_usable_password()