Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
xtnctx authored Nov 9, 2022
1 parent 7c85cdc commit 7caf966
Showing 1 changed file with 41 additions and 15 deletions.
56 changes: 41 additions & 15 deletions bfrbsysAPI/apis/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .models import Item, TrainedModel
from django.contrib.auth.models import User
from rest_framework.validators import UniqueTogetherValidator
from django.contrib.auth import authenticate

class ItemSerializer(serializers.ModelSerializer):
class Meta:
Expand All @@ -15,23 +16,48 @@ class Meta:



# class UserSerializer(serializers.ModelSerializer):
# def create(self, validated_data):
# user = User.objects.create_user(**validated_data)
# return user

# class Meta:
# model = User
# fields = (
# 'username',
# 'first_name',
# 'last_name',
# 'email',
# 'password',
# )
# validators = [
# UniqueTogetherValidator(
# queryset=User.objects.all(),
# fields=['username', 'password']
# )
# ]

class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('id', 'username', 'email',)

class RegisterSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('id', 'username', 'password', 'email',)
extra_kwargs = {'password': {'write_only': True}}

def create(self, validated_data):
user = User.objects.create_user(**validated_data)
return user

class Meta:
model = User
fields = (
'username',
'first_name',
'last_name',
'email',
'password',
)
validators = [
UniqueTogetherValidator(
queryset=User.objects.all(),
fields=['username', 'email']
)
]
class LoginSerializer(serializers.Serializer):
username = serializers.CharField()
password = serializers.CharField()

def validate(self, data):
user = authenticate(**data)
if user and user.is_active:
return user
raise serializers.ValidationError("Incorrect Credentials")

0 comments on commit 7caf966

Please sign in to comment.