# Path: yak/rest_core/serializers.py
# class YAKModelSerializer(serializers.ModelSerializer):
# 
#     def __init__(self, *args, **kwargs):
#         super(YAKModelSerializer, self).__init__(*args, **kwargs)
#         self.fields['content_type'] = serializers.SerializerMethodField()
# 
#     def get_content_type(self, obj):
#         return ContentType.objects.get_for_model(obj).pk
# 
# Path: yak/rest_core/utils.py
# def get_package_version(package):
#     """
#     Return the version number of a Python package as a list of integers
#     e.g., 1.7.2 will return [1, 7, 2]
#     """
#     return [int(num) for num in package.__version__.split('.')]
# 
# Path: yak/settings.py
# def perform_import(val, setting_name):
#     def __getattr__(self, attr):
# class YAKAPISettings(APISettings):
# USER_SETTINGS = getattr(settings, 'YAK', None)
# DEFAULTS = {
#     'USER_APP_LABEL': 'test_app',
#     'USER_MODEL': 'user',
#     'USER_SERIALIZER': "test_app.api.serializers.UserSerializer",
#     'API_SCHEMA': 'api-schema-1.0.json',
#     'SOCIAL_MODEL': "test_app.models.Post",
#     'ALLOW_EMAIL': True,
#     'ALLOW_PUSH': True,
#     'EMAIL_NOTIFICATION_SUBJECT': 'Test Project Notification',
#     'PUSHWOOSH_AUTH_TOKEN': "",
#     'PUSHWOOSH_APP_CODE': "",
#     'PUSH_NOTIFICATION_HANDLER': "yak.rest_notifications.utils.send_pushwoosh_notification",
#     'SOCIAL_SHARE_DELAY': 60,
#     'USE_FACEBOOK_OG': False,
#     'FACEBOOK_OG_NAMESPACE': "",
#     'SERIALIZER_MAPPING': {},
#     'FLAKE8_CONFIG': None,
# }
# IMPORT_STRINGS = (
#     "USER_SERIALIZER",
#     "SOCIAL_MODEL",
#     "SERIALIZER_MAPPING",
# )


import base64
import oauth2_provider
from django.contrib.auth import get_user_model
from django.contrib.auth.hashers import make_password
from django.core.validators import RegexValidator
from rest_framework import serializers
from rest_framework.validators import UniqueValidator
from yak.rest_core.serializers import YAKModelSerializer
from yak.rest_core.utils import get_package_version
from yak.settings import yak_settings
    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


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 SignUpSerializer(AuthSerializerMixin, LoginSerializer):

# Path: yak/rest_core/serializers.py
# class YAKModelSerializer(serializers.ModelSerializer):
# 
#     def __init__(self, *args, **kwargs):
#         super(YAKModelSerializer, self).__init__(*args, **kwargs)
#         self.fields['content_type'] = serializers.SerializerMethodField()
# 
#     def get_content_type(self, obj):
#         return ContentType.objects.get_for_model(obj).pk
# 
# Path: yak/rest_core/utils.py
# def get_package_version(package):
#     """
#     Return the version number of a Python package as a list of integers
#     e.g., 1.7.2 will return [1, 7, 2]
#     """
#     return [int(num) for num in package.__version__.split('.')]
# 
# Path: yak/settings.py
# def perform_import(val, setting_name):
#     def __getattr__(self, attr):
# class YAKAPISettings(APISettings):
# USER_SETTINGS = getattr(settings, 'YAK', None)
# DEFAULTS = {
#     'USER_APP_LABEL': 'test_app',
#     'USER_MODEL': 'user',
#     'USER_SERIALIZER': "test_app.api.serializers.UserSerializer",
#     'API_SCHEMA': 'api-schema-1.0.json',
#     'SOCIAL_MODEL': "test_app.models.Post",
#     'ALLOW_EMAIL': True,
#     'ALLOW_PUSH': True,
#     'EMAIL_NOTIFICATION_SUBJECT': 'Test Project Notification',
#     'PUSHWOOSH_AUTH_TOKEN': "",
#     'PUSHWOOSH_APP_CODE': "",
#     'PUSH_NOTIFICATION_HANDLER': "yak.rest_notifications.utils.send_pushwoosh_notification",
#     'SOCIAL_SHARE_DELAY': 60,
#     'USE_FACEBOOK_OG': False,
#     'FACEBOOK_OG_NAMESPACE': "",
#     'SERIALIZER_MAPPING': {},
#     'FLAKE8_CONFIG': None,
# }
# IMPORT_STRINGS = (
#     "USER_SERIALIZER",
#     "SOCIAL_MODEL",
#     "SERIALIZER_MAPPING",
# )


# Path: yak/rest_user/serializers.py
import base64
import oauth2_provider
from django.contrib.auth import get_user_model
from django.contrib.auth.hashers import make_password
from django.core.validators import RegexValidator
from rest_framework import serializers
from rest_framework.validators import UniqueValidator
from yak.rest_core.serializers import YAKModelSerializer
from yak.rest_core.utils import get_package_version
from yak.settings import yak_settings

    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


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 SignUpSerializer(AuthSerializerMixin, LoginSerializer):

    password = serializers.CharField(max_length=128, write_only=True, error_messages={'required': 'Password required'})