コード例 #1
0
    def upload(self, path, file_object):
        path = "%s/%s" % (base64.encodestring(self.email_address), path.lstrip('/'))
        client = boto3.client(
            's3',
            aws_access_key_id=config__get("COUCHDROP_SERVICE__AWS_KEY"),
            aws_secret_access_key=config__get("COUCHDROP_SERVICE__AWS_SECRET")
        )

        client.put_object(Bucket=config__get("COUCHDROP_SERVICE__AWS_HOSTED_S3_BUCKET"), Key=path, Body=file_object)
コード例 #2
0
    def download(self, path):
        path = "%s/%s" % (base64.encodestring(self.email_address), path.lstrip('/'))
        client = boto3.client(
            's3',
            aws_access_key_id=config__get("COUCHDROP_SERVICE__AWS_KEY"),
            aws_secret_access_key=config__get("COUCHDROP_SERVICE__AWS_SECRET")
        )

        object = client.get_object(Bucket=config__get("COUCHDROP_SERVICE__AWS_HOSTED_S3_BUCKET"), Key=path)
        return True, object["Body"].read()
コード例 #3
0
def push_authenticate_get_pub():
    username = request.form.get("username")
    service_token = request.form.get("service_token")

    if service_token != config__get("COUCHDROP_SERVICE__SERVICE_TOKEN"):
        return flask.jsonify(err="This route requires a service token"), 403

    account = flask.g.db_session.query(Account).filter(
        Account.username == username).scalar()
    if account:
        if account.endpoint__valid_public_key:
            return flask.jsonify(public_key=account.endpoint__valid_public_key)
        return flask.jsonify(err="No public key"), 403
    return flask.jsonify(err="Account was invalid"), 403
コード例 #4
0
def push_authenticate_get_token():
    username = request.form.get("username")
    service_token = request.form.get("service_token")

    if service_token != config__get("COUCHDROP_SERVICE__SERVICE_TOKEN"):
        return flask.jsonify(err="This route requires a service token"), 403

    account = flask.g.db_session.query(Account).filter(
        Account.username == username).scalar()
    if account:
        if not account.email_confirmation_code_accepted:
            return flask.jsonify(
                err="Account email address has not been registered"), 403

        new_token = PushToken()
        new_token.account = account.username
        new_token.authenticated_user = username
        new_token.token = str(uuid.uuid4())
        new_token.admin = True
        flask.g.db_session.add(new_token)
        return flask.jsonify(token=new_token.token)
    return flask.jsonify(err="Account was invalid"), 403
コード例 #5
0
def mandrill__email_confirm__email(rec, rec_name, confirm_code):
    request = {
        "key":
        config__get("COUCHDROP_SERVICE__MANDRILL_API_KEY"),
        "template_name":
        "Confirm email",
        "template_content": [{
            "content": "example content",
            "name": "example name"
        }],
        "message": {
            "subject":
            "Couchdrop Email Confirmation",
            "from_email":
            "*****@*****.**",
            "from_name":
            "Couchdrop",
            "to": [{
                "email": rec,
                "name": rec_name,
                "type": "to"
            }],
            "headers": {
                "Reply-To": "*****@*****.**"
            },
            "important":
            False,
            "track_opens":
            None,
            "track_clicks":
            None,
            "auto_text":
            None,
            "auto_html":
            None,
            "inline_css":
            None,
            "url_strip_qs":
            None,
            "preserve_recipients":
            None,
            "view_content_link":
            None,
            "tracking_domain":
            None,
            "signing_domain":
            None,
            "return_path_domain":
            None,
            "merge":
            True,
            "merge_language":
            "mailchimp",
            "global_merge_vars": [
                {
                    "name":
                    "link",
                    "content":
                    "https://my.couchdrop.io/register/awaitingconfirm/%s" %
                    confirm_code
                },
            ]
        },
        "async":
        False,
    }

    requests.post(
        "https://mandrillapp.com/api/1.0/messages/send-template.json",
        data=json.dumps(request))
コード例 #6
0
def mandrill__send_file__email(rec, rec_name, sender_name, filename,
                               file_object_base64_encoded):
    request = {
        "key":
        config__get("COUCHDROP_SERVICE__MANDRILL_API_KEY"),
        "template_name":
        "Received a file",
        "template_content": [{
            "content": "example content",
            "name": "example name"
        }],
        "message": {
            "subject":
            "You received a file",
            "from_email":
            "*****@*****.**",
            "from_name":
            "Couchdrop",
            "to": [{
                "email": rec,
                "name": rec_name,
                "type": "to"
            }],
            "headers": {
                "Reply-To": "*****@*****.**"
            },
            "important":
            False,
            "track_opens":
            None,
            "track_clicks":
            None,
            "auto_text":
            None,
            "auto_html":
            None,
            "inline_css":
            None,
            "url_strip_qs":
            None,
            "preserve_recipients":
            None,
            "view_content_link":
            None,
            "tracking_domain":
            None,
            "signing_domain":
            None,
            "return_path_domain":
            None,
            "merge":
            True,
            "merge_language":
            "mailchimp",
            "global_merge_vars": [{
                "name": "filename",
                "content": filename
            }, {
                "name": "sender",
                "content": sender_name
            }],
            "attachments": [{
                "type": "text/plain",
                "name": filename,
                "content": file_object_base64_encoded
            }],
        },
        "async":
        False,
    }

    requests.post(
        "https://mandrillapp.com/api/1.0/messages/send-template.json",
        data=json.dumps(request))