Пример #1
0
def auth_sms(deed_reference, borrower_token, borrower_code):
    deed = Deed.get_deed(deed_reference)

    if deed is None:
        LOGGER.error("Database Exception 404 for deed reference - %s" %
                     deed_reference)
        abort(status.HTTP_404_NOT_FOUND)
    else:
        LOGGER.info(
            "Signing deed for borrower_token %s against deed reference %s" %
            (borrower_token, deed_reference))

        # check if XML already exist
        if deed.deed_xml is None:
            LOGGER.info("Generating DEED_XML")
            deed_XML = convert_json_to_xml(deed.deed)
            deed.deed_xml = deed_XML.encode("utf-8")

        try:
            LOGGER.info("getting existing XML")
            modify_xml = copy.deepcopy(deed.deed_xml)
            borrower_pos = deed.get_borrower_position(borrower_token)
            borrower = Borrower.get_by_token(borrower_token)
            esec_id = borrower.esec_user_name

            if esec_id:
                result_xml, status_code = esec_client.auth_sms(
                    modify_xml, borrower_pos, esec_id, borrower_code)
                LOGGER.info("signed status code: %s", str(status_code))
                LOGGER.info("signed XML: %s" % result_xml)

                if status_code == 200:
                    deed.deed_xml = result_xml

                    LOGGER.info("Saving XML to DB")
                    deed.save()

                    LOGGER.info("updating JSON with Signature")
                    deed.deed = update_deed_signature_timestamp(
                        deed, borrower_token)
                else:
                    LOGGER.error("Failed to sign Mortgage document")
                    return "Failed to sign Mortgage document", status_code
            else:
                LOGGER.error(
                    "Failed to sign Mortgage document - unable to create user")
                abort(status.HTTP_500_INTERNAL_SERVER_ERROR)

        except:
            msg = str(sys.exc_info())
            LOGGER.error("Failed to sign Mortgage document: %s" % msg)
            abort(status.HTTP_500_INTERNAL_SERVER_ERROR)

    return jsonify({"deed": deed.deed}), status.HTTP_200_OK
Пример #2
0
def auth_sms(deed_reference, borrower_token, borrower_code):
    deed = Deed.get_deed(deed_reference)

    if deed is None:
        LOGGER.error("Database Exception 404 for deed reference - %s" % deed_reference)
        abort(status.HTTP_404_NOT_FOUND)
    else:
        LOGGER.info("Signing deed for borrower_token %s against deed reference %s" % (borrower_token, deed_reference))

        # check if XML already exist
        if deed.deed_xml is None:
            LOGGER.info("Generating DEED_XML")
            deed_XML = convert_json_to_xml(deed.deed)
            deed.deed_xml = deed_XML.encode("utf-8")

        try:
            LOGGER.info("getting existing XML")
            modify_xml = copy.deepcopy(deed.deed_xml)
            borrower_pos = deed.get_borrower_position(borrower_token)
            borrower = Borrower.get_by_token(borrower_token)
            esec_id = borrower.esec_user_name

            if esec_id:
                result_xml, status_code = esec_client.auth_sms(modify_xml, borrower_pos,
                                                               esec_id, borrower_code)
                LOGGER.info("signed status code: %s", str(status_code))
                LOGGER.info("signed XML: %s" % result_xml)

                if status_code == 200:
                    deed.deed_xml = result_xml

                    LOGGER.info("Saving XML to DB")
                    deed.save()

                    LOGGER.info("updating JSON with Signature")
                    deed.deed = update_deed_signature_timestamp(deed, borrower_token)
                else:
                    LOGGER.error("Failed to sign Mortgage document")
                    return "Failed to sign Mortgage document", status_code
            else:
                LOGGER.error("Failed to sign Mortgage document - unable to create user")
                abort(status.HTTP_500_INTERNAL_SERVER_ERROR)

        except:
            msg = str(sys.exc_info())
            LOGGER.error("Failed to sign Mortgage document: %s" % msg)
            abort(status.HTTP_500_INTERNAL_SERVER_ERROR)

    return jsonify({"deed": deed.deed}), status.HTTP_200_OK
Пример #3
0
 def test_xml_generation(self):
     xml = convert_json_to_xml(DeedModelMock().deed)
     res = validate_generated_xml(xml)
     self.assertEqual(res, True)
Пример #4
0
def auth_sms(deed_reference, borrower_token, borrower_code):
    deed_instance = Deed()
    deed = deed_instance.get_deed(deed_reference)

    if deed is None:
        application.app.logger.error(
            "Database Exception 404 for deed reference - %s" % deed_reference)
        abort(status.HTTP_404_NOT_FOUND)
    else:
        application.app.logger.info(
            "Signing deed for borrower_token %s against deed reference %s" %
            (borrower_token, deed_reference))

        signing_deed_akuma = Akuma.do_check(deed.deed, "borrower sign",
                                            deed.organisation_name, "",
                                            deed.token)
        application.app.logger.info("Check ID - Borrower SIGNING: " +
                                    signing_deed_akuma['id'])

        if signing_deed_akuma["result"] == "Z":
            application.app.logger.error("Failed to sign Mortgage document")
            return "Failed to sign Mortgage document"

        # check if XML already exist
        if deed.deed_xml is None:
            application.app.logger.info("Generating DEED_XML")
            deed_XML = convert_json_to_xml(deed.deed)
            deed.deed_xml = deed_XML.encode("utf-8")

        try:
            application.app.logger.info("getting existing XML")
            borrower_pos = deed.get_borrower_position(borrower_token)
            borrower = Borrower.get_by_token(borrower_token)
            esec_id = borrower.esec_user_name

            if esec_id:
                esec_client = make_esec_client()
                response, status_code = esec_client.auth_sms(
                    deed, borrower_pos, esec_id, borrower_code, borrower_token)
                application.app.logger.info("auth_sms status code: %s",
                                            str(status_code))

                if status_code == 200:
                    return jsonify({"deed": deed.deed}), status.HTTP_200_OK

                else:
                    application.app.logger.error(
                        "Failed to authenticate sms code")
                    return jsonify({
                        "status": "Failed to authenticate sms code"
                    }), status.HTTP_401_UNAUTHORIZED

            else:
                application.app.logger.error(
                    "Failed to sign Mortgage document - unable to create user")
                abort(status.HTTP_500_INTERNAL_SERVER_ERROR)

        except:
            msg = str(sys.exc_info())
            application.app.logger.error(
                "Failed to sign Mortgage document: %s" % msg)
            abort(status.HTTP_500_INTERNAL_SERVER_ERROR)

        return jsonify({"deed": deed.deed}), status.HTTP_200_OK
Пример #5
0
 def test_xml_generation(self):
     xml = convert_json_to_xml(DeedModelMock().deed)
     res = validate_generated_xml(xml)
     self.assertEqual(res, True)