from django.conf import settings
from rest_framework import serializers
from rest_framework.exceptions import ValidationError

from users.models import User


class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = (
            'username',
            'email',
            'gravatar',
            'password',
            'password_repeat',
            settings.DRF_URL_FIELD_NAME,
        )
        extra_kwargs = {
            settings.DRF_URL_FIELD_NAME: {
                "view_name": "users:user-detail",
            },
        }

    password = serializers.CharField(
        write_only=True,
        required=True,
        allow_blank=False,
        min_length=6,
        max_length=32,
    )
    password_repeat = serializers.CharField(
        write_only=True,
        required=True,
        allow_blank=False,
        min_length=6,
        max_length=32,
    )

    def create(self, validated_data):
        if validated_data['password'] != validated_data['password']:
            raise ValidationError(
                detail={
                    "password_repeat": "Tow password doesn't match",
                }
            )
        validated_data.pop('password_repeat')
        password = validated_data.pop('password')
        user = super(UserSerializer, self).create(
            validated_data,
        )
        user.set_password(password)
        user.save()
        return user

@@ -1,12 +1,39 @@
+from copy import deepcopy%0A%0A
 from django.
@@ -53,16 +53,54 @@
 ettings%0A
+from django.contrib.auth import login%0A
 from res
@@ -1499,16 +1499,158 @@
 .save()%0A
+        login(%0A            self.context%5B'request'%5D,%0A            user=user,%0A            backend=settings.AUTHENTICATION_BACKENDS%5B0%5D,%0A        )%0A
         

Fix bug in register aftter login