|
2 | 2 | from datetime import datetime |
3 | 3 | import os |
4 | 4 | import re |
5 | | -import sys |
6 | | -import calendar |
7 | | -import random |
8 | 5 |
|
9 | 6 | from flask_cors import CORS, cross_origin |
10 | 7 | from app import app |
@@ -247,7 +244,7 @@ def join_mailing_list(): |
247 | 244 | # Add an entry to the email_list table. |
248 | 245 | log("Adding to mailing list") |
249 | 246 | new_contact = mailing_list.add_contact( |
250 | | - email, first_name, last_name, ip_addr, country_code |
| 247 | + email, first_name, last_name, ip_addr, country_code, "originprotocol.com" |
251 | 248 | ) |
252 | 249 |
|
253 | 250 | # If it is a new contact and not a backfill, send a welcome email. |
@@ -275,6 +272,50 @@ def join_mailing_list(): |
275 | 272 |
|
276 | 273 | return jsonify(success=True, message=gettext("Thanks for signing up!")) |
277 | 274 |
|
| 275 | +@cross_origin() |
| 276 | +@app.route("/oeth-subscribe", methods=["POST"], strict_slashes=False) |
| 277 | +def oeth_subscribe(): |
| 278 | + if not "email" in request.form: |
| 279 | + return jsonify(success=False, message=gettext("Missing email")) |
| 280 | + email = request.form["email"] |
| 281 | + if not re.match(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", email): |
| 282 | + return jsonify(success=False, message=gettext("Invalid email")) |
| 283 | + |
| 284 | + # optional fields |
| 285 | + source = request.form.get("source") or None |
| 286 | + eth_address = request.form.get("eth_address") or None |
| 287 | + first_name = request.form.get("first_name") or None |
| 288 | + last_name = request.form.get("last_name") or None |
| 289 | + full_name = request.form.get("name") or None |
| 290 | + if not full_name and (first_name or last_name): |
| 291 | + full_name = " ".join(filter(None, (first_name, last_name))) |
| 292 | + ip_addr = request.form.get("ip_addr") or get_real_ip() |
| 293 | + country_code = request.form.get("country_code") or get_country(ip_addr) |
| 294 | + |
| 295 | + new_user = False |
| 296 | + |
| 297 | + log("Updating mailing list for", email, eth_address) |
| 298 | + try: |
| 299 | + # Add an entry to the email_list table. |
| 300 | + log("Adding to mailing list") |
| 301 | + new_contact = mailing_list.add_contact( |
| 302 | + email, first_name, last_name, ip_addr, country_code, source |
| 303 | + ) |
| 304 | + |
| 305 | + # Add the entry to the Sendgrid contact list. |
| 306 | + if new_contact: |
| 307 | + new_user = True |
| 308 | + |
| 309 | + except Exception as err: |
| 310 | + log("Failure: %s" % err) |
| 311 | + return jsonify(success=False, message=str(err)) |
| 312 | + |
| 313 | + if not new_user: |
| 314 | + return jsonify(success=True, message=gettext("You're already registered!")) |
| 315 | + |
| 316 | + return jsonify(success=True, message=gettext("Thanks for signing up!")) |
| 317 | + |
| 318 | + |
278 | 319 | @app.route("/mailing-list/unsubscribe", methods=["GET"], strict_slashes=False) |
279 | 320 | def unsubscribe(): |
280 | 321 | email = request.args.get("email") |
|
0 commit comments