Пример #1
0
    def post(self, request):
        unserializer = UserSerializer(data=request.data)
        unserializer.is_valid(raise_exception=True)

        user = unserializer.save()
        password = User.objects.make_random_password()
        user.set_password(password)
        user.groups.add(get_default_permission_group())
        user.save()

        mail = singup_mail.copy()
        mail["recipient_list"] = [user.email]
        full_name = "%s %s" % (user.first_name, user.last_name)
        mail["message"] = mail["message"].format(email=user.email, password=password, name=full_name)
        send_mail(**mail)

        serializer = UserSerializer(user)
        return Response(serializer.data, 201)
Пример #2
0
def user_created(sender, instance, created, **kwargs):
    if created:
        instance.groups.add(get_default_permission_group())
        instance.save()
        Profile.objects.create(user=instance)