Ejemplo n.º 1
0
def join_mailing_list():
    if 'email' in request.form:
        email = request.form['email']
        # optional fields
        first_name = request.form[
            'first_name'] if 'first_name' in request.form else None
        last_name = request.form[
            'last_name'] if 'last_name' in request.form else None
        full_name = ' '.join(filter(None, (first_name, last_name)))
        full_name = None if full_name == '' else full_name
        phone = request.form['phone'] if 'phone' in request.form else None
        dapp_user = 1 if 'dapp_user' in request.form else 0
        if 'eth_address' in request.form:
            insight.add_contact(address=request.form['eth_address'],
                                dapp_user=1,
                                name=full_name,
                                email=email,
                                phone=phone)
        ip_addr = get_real_ip()
        feedback = mailing_list.send_welcome(email, ip_addr)
        mailing_list.add_sendgrid_contact(email=email,
                                          full_name=full_name,
                                          dapp_user=dapp_user)
        return jsonify(feedback)
    else:
        return jsonify("Missing email")
Ejemplo n.º 2
0
def join_mailing_list():
    if not 'email' in request.form:
        return jsonify(success=False, message=gettext("Missing email"))
    email = request.form['email']
    if not re.match(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)",
                    email):
        return jsonify(success=False, message=gettext("Invalid email"))

    # optional fields
    eth_address = request.form.get('eth_address') or None
    first_name = request.form.get('first_name') or None
    last_name = request.form.get('last_name') or None
    full_name = request.form.get('name') or None
    if not full_name and (first_name or last_name):
        full_name = ' '.join(filter(None, (first_name, last_name)))
    phone = request.form.get('phone') or None
    ip_addr = request.form.get('ip_addr') or get_real_ip()
    country_code = request.form.get('country_code') or get_country(ip_addr)
    dapp_user = 1 if 'dapp_user' in request.form else 0
    investor = 1 if 'investor' in request.form else 0
    backfill = request.form.get(
        'backfill'
    ) or None  # Indicates the request was made from an internal backfill script.

    new_user = False

    log('Updating mailing list for', email, eth_address)
    try:
        # Add an entry to the eth_contact DB table.
        if eth_address:
            log('Adding to wallet insights')
            insight.add_contact(address=eth_address,
                                dapp_user=dapp_user,
                                investor=investor,
                                name=full_name,
                                email=email,
                                phone=phone,
                                country_code=country_code)

        # Add an entry to the email_list table.
        log('Adding to mailing list')
        new_contact = mailing_list.add_contact(email, first_name, last_name,
                                               ip_addr, country_code)

        # If it is a new contact and not a backfill, send a welcome email.
        if new_contact and not backfill:
            log('Sending welcome email')
            mailing_list.send_welcome(email)

        # Add the entry to the Sendgrid contact list.
        if new_contact:
            new_user = True
            log('Adding to Sendgrid contact list')
            mailing_list.add_sendgrid_contact(email=email,
                                              full_name=full_name,
                                              country_code=country_code,
                                              dapp_user=dapp_user)

    except Exception as err:
        log('Failure: %s' % err)
        return jsonify(success=False, message=str(err))

    if not new_user:
        return jsonify(success=True,
                       message=gettext('You\'re already registered!'))

    return jsonify(success=True, message=gettext('Thanks for signing up!'))
Ejemplo n.º 3
0
def join_mailing_list():
    email = request.form['email']
    ip_addr = get_real_ip()
    feedback = mailing_list.send_welcome(email, ip_addr)
    return jsonify(feedback)
Ejemplo n.º 4
0
def join_mailing_list():
    email = request.form['email']
    feedback = mailing_list.send_welcome(email)
    return jsonify(feedback)
Ejemplo n.º 5
0
def join_mailing_list():
    if not "email" in request.form:
        return jsonify(success=False, message=gettext("Missing email"))
    email = request.form["email"]
    if not re.match(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)",
                    email):
        return jsonify(success=False, message=gettext("Invalid email"))

    # optional fields
    source = request.form.get("source") or None
    eth_address = request.form.get("eth_address") or None
    first_name = request.form.get("first_name") or None
    last_name = request.form.get("last_name") or None
    full_name = request.form.get("name") or None
    if not full_name and (first_name or last_name):
        full_name = " ".join(filter(None, (first_name, last_name)))
    phone = request.form.get("phone") or None
    ip_addr = request.form.get("ip_addr") or get_real_ip()
    country_code = request.form.get("country_code") or get_country(ip_addr)
    dapp_user = 1 if "dapp_user" in request.form else 0
    investor = 1 if "investor" in request.form else 0
    backfill = (
        request.form.get("backfill") or None
    )  # Indicates the request was made from an internal backfill script.

    new_user = False

    log("Updating mailing list for", email, eth_address)
    try:
        # Add an entry to the eth_contact DB table.
        if eth_address:
            log("Adding to wallet insights")
            insight.add_contact(
                address=eth_address,
                dapp_user=dapp_user,
                investor=investor,
                name=full_name,
                email=email,
                phone=phone,
                country_code=country_code,
            )

        # Add an entry to the email_list table.
        log("Adding to mailing list")
        new_contact = mailing_list.add_contact(email, first_name, last_name,
                                               ip_addr, country_code)

        # If it is a new contact and not a backfill, send a welcome email.
        if new_contact and not backfill:
            log("Sending welcome email")
            mailing_list.send_welcome(email, source)

        # Add the entry to the Sendgrid contact list.
        if new_contact:
            new_user = True
            log("Adding to Sendgrid contact list")
            mailing_list.add_sendgrid_contact(
                email=email,
                full_name=full_name,
                country_code=country_code,
                dapp_user=dapp_user,
            )

    except Exception as err:
        log("Failure: %s" % err)
        return jsonify(success=False, message=str(err))

    if not new_user:
        return jsonify(success=True,
                       message=gettext("You're already registered!"))

    return jsonify(success=True, message=gettext("Thanks for signing up!"))