Esempio n. 1
0
 def post(self):
     try:
         body = request.get_json()
         user = User.objects.get(email=body.get('email'))
         if not (user is None):
             print("Value is not none user is already registered : " +
                   str(user))
             expires = datetime.timedelta(days=365)
             access_token = create_access_token(identity=str(user.id),
                                                expires_delta=expires)
             user.access_token = access_token
             if user.visiting_card_exist:
                 user.visiting_card_id = user.visiting_card.id
             return Response(user.to_json(),
                             mimetype="application/json",
                             status=200)
     except User.DoesNotExist as e:
         print(
             "Value is none user is not registered so registering and logging in : "
             + str(e))
         user = User(**body)
         user.hash_password()
         user.save()
         expires = datetime.timedelta(days=365)
         access_token = create_access_token(identity=str(user.id),
                                            expires_delta=expires)
         user.access_token = access_token
         if user.visiting_card_exist:
             user.visiting_card_id = user.visiting_card.id
         return Response(user.to_json(),
                         mimetype="application/json",
                         status=200)
     except ValidationError as e:
         print("SocialAuthApi ValidationError  : " + str(e))
         return {'error': str(e)}, 400
     except FieldDoesNotExist as e:
         print("SocialAuthApi FieldDoesNotExist  : " + str(e))
         return {'error': str(e)}, 400
     except NotUniqueError as e:
         print("SocialAuthApi NotUniqueError  : " + str(e))
         return {'error': str(e)}, 400
     except Exception as e:
         print("SocialAuthApi Exception  : " + str(e))
         return {'error': str(e)}, 500
Esempio n. 2
0
 def post(self):
     try:
         body = request.get_json()
         user = User(body)
         user.hash_password()
         user.save()
         expires = datetime.timedelta(days=365)
         access_token = create_access_token(identity=str(user.id),
                                            expires_delta=expires)
         user.access_token = access_token
         user_json = user.to_json()
         return Response(user_json, mimetype="application/json", status=200)
     except ValidationError as e:
         print("SignupApi ValidationError  : " + str(e))
         return {'error': str(e)}, 400
     except FieldDoesNotExist as e:
         print("SignupApi FieldDoesNotExist  : " + str(e))
         return {'error': str(e)}, 400
     except NotUniqueError as e:
         print("SignupApi NotUniqueError  : " + str(e))
         return {'error': str(e)}, 409
     except Exception as e:
         print("SignupApi Exception  : " + str(e))
         return {'error': str(e)}, 500