text: # Third Party Stuff
  from django.contrib.auth import password_validation
  from rest_framework import serializers
  
  # {{ cookiecutter.project_name }} Stuff
  from {{cookiecutter.main_module}}.users import services as user_services
  from {{cookiecutter.main_module}}.users.models import UserManager
  from {{cookiecutter.main_module}}.users.serializers import UserSerializer
  
  from . import tokens
  
  
  class EmptySerializer(serializers.Serializer):
      pass
  
  
  class LoginSerializer(serializers.Serializer):
      email = serializers.CharField(max_length=300, required=True)
      password = serializers.CharField(required=True)
  
  
  class RegisterSerializer(serializers.Serializer):
      email = serializers.EmailField(required=True)
      password = serializers.CharField(required=True)
  
      def validate_email(self, value):
          user = user_services.get_user_by_email(email=value)
          if user:
              raise serializers.ValidationError("Email is already taken.")
          return UserManager.normalize_email(value)
  
  
  class AuthUserSerializer(UserSerializer):
      auth_token = serializers.SerializerMethodField()
  
      class Meta(UserSerializer.Meta):
          fields = UserSerializer.Meta.fields + ["auth_token"]
  
      def get_auth_token(self, obj):
          return tokens.get_token_for_user(obj, "authentication")
  
  
  class PasswordChangeSerializer(serializers.Serializer):
      current_password = serializers.CharField(required=True)
      new_password = serializers.CharField(required=True)
  
      default_error_messages = {"invalid_password": "Current password does not match"}
  
      def validate_current_password(self, value):
          if not self.context["request"].user.check_password(value):
              raise serializers.ValidationError(
                  self.default_error_messages["invalid_password"]
              )
          return value
  
      def validate_new_password(self, value):
          # https://docs.djangoproject.com/en/2.0/topics/auth/passwords/#django.contrib.auth.password_validation.validate_password
          password_validation.validate_password(value)
          return value
  
  
  class PasswordResetSerializer(serializers.Serializer):
      email = serializers.EmailField(required=True)
  
  
  class PasswordResetConfirmSerializer(serializers.Serializer):
      new_password = serializers.CharField(required=True)
      token = serializers.CharField(required=True)
  
      def validate_new_password(self, value):
          password_validation.validate_password(value)
          return value
  