# Path: yak/rest_user/serializers.py
# class LoginSerializer(serializers.ModelSerializer):
#     client_id = serializers.SerializerMethodField()
#     client_secret = serializers.SerializerMethodField()
# 
#     class Meta:
#         model = User
#         fields = ('client_id', 'client_secret')
# 
#     def get_application(self, obj):
#         # If we're using version 0.8.0 or higher
#         if oauth_toolkit_version[0] >= 0 and oauth_toolkit_version[1] >= 8:
#             return obj.oauth2_provider_application.first()
#         else:
#             return obj.oauth2_provider_application.first()
# 
#     def get_client_id(self, obj):
#         return self.get_application(obj).client_id
# 
#     def get_client_secret(self, obj):
#         return self.get_application(obj).client_secret
# 
# class AuthSerializerMixin(object):
#     def create(self, validated_data):
#         if validated_data.get("username", None):
#             validated_data["username"] = validated_data["username"].lower()
#         if validated_data.get("email", None):
#             validated_data["email"] = validated_data["email"].lower()
#         if validated_data.get("password", None):
#             validated_data["password"] = make_password(validated_data["password"])
# 
#         return super(AuthSerializerMixin, self).create(validated_data)
# 
#     def update(self, instance, validated_data):
#         if validated_data.get("username", None):
#             validated_data["username"] = validated_data["username"].lower()
#         if validated_data.get("email", None):
#             validated_data["email"] = validated_data["email"].lower()
#         if validated_data.get("password", None):
#             validated_data["password"] = make_password(validated_data["password"])
# 
#         return super(AuthSerializerMixin, self).update(instance, validated_data)
# 
#     def validate_username(self, value):
#         username = self.context['request'].user.username if self.context['request'].user.is_authenticated else None
#         if value and value != username and User.objects.filter(username__iexact=value).exists():
#             raise serializers.ValidationError("That username is taken")
#         return value
# 
#     def validate_email(self, value):
#         email = self.context['request'].user.email if self.context['request'].user.is_authenticated else None
#         if value and value != email and User.objects.filter(email__iexact=value).exists():
#             raise serializers.ValidationError("An account already exists with that email")
#         return value
# 
#     def validate_password(self, value):
#         value = base64.decodebytes(bytes(value, 'utf8')).decode()
#         if len(value) < 6:
#             raise serializers.ValidationError("Password must be at least 6 characters")
#         return value


from django.contrib.auth import get_user_model
from rest_framework import serializers
from yak.rest_user.serializers import LoginSerializer, AuthSerializerMixin

User = get_user_model()


class SocialSignUpSerializer(AuthSerializerMixin, LoginSerializer):
    fullname = serializers.CharField(read_only=True)
    username = serializers.CharField(read_only=True)

# Path: yak/rest_user/serializers.py
# class LoginSerializer(serializers.ModelSerializer):
#     client_id = serializers.SerializerMethodField()
#     client_secret = serializers.SerializerMethodField()
# 
#     class Meta:
#         model = User
#         fields = ('client_id', 'client_secret')
# 
#     def get_application(self, obj):
#         # If we're using version 0.8.0 or higher
#         if oauth_toolkit_version[0] >= 0 and oauth_toolkit_version[1] >= 8:
#             return obj.oauth2_provider_application.first()
#         else:
#             return obj.oauth2_provider_application.first()
# 
#     def get_client_id(self, obj):
#         return self.get_application(obj).client_id
# 
#     def get_client_secret(self, obj):
#         return self.get_application(obj).client_secret
# 
# class AuthSerializerMixin(object):
#     def create(self, validated_data):
#         if validated_data.get("username", None):
#             validated_data["username"] = validated_data["username"].lower()
#         if validated_data.get("email", None):
#             validated_data["email"] = validated_data["email"].lower()
#         if validated_data.get("password", None):
#             validated_data["password"] = make_password(validated_data["password"])
# 
#         return super(AuthSerializerMixin, self).create(validated_data)
# 
#     def update(self, instance, validated_data):
#         if validated_data.get("username", None):
#             validated_data["username"] = validated_data["username"].lower()
#         if validated_data.get("email", None):
#             validated_data["email"] = validated_data["email"].lower()
#         if validated_data.get("password", None):
#             validated_data["password"] = make_password(validated_data["password"])
# 
#         return super(AuthSerializerMixin, self).update(instance, validated_data)
# 
#     def validate_username(self, value):
#         username = self.context['request'].user.username if self.context['request'].user.is_authenticated else None
#         if value and value != username and User.objects.filter(username__iexact=value).exists():
#             raise serializers.ValidationError("That username is taken")
#         return value
# 
#     def validate_email(self, value):
#         email = self.context['request'].user.email if self.context['request'].user.is_authenticated else None
#         if value and value != email and User.objects.filter(email__iexact=value).exists():
#             raise serializers.ValidationError("An account already exists with that email")
#         return value
# 
#     def validate_password(self, value):
#         value = base64.decodebytes(bytes(value, 'utf8')).decode()
#         if len(value) < 6:
#             raise serializers.ValidationError("Password must be at least 6 characters")
#         return value


# Path: yak/rest_social_auth/serializers.py
from django.contrib.auth import get_user_model
from rest_framework import serializers
from yak.rest_user.serializers import LoginSerializer, AuthSerializerMixin


User = get_user_model()


class SocialSignUpSerializer(AuthSerializerMixin, LoginSerializer):
    fullname = serializers.CharField(read_only=True)
    username = serializers.CharField(read_only=True)

    email = serializers.EmailField(read_only=True)