add login api
This commit is contained in:
17
core/apps/accounts/serializers/login.py
Normal file
17
core/apps/accounts/serializers/login.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from core.apps.accounts.models.user import User
|
||||
|
||||
|
||||
class LoginSerializer(serializers.Serializer):
|
||||
username = serializers.CharField()
|
||||
password = serializers.CharField()
|
||||
|
||||
def validate(self, data):
|
||||
user = User.objects.filter(username=data['username']).first()
|
||||
if not user:
|
||||
raise serializers.ValidationError("User not found with this credentials")
|
||||
if not user.check_password(data['password']):
|
||||
raise serializers.ValidationError("User not found with this credentials")
|
||||
data['user'] = user
|
||||
return data
|
||||
Reference in New Issue
Block a user