Esempio n. 1
0
    def post(self):

        try:
            args = _parser.parse_args(strict=True)
            user = UserModel.get_by_email(args["email"])

            print(args)
            if user:
                return {"message": "Conflict: User already exists!!"}, 409

            UserModel(**args).save_to_db()
            return {"message": "Success!"}, 200

        except BadRequest as e:
            return {"error": "Bad Request"}, 400
        except BaseException as e:
            print(e)
            return {"error": "Internal Server Error"}, 500
Esempio n. 2
0
    def post(self):
        try:
            args = _parser.parse_args(strict=True)
            user = UserModel.get_by_email(args["email"])

            if user:
                is_password_valid = user.password == args.password
                if is_password_valid:
                    claims = {"email": user.email}
                    access_token = create_access_token(identity=user.id,
                                                       user_claims=claims)
                    return {"access_token": access_token}, 200
            return {"error": "Unauthorized!"}, 401

        except BadRequest as e:
            return {"error": "Bad Request"}, 400
        except BaseException as e:
            print(e)
            return {"error": "Internal Server Error"}, 500