SHARE
TWEET

Untitled

a guest Jun 18th, 2019 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class UserLoginSerializer(serializers.ModelSerializer):
  2. class Meta:
  3.     model = Account
  4.     fields = ('id', 'username','title','email')
  5.      
  6. class Login(APIView):
  7. permission_classes = (AllowAny,)
  8.   def post(self,request):
  9.     email = request.data.get('email',None)
  10.     password = request.data.get('password',None)
  11.     if email and password:
  12.         user_obj = Account.objects.filter(email__iexact=email)
  13.         if user.exists() and user.first().check_password(password):
  14.             user = UserLoginSerializer(user_obj)
  15.             data_list = {}
  16.             data_list.update(user.data)
  17.             return Response({"message": "Login Successfully", "data":data_list, "code": 200})
  18.         else:
  19.             message = "Unable to login with given credentials"
  20.             return Response({"message": message , "code": 500, 'data': {}} )
  21.     else:
  22.         message = "Invalid login details."
  23.         return Response({"message": message , "code": 500, 'data': {}})
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top