示例#1
0
文件: forms.py 项目: cbjoseph/btray
    def validate(self):
        rv = Form.validate(self)
        if not rv:
            return False
        try:
            self.webhook_config = self.user.add_webhook_config(
                WebhookConfig(
                    name=self.name.data,
                    notes=self.notes.data,
                    bt_merchant_id=self.bt_merchant_id.data,
                    bt_public_key=self.bt_public_key.data,
                    bt_private_key=self.bt_private_key.data,
                ))
        except IntegrityError as error:
            self.bt_public_key.errors.append(
                "A webhook endpoint with this public key already exists")
            return False

        return True
示例#2
0
文件: db.py 项目: cbjoseph/btray
if command == "generate":
    if app.config["ENVIRONMENT"] == "production":
        raise Exception("Cannot generate in production")

    words = [
        "Horse", "Zenith", "Goose", "Farmer", "Obsidian", "Grapefruit",
        "Martian", "Coal", "Morlock"
    ]

    password = app.config.get("TESTING_USER_PASSWORD", None)
    if password is None:
        password = getpass("Password for 'user': "******"user", "*****@*****.**", password)
    for i in range(0, 10):
        webhook_config = WebhookConfig(name=" ".join(sample(words, 4)),
                                       notes="\n".join(sample(words, 6)),
                                       bt_merchant_id="abc%s" % i,
                                       bt_public_key="def%s" % i,
                                       bt_private_key="ghi%s" % i)
        user.webhook_configs.append(webhook_config)

        for j in range(0, 15):
            webhook_config.parse_webhook_response(
                'VGhpcyBpcyBhIHRlc3QNClRoaXMgaXMgb25seSBhIHRlc3QNCklmIHlvdSB0cnkgYW55dGhpbmcgZnVubnkgaXQgd2lsbCBlbmQgcG9vcmx5Lg==',
                'fake-valid-signature-for-testing')
    db.session.add(user)

db.session.commit()
print("Committed")