make-post-sell 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- make_post_sell/__init__.py +125 -0
- make_post_sell/config_jinja2.py +5 -0
- make_post_sell/lib/__init__.py +0 -0
- make_post_sell/lib/currency.py +39 -0
- make_post_sell/lib/hex_color.py +43 -0
- make_post_sell/lib/mail.py +286 -0
- make_post_sell/lib/mail_messages.py +200 -0
- make_post_sell/lib/phone_numbers.py +23 -0
- make_post_sell/lib/render.py +32 -0
- make_post_sell/lib/sanitize_html.py +219 -0
- make_post_sell/lib/time_funcs.py +12 -0
- make_post_sell/lib/uuid_validation.py +27 -0
- make_post_sell/models/__init__.py +94 -0
- make_post_sell/models/cart.py +491 -0
- make_post_sell/models/cart_coupon.py +33 -0
- make_post_sell/models/coupon.py +223 -0
- make_post_sell/models/coupon_redemption.py +34 -0
- make_post_sell/models/inventory.py +50 -0
- make_post_sell/models/invoice.py +236 -0
- make_post_sell/models/market.py +10 -0
- make_post_sell/models/meta.py +196 -0
- make_post_sell/models/price.py +31 -0
- make_post_sell/models/product.py +561 -0
- make_post_sell/models/shop.py +415 -0
- make_post_sell/models/shop_location.py +88 -0
- make_post_sell/models/shop_search_request.py +35 -0
- make_post_sell/models/stripe_user_shop.py +79 -0
- make_post_sell/models/user.py +317 -0
- make_post_sell/models/user_address.py +29 -0
- make_post_sell/models/user_product.py +36 -0
- make_post_sell/models/user_shop.py +56 -0
- make_post_sell/request_methods.py +198 -0
- make_post_sell/routes.py +134 -0
- make_post_sell/scripts/__init__.py +1 -0
- make_post_sell/scripts/alembic/env.py +77 -0
- make_post_sell/scripts/alembic/script.py.mako +26 -0
- make_post_sell/scripts/alembic/versions/03292288a132_role_id_to_user_shop_table.py +30 -0
- make_post_sell/scripts/alembic/versions/1275752bc491_shop_updated_timestamp.py +24 -0
- make_post_sell/scripts/alembic/versions/15751f5d7a03_add_active_cart_total_in_cents_to_user_.py +28 -0
- make_post_sell/scripts/alembic/versions/1b3ecdde9e65_handling_options.py +36 -0
- make_post_sell/scripts/alembic/versions/201924e6306f_add_shop_id_to_cart.py +37 -0
- make_post_sell/scripts/alembic/versions/24662905655f_create_new_active_shop_id_column_on_.py +26 -0
- make_post_sell/scripts/alembic/versions/3e1e70bfe89d_google_analytics_id.py +24 -0
- make_post_sell/scripts/alembic/versions/4d9da43b0e86_product_visibility_column.py +27 -0
- make_post_sell/scripts/alembic/versions/5c40dfb56179_shop_ribbon_columns.py +28 -0
- make_post_sell/scripts/alembic/versions/6da97f2f913f_add_updated_timestamp_to_cart.py +28 -0
- make_post_sell/scripts/alembic/versions/7217f39a20a8_product_file_bytes.py +28 -0
- make_post_sell/scripts/alembic/versions/96f851cbab01_terms_and_privacy.py +30 -0
- make_post_sell/scripts/alembic/versions/aad3d454a6f4_shop_logo_banner_boolean.py +30 -0
- make_post_sell/scripts/alembic/versions/ab7338eaedf1_add_price_in_cents_column.py +24 -0
- make_post_sell/scripts/alembic/versions/af28cc35ed6f_product_bundles.py +34 -0
- make_post_sell/scripts/alembic/versions/b0d5604d9255_add_active_cart_count_to_user_table.py +28 -0
- make_post_sell/scripts/alembic/versions/b8be6cd51cbd_stripe_shop_user_active_card_id.py +27 -0
- make_post_sell/scripts/alembic/versions/bfc4195a7f56_product_is_sellable_coluumn.py +26 -0
- make_post_sell/scripts/alembic/versions/c263b4fba9e7_new_ux_columns.py +30 -0
- make_post_sell/scripts/alembic/versions/c4d5566ec87d_coupon_stackable_and_couponredemption.py +42 -0
- make_post_sell/scripts/alembic/versions/cc6211ec360e_physical_products_shop_locations_and_.py +61 -0
- make_post_sell/scripts/alembic/versions/cdad5c220c39_plausible_domain_name_column_on_shop.py +24 -0
- make_post_sell/scripts/alembic/versions/d38d649cb682_address_migration.py +31 -0
- make_post_sell/scripts/alembic/versions/ddfbd6d96915_shop_location_rates_and_hours.py +46 -0
- make_post_sell/scripts/alembic/versions/e12bbe39d87e_cart_coupon_table.py +40 -0
- make_post_sell/scripts/alembic/versions/e6ac162d096f_password_attempt_throttling.py +26 -0
- make_post_sell/scripts/alembic/versions/eadd0d69e133_shop_ribbon_text_color.py +24 -0
- make_post_sell/scripts/alembic/versions/f3aa57777025_coupon_table.py +45 -0
- make_post_sell/scripts/alembic/versions/f882f2255cd1_add_stripe_secret_and_public_key_to_shop.py +27 -0
- make_post_sell/scripts/alembic/versions/fd9f7e2f2b78_user_full_name.py +28 -0
- make_post_sell/scripts/initialize_db.py +77 -0
- make_post_sell/scripts/pshell.py +13 -0
- make_post_sell/static/css/common.css +883 -0
- make_post_sell/static/favicon.ico +0 -0
- make_post_sell/static/js/custom.js +30 -0
- make_post_sell/static/js/jquery-3.6.0.min.js +3 -0
- make_post_sell/static/js/jquery.min.js +3 -0
- make_post_sell/static/makepostsell-3.png +0 -0
- make_post_sell/static/makepostsell.png +0 -0
- make_post_sell/static/memopoly.png +0 -0
- make_post_sell/static/mps.png +0 -0
- make_post_sell/templates/actions_new.j2 +41 -0
- make_post_sell/templates/actions_view.j2 +51 -0
- make_post_sell/templates/base.j2 +126 -0
- make_post_sell/templates/billing.j2 +49 -0
- make_post_sell/templates/cart.j2 +262 -0
- make_post_sell/templates/cart_checkout.j2 +47 -0
- make_post_sell/templates/carts.j2 +20 -0
- make_post_sell/templates/content.j2 +85 -0
- make_post_sell/templates/content_new.j2 +66 -0
- make_post_sell/templates/coupon.j2 +81 -0
- make_post_sell/templates/coupon_new.j2 +159 -0
- make_post_sell/templates/coupons.j2 +66 -0
- make_post_sell/templates/home.j2 +66 -0
- make_post_sell/templates/invoice.j2 +35 -0
- make_post_sell/templates/join-or-log-in.j2 +40 -0
- make_post_sell/templates/markup_editor.j2 +38 -0
- make_post_sell/templates/markup_renderer.j2 +19 -0
- make_post_sell/templates/product.j2 +150 -0
- make_post_sell/templates/product_edit.j2 +236 -0
- make_post_sell/templates/product_new.j2 +110 -0
- make_post_sell/templates/sales.j2 +26 -0
- make_post_sell/templates/shop.j2 +30 -0
- make_post_sell/templates/shop_about.j2 +44 -0
- make_post_sell/templates/shop_location_form.j2 +210 -0
- make_post_sell/templates/shop_locations.j2 +28 -0
- make_post_sell/templates/shop_new.j2 +68 -0
- make_post_sell/templates/shop_products.j2 +35 -0
- make_post_sell/templates/shop_settings.j2 +315 -0
- make_post_sell/templates/shop_users.j2 +105 -0
- make_post_sell/templates/shops.j2 +28 -0
- make_post_sell/templates/snippets/analytics.j2 +15 -0
- make_post_sell/templates/snippets/csrf.j2 +3 -0
- make_post_sell/templates/snippets/flash-alerts.j2 +16 -0
- make_post_sell/templates/snippets/optional-javascript.j2 +2 -0
- make_post_sell/templates/snippets/ribbon.j2 +33 -0
- make_post_sell/templates/snippets/search.j2 +25 -0
- make_post_sell/templates/snippets/stripe.j2 +114 -0
- make_post_sell/templates/update-card.j2 +32 -0
- make_post_sell/templates/user_addresses.j2 +70 -0
- make_post_sell/templates/user_purchases.j2 +55 -0
- make_post_sell/templates/user_settings.j2 +81 -0
- make_post_sell/templates/verification-challenge.j2 +27 -0
- make_post_sell/tests/__init__.py +0 -0
- make_post_sell/tests/test_functional.py +646 -0
- make_post_sell/tests/test_models.py +159 -0
- make_post_sell/tests/test_sanitize_html.py +56 -0
- make_post_sell/views/__init__.py +108 -0
- make_post_sell/views/actions.py +15 -0
- make_post_sell/views/authentication.py +123 -0
- make_post_sell/views/billing.py +115 -0
- make_post_sell/views/cart.py +568 -0
- make_post_sell/views/content.py +72 -0
- make_post_sell/views/coupon.py +184 -0
- make_post_sell/views/invoice.py +28 -0
- make_post_sell/views/misc.py +75 -0
- make_post_sell/views/product.py +491 -0
- make_post_sell/views/sales.py +12 -0
- make_post_sell/views/shop.py +671 -0
- make_post_sell/views/shop_location.py +209 -0
- make_post_sell/views/user.py +136 -0
- make_post_sell-1.0.0.dist-info/METADATA +237 -0
- make_post_sell-1.0.0.dist-info/RECORD +142 -0
- make_post_sell-1.0.0.dist-info/WHEEL +5 -0
- make_post_sell-1.0.0.dist-info/entry_points.txt +6 -0
- make_post_sell-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
from pyramid.config import Configurator
|
|
2
|
+
from pyramid.session import SignedCookieSessionFactory
|
|
3
|
+
from pyramid.session import JSONSerializer
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SpamBlockerMiddleware:
|
|
9
|
+
"""
|
|
10
|
+
Middleware to block spammy requests based on query string patterns.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
def __init__(self, app):
|
|
14
|
+
self.app = app
|
|
15
|
+
|
|
16
|
+
def __call__(self, environ, start_response):
|
|
17
|
+
# Extract the query string
|
|
18
|
+
query_string = environ.get("QUERY_STRING", "")
|
|
19
|
+
|
|
20
|
+
# Define regex patterns
|
|
21
|
+
unescaped_next_count = len(re.findall(r"(?i)\bnext=", query_string))
|
|
22
|
+
escaped_next_count = len(
|
|
23
|
+
re.findall(r"(?i)\bnext%25|next%3D|next%253D|next%2525", query_string)
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
# Check if the request is spammy
|
|
27
|
+
if unescaped_next_count + escaped_next_count > 1:
|
|
28
|
+
# Respond with 401 Unauthorized
|
|
29
|
+
print("next= query spam detected.")
|
|
30
|
+
status = "401 Unauthorized"
|
|
31
|
+
headers = [("Content-Type", "text/plain")]
|
|
32
|
+
start_response(status, headers)
|
|
33
|
+
return [b"Request appears malformed or spammy.\n"]
|
|
34
|
+
|
|
35
|
+
# Forward the request to the next application/middleware
|
|
36
|
+
return self.app(environ, start_response)
|
|
37
|
+
|
|
38
|
+
def __getattr__(self, name):
|
|
39
|
+
"""
|
|
40
|
+
Delegate attribute access to the wrapped Pyramid app.
|
|
41
|
+
This ensures that attributes like 'registry' are accessible.
|
|
42
|
+
"""
|
|
43
|
+
return getattr(self.app, name)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def get_int_or_bool_or_none_or_str(value):
|
|
47
|
+
"""
|
|
48
|
+
Given a string value pulled from a configuration file,
|
|
49
|
+
this function attempts to return the value with the proper type.
|
|
50
|
+
"""
|
|
51
|
+
try:
|
|
52
|
+
return int(value)
|
|
53
|
+
except ValueError:
|
|
54
|
+
if value.lower() in {"yes", "y", "true", "y"}:
|
|
55
|
+
return True
|
|
56
|
+
elif value.lower() in {"no", "n", "false", "f"}:
|
|
57
|
+
return False
|
|
58
|
+
elif value.lower() == "none":
|
|
59
|
+
return None
|
|
60
|
+
return str(value)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def get_children_settings(settings, parent_key):
|
|
64
|
+
"""
|
|
65
|
+
Accept a settings dict and parent key, return dict of children
|
|
66
|
+
|
|
67
|
+
For example:
|
|
68
|
+
|
|
69
|
+
auth_tkt.hashalg = md5
|
|
70
|
+
|
|
71
|
+
Results to:
|
|
72
|
+
|
|
73
|
+
{'auth_tkt.hashalg': 'md5'}
|
|
74
|
+
|
|
75
|
+
This function returns the following:
|
|
76
|
+
|
|
77
|
+
>>> get_children_settings({'auth_tkt.hashalg': 'md5'}, 'auth_tkt')
|
|
78
|
+
{'hashalg': 'md5'}
|
|
79
|
+
|
|
80
|
+
"""
|
|
81
|
+
# needed to support expanding ENV vars from ini.
|
|
82
|
+
from os.path import expandvars
|
|
83
|
+
|
|
84
|
+
# the +1 is the . between parent and child settings.
|
|
85
|
+
parent_len = len(parent_key) + 1
|
|
86
|
+
children = {}
|
|
87
|
+
for key, value in settings.items():
|
|
88
|
+
if parent_key in key:
|
|
89
|
+
# expandvars replaces template with ENV vars.
|
|
90
|
+
children[key[parent_len:]] = get_int_or_bool_or_none_or_str(
|
|
91
|
+
expandvars(value)
|
|
92
|
+
)
|
|
93
|
+
return children
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def main(global_config, **settings):
|
|
97
|
+
"""This function returns a Pyramid WSGI application."""
|
|
98
|
+
|
|
99
|
+
# Setup session factory signed cookies prevent tampering, not encrypted.
|
|
100
|
+
session_settings = get_children_settings(settings, "session")
|
|
101
|
+
|
|
102
|
+
# Setup session serializer.
|
|
103
|
+
session_settings["serializer"] = JSONSerializer()
|
|
104
|
+
|
|
105
|
+
session_factory = SignedCookieSessionFactory(**session_settings)
|
|
106
|
+
|
|
107
|
+
with Configurator(settings=settings, session_factory=session_factory) as config:
|
|
108
|
+
# all of the models for persisting data into our database.
|
|
109
|
+
config.include(".models")
|
|
110
|
+
# all of the web application routes.
|
|
111
|
+
config.include(".routes")
|
|
112
|
+
# all of the data we attach to each inbound request.
|
|
113
|
+
config.include(".request_methods")
|
|
114
|
+
# enable jinja2 templating engine.
|
|
115
|
+
config.include(".config_jinja2")
|
|
116
|
+
# scan each of these includes for additional configuration.
|
|
117
|
+
config.scan()
|
|
118
|
+
|
|
119
|
+
# generate app.
|
|
120
|
+
app = config.make_wsgi_app()
|
|
121
|
+
|
|
122
|
+
# Wrap the Pyramid app with SpamBlockerMiddleware.
|
|
123
|
+
app = SpamBlockerMiddleware(app)
|
|
124
|
+
|
|
125
|
+
return app
|
|
File without changes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Maximum value for SQLite INTEGER
|
|
2
|
+
MAX_INT = 9223372036854775807
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def dollars_to_cents(dollars):
|
|
6
|
+
return int(float(dollars) * 100)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def cents_to_dollars(cents):
|
|
10
|
+
return int(cents) / 100.0
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def validate_int(value):
|
|
14
|
+
try:
|
|
15
|
+
value = int(value)
|
|
16
|
+
if abs(value) > MAX_INT:
|
|
17
|
+
raise ValueError(
|
|
18
|
+
f"Value exceeds maximum limit {MAX_INT} for SQLite INTEGER."
|
|
19
|
+
)
|
|
20
|
+
return value
|
|
21
|
+
except ValueError as e:
|
|
22
|
+
raise ValueError(f"Invalid integer value: {e}") from e
|
|
23
|
+
except TypeError as e:
|
|
24
|
+
raise TypeError(f"Invalid integer type: {e}") from e
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def validate_float(value):
|
|
28
|
+
try:
|
|
29
|
+
value = float(value)
|
|
30
|
+
value_in_cents = dollars_to_cents(value)
|
|
31
|
+
if abs(value_in_cents) > MAX_INT:
|
|
32
|
+
raise ValueError(
|
|
33
|
+
f"Value exceeds maximum limit {MAX_INT} for SQLite INTEGER."
|
|
34
|
+
)
|
|
35
|
+
return value
|
|
36
|
+
except ValueError as e:
|
|
37
|
+
raise ValueError(f"Invalid float value: {e}") from e
|
|
38
|
+
except TypeError as e:
|
|
39
|
+
raise TypeError(f"Invalid float type: {e}") from e
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Original Sourcecode pulled from:
|
|
3
|
+
|
|
4
|
+
https://thadeusb.com/weblog/2010/10/10/python_scale_hex_color/
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def clamp(val, minimum=0, maximum=255):
|
|
9
|
+
if val < minimum:
|
|
10
|
+
return minimum
|
|
11
|
+
if val > maximum:
|
|
12
|
+
return maximum
|
|
13
|
+
return val
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def color_scale(hex_str, scale_factor):
|
|
17
|
+
"""
|
|
18
|
+
Scales a hex string by ``scale_factor``. Returns scaled hex string.
|
|
19
|
+
|
|
20
|
+
To darken the color, use a float value between 0 and 1.
|
|
21
|
+
To brighten the color, use a float value greater than 1.
|
|
22
|
+
|
|
23
|
+
>>> color_scale("#DF3C3C", .5)
|
|
24
|
+
#6F1E1E
|
|
25
|
+
>>> color_scale("#52D24F", 1.6)
|
|
26
|
+
#83FF7E
|
|
27
|
+
>>> color_scale("#4F75D2", 1)
|
|
28
|
+
#4F75D2
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
hex_str = hex_str.strip("#")
|
|
32
|
+
|
|
33
|
+
if scale_factor < 0 or len(hex_str) != 6:
|
|
34
|
+
return hex_str
|
|
35
|
+
|
|
36
|
+
r, g, b = int(hex_str[:2], 16), int(hex_str[2:4], 16), int(hex_str[4:], 16)
|
|
37
|
+
|
|
38
|
+
r = int(clamp(r * scale_factor))
|
|
39
|
+
g = int(clamp(g * scale_factor))
|
|
40
|
+
b = int(clamp(b * scale_factor))
|
|
41
|
+
|
|
42
|
+
# return "#%02x%02x%02x" % (r, g, b)
|
|
43
|
+
return f"#{r:02x}{g:02x}{b:02x}"
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
# quote email address in OTP so that a plus address
|
|
2
|
+
# is not decoded as a space during authentication.
|
|
3
|
+
try:
|
|
4
|
+
# Python 2.
|
|
5
|
+
from urllib import quote_plus
|
|
6
|
+
except ImportError:
|
|
7
|
+
# Python 3.
|
|
8
|
+
from urllib.parse import quote_plus
|
|
9
|
+
|
|
10
|
+
from make_post_sell.lib.mail_messages import (
|
|
11
|
+
WELCOME_1_TEXT,
|
|
12
|
+
WELCOME_1_HTML,
|
|
13
|
+
PURCHASE_1_TEXT,
|
|
14
|
+
PURCHASE_1_HTML,
|
|
15
|
+
SALE_1_TEXT,
|
|
16
|
+
SALE_1_HTML,
|
|
17
|
+
INVITE_1_TEXT,
|
|
18
|
+
INVITE_1_HTML,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
import dkim
|
|
22
|
+
import smtplib
|
|
23
|
+
from email.mime.multipart import MIMEMultipart
|
|
24
|
+
from email.mime.text import MIMEText
|
|
25
|
+
# Catch socket errors when postfix isn't running...
|
|
26
|
+
from socket import error as socket_error
|
|
27
|
+
import logging
|
|
28
|
+
|
|
29
|
+
log = logging.getLogger(__name__)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def send_email(
|
|
33
|
+
to_email,
|
|
34
|
+
sender_email,
|
|
35
|
+
subject,
|
|
36
|
+
message_text,
|
|
37
|
+
message_html,
|
|
38
|
+
relay="localhost",
|
|
39
|
+
dkim_private_key_path="",
|
|
40
|
+
dkim_selector="",
|
|
41
|
+
dkim_signature_algorithm="ed25519-sha256",
|
|
42
|
+
debug_mode=False,
|
|
43
|
+
):
|
|
44
|
+
# The `email` library assumes it is working with string objects.
|
|
45
|
+
# The `dkim` library assumes it is working with byte objects.
|
|
46
|
+
# This function performs the acrobatics to make them both happy.
|
|
47
|
+
|
|
48
|
+
if isinstance(message_text, bytes):
|
|
49
|
+
# Needed for Python 3.
|
|
50
|
+
message_text = message_text.decode()
|
|
51
|
+
|
|
52
|
+
if isinstance(message_html, bytes):
|
|
53
|
+
# Needed for Python 3.
|
|
54
|
+
message_html = message_html.decode()
|
|
55
|
+
|
|
56
|
+
sender_domain = sender_email.split("@")[-1]
|
|
57
|
+
msg = MIMEMultipart("alternative")
|
|
58
|
+
msg.attach(MIMEText(message_text, "plain"))
|
|
59
|
+
msg.attach(MIMEText(message_html, "html"))
|
|
60
|
+
msg["To"] = to_email
|
|
61
|
+
msg["From"] = sender_email
|
|
62
|
+
msg["Subject"] = subject
|
|
63
|
+
|
|
64
|
+
try:
|
|
65
|
+
# Python 3 libraries expect bytes.
|
|
66
|
+
msg_data = msg.as_bytes()
|
|
67
|
+
except:
|
|
68
|
+
# Python 2 libraries expect strings.
|
|
69
|
+
msg_data = msg.as_string()
|
|
70
|
+
|
|
71
|
+
if dkim_private_key_path and dkim_selector:
|
|
72
|
+
try:
|
|
73
|
+
# The dkim library uses regex on byte strings so everything
|
|
74
|
+
# needs to be encoded from strings to bytes.
|
|
75
|
+
with open(dkim_private_key_path) as fh:
|
|
76
|
+
dkim_private_key = fh.read()
|
|
77
|
+
headers = [b"To", b"From", b"Subject"]
|
|
78
|
+
sig = dkim.sign(
|
|
79
|
+
message=msg_data,
|
|
80
|
+
selector=str(dkim_selector).encode(),
|
|
81
|
+
domain=sender_domain.encode(),
|
|
82
|
+
privkey=dkim_private_key.encode(),
|
|
83
|
+
include_headers=headers,
|
|
84
|
+
signature_algorithm=dkim_signature_algorithm.encode(),
|
|
85
|
+
)
|
|
86
|
+
# Add the dkim signature to the email message headers.
|
|
87
|
+
# Decode the signature back to string_type because later on
|
|
88
|
+
# the call to msg.as_string() performs its own bytes encoding...
|
|
89
|
+
msg["DKIM-Signature"] = sig[len("DKIM-Signature: ") :].decode()
|
|
90
|
+
|
|
91
|
+
try:
|
|
92
|
+
# Python 3 libraries expect bytes.
|
|
93
|
+
msg_data = msg.as_bytes()
|
|
94
|
+
except AttributeError: # For Python 2 compatibility
|
|
95
|
+
# Python 2 libraries expect strings.
|
|
96
|
+
msg_data = msg.as_string()
|
|
97
|
+
except Exception as e:
|
|
98
|
+
if debug_mode:
|
|
99
|
+
log.error(f"DKIM signing failed: {str(e)}")
|
|
100
|
+
raise
|
|
101
|
+
|
|
102
|
+
try:
|
|
103
|
+
s = smtplib.SMTP(relay)
|
|
104
|
+
s.sendmail(sender_email, [to_email], msg_data)
|
|
105
|
+
s.quit()
|
|
106
|
+
return msg
|
|
107
|
+
except (socket_error, smtplib.SMTPException) as e:
|
|
108
|
+
error_msg = f"Failed to send email: {str(e)}"
|
|
109
|
+
|
|
110
|
+
if debug_mode:
|
|
111
|
+
# Log the error first for quick scanning
|
|
112
|
+
log.error(error_msg)
|
|
113
|
+
# Then log the email details
|
|
114
|
+
log.info(
|
|
115
|
+
f"""
|
|
116
|
+
|
|
117
|
+
Email Contents:
|
|
118
|
+
To: {to_email}
|
|
119
|
+
From: {sender_email}
|
|
120
|
+
Subject: {subject}
|
|
121
|
+
|
|
122
|
+
Text Content:
|
|
123
|
+
{message_text}
|
|
124
|
+
|
|
125
|
+
HTML Content:
|
|
126
|
+
{message_html}
|
|
127
|
+
"""
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
if not debug_mode:
|
|
131
|
+
raise
|
|
132
|
+
return None
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def send_pyramid_email(request, to_email, subject, message_text, message_html):
|
|
136
|
+
"""Thin wrapper around `send_email` to customize settings using request object."""
|
|
137
|
+
default_sender = f"no-reply@{request.domain}"
|
|
138
|
+
sender_email = request.app.get("email.sender", default_sender)
|
|
139
|
+
subject = f"{subject} | {request.app.get('email.subject_postfix', request.domain)}"
|
|
140
|
+
relay = request.app.get("email.relay", "localhost")
|
|
141
|
+
dkim_private_key_path = request.app.get("email.dkim_private_key_path", "")
|
|
142
|
+
dkim_selector = request.app.get("email.dkim_selector", "")
|
|
143
|
+
dkim_signature_algorithm = request.app.get(
|
|
144
|
+
"email.dkim_signature_algorithm", "ed25519-sha256"
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
send_email(
|
|
148
|
+
to_email,
|
|
149
|
+
sender_email,
|
|
150
|
+
subject,
|
|
151
|
+
message_text,
|
|
152
|
+
message_html,
|
|
153
|
+
relay,
|
|
154
|
+
dkim_private_key_path,
|
|
155
|
+
dkim_selector,
|
|
156
|
+
dkim_signature_algorithm,
|
|
157
|
+
request.debug_mode,
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def send_verification_digits_to_email(request, to_email, raw_digits):
|
|
162
|
+
"""
|
|
163
|
+
Send email with raw_digits a user may pass to verify & authenticate.
|
|
164
|
+
|
|
165
|
+
request
|
|
166
|
+
the request (of the successful log in attempt)
|
|
167
|
+
|
|
168
|
+
to_email
|
|
169
|
+
the email address to send the raw_digits
|
|
170
|
+
|
|
171
|
+
raw_digits:
|
|
172
|
+
the raw (unencrypted) digits the user may use to verify & authenticate.
|
|
173
|
+
"""
|
|
174
|
+
subject = f"Verification Code | {raw_digits}"
|
|
175
|
+
message_text = WELCOME_1_TEXT.format(raw_digits)
|
|
176
|
+
message_html = WELCOME_1_HTML.format(subject, raw_digits)
|
|
177
|
+
send_pyramid_email(request, to_email, subject, message_text, message_html)
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def send_purchase_email(request, to_email, products, total_cost):
|
|
181
|
+
"""
|
|
182
|
+
Send purchase email to customer.
|
|
183
|
+
|
|
184
|
+
request
|
|
185
|
+
the request (of the successful log in attempt)
|
|
186
|
+
|
|
187
|
+
to_email
|
|
188
|
+
the email address to send the email to.
|
|
189
|
+
|
|
190
|
+
products
|
|
191
|
+
the list of products that the customer purchased.
|
|
192
|
+
|
|
193
|
+
total_cost
|
|
194
|
+
the total transaction price.
|
|
195
|
+
"""
|
|
196
|
+
subject = "Your purchase was successful!"
|
|
197
|
+
product_text_list = []
|
|
198
|
+
for p in products:
|
|
199
|
+
thumbnail = ""
|
|
200
|
+
if "thumbnail1" in p.extensions:
|
|
201
|
+
thumbnail = '<img src="{}/{}/thumbnail1?ts={}" style="border: 1px solid #ddd; border-radius: 4px; max-width: 184px; max-height: 184px; width: auto; height: auto;" />'.format(
|
|
202
|
+
request.app["bucket.secure_uploads.get_endpoint"],
|
|
203
|
+
p.s3_path,
|
|
204
|
+
p.updated_timestamp,
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
product_text_list.append(
|
|
208
|
+
f'<p><a href="{p.absolute_url(request)}">{p.title}<br/>{thumbnail}</a></p>'
|
|
209
|
+
)
|
|
210
|
+
product_text = "<br/>".join(product_text_list)
|
|
211
|
+
|
|
212
|
+
message_text = PURCHASE_1_TEXT.format(f"{total_cost:.2f}", request.host_url)
|
|
213
|
+
message_html = PURCHASE_1_HTML.format(
|
|
214
|
+
subject, request.host_url, product_text, f"{total_cost:.2f}"
|
|
215
|
+
)
|
|
216
|
+
send_pyramid_email(request, to_email, subject, message_text, message_html)
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def send_sale_email(request, shop, products, total_cost):
|
|
220
|
+
"""
|
|
221
|
+
Send an email to all shop owners regarding the sale.
|
|
222
|
+
|
|
223
|
+
request
|
|
224
|
+
the request (of the successful log in attempt)
|
|
225
|
+
|
|
226
|
+
shop
|
|
227
|
+
the shop that made the sale
|
|
228
|
+
|
|
229
|
+
products
|
|
230
|
+
the list of products that the customer purchased.
|
|
231
|
+
|
|
232
|
+
total_cost
|
|
233
|
+
the total transaction price.
|
|
234
|
+
"""
|
|
235
|
+
subject = "You made a sale!"
|
|
236
|
+
product_text_list = []
|
|
237
|
+
for p in products:
|
|
238
|
+
thumbnail = ""
|
|
239
|
+
if "thumbnail1" in p.extensions:
|
|
240
|
+
thumbnail = '<img src="{}/{}/thumbnail1?ts={}" style="border: 1px solid #ddd; border-radius: 4px; max-width: 184px; max-height: 184px; width: auto; height: auto;" />'.format(
|
|
241
|
+
request.app["bucket.secure_uploads.get_endpoint"],
|
|
242
|
+
p.s3_path,
|
|
243
|
+
p.updated_timestamp,
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
product_text_list.append(
|
|
247
|
+
f'<p><a href="{p.absolute_url(request)}">{p.title}<br/>{thumbnail}</a></p>'
|
|
248
|
+
)
|
|
249
|
+
product_text = "<br/>".join(product_text_list)
|
|
250
|
+
|
|
251
|
+
message_text = SALE_1_TEXT.format(
|
|
252
|
+
f"{total_cost:.2f}", shop.absolute_sales_url(request)
|
|
253
|
+
)
|
|
254
|
+
message_html = SALE_1_HTML.format(
|
|
255
|
+
subject, shop.absolute_sales_url(request), product_text, f"{total_cost:.2f}"
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
# Send a separate email for each shop owner.
|
|
259
|
+
for user in shop.users:
|
|
260
|
+
send_pyramid_email(request, user.email, subject, message_text, message_html)
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def send_invite_email(request, to_email, user, shop):
|
|
264
|
+
"""
|
|
265
|
+
Send an email to invite a user to join a shop.
|
|
266
|
+
|
|
267
|
+
request
|
|
268
|
+
the request (of the invitation)
|
|
269
|
+
|
|
270
|
+
to_email
|
|
271
|
+
the email address to send the shop invitation to.
|
|
272
|
+
|
|
273
|
+
user
|
|
274
|
+
the user who sent the invite.
|
|
275
|
+
|
|
276
|
+
shop
|
|
277
|
+
the shop the invitation is for.
|
|
278
|
+
"""
|
|
279
|
+
subject = f"You have been invited to {shop.name}"
|
|
280
|
+
join_link = request.route_url(
|
|
281
|
+
"join-or-log-in",
|
|
282
|
+
_query={"email": to_email},
|
|
283
|
+
)
|
|
284
|
+
message_text = INVITE_1_TEXT.format(user.email, shop.name, join_link)
|
|
285
|
+
message_html = INVITE_1_HTML.format(subject, user.email, shop.name, join_link)
|
|
286
|
+
send_pyramid_email(request, to_email, subject, message_text, message_html)
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
WELCOME_1_TEXT = """
|
|
2
|
+
Hey there!
|
|
3
|
+
|
|
4
|
+
\n{0}\n
|
|
5
|
+
|
|
6
|
+
Here is the verification code you requested.
|
|
7
|
+
Type code into the challenge input field.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
WELCOME_1_HTML = """
|
|
11
|
+
<!DOCTYPE html>
|
|
12
|
+
<html>
|
|
13
|
+
<head>
|
|
14
|
+
<title>{0}</title>
|
|
15
|
+
</head>
|
|
16
|
+
<body>
|
|
17
|
+
<h2>Hey there!</h2>
|
|
18
|
+
|
|
19
|
+
<p><b>{1}</b></p>
|
|
20
|
+
|
|
21
|
+
<p>
|
|
22
|
+
Here is the verification code you requested.
|
|
23
|
+
Type code into the challenge input field.
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+
</body>
|
|
27
|
+
</html>
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
PURCHASE_1_TEXT = """
|
|
31
|
+
You made a purchase!
|
|
32
|
+
|
|
33
|
+
{0}
|
|
34
|
+
|
|
35
|
+
You may paste this link into your browser to view and download your purchases:
|
|
36
|
+
|
|
37
|
+
\n{1}\n
|
|
38
|
+
|
|
39
|
+
Thank you very much!
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
# 0: subject,
|
|
43
|
+
# 1: request.host_url,
|
|
44
|
+
# 2: product_text,
|
|
45
|
+
# 3: total_cost,
|
|
46
|
+
|
|
47
|
+
PURCHASE_1_HTML = """
|
|
48
|
+
<!DOCTYPE html>
|
|
49
|
+
<html>
|
|
50
|
+
<head>
|
|
51
|
+
<title>{0}</title>
|
|
52
|
+
|
|
53
|
+
</head>
|
|
54
|
+
<body>
|
|
55
|
+
<h2>
|
|
56
|
+
You made a purchase!
|
|
57
|
+
</h2>
|
|
58
|
+
|
|
59
|
+
{2}
|
|
60
|
+
|
|
61
|
+
<b>${3}</b>
|
|
62
|
+
|
|
63
|
+
<p>
|
|
64
|
+
You may <a href="{1}/u/purchases" style="font-weight: bold;" target="_blank">download your purchases</a> at any time.
|
|
65
|
+
</p>
|
|
66
|
+
|
|
67
|
+
<p>
|
|
68
|
+
</p>
|
|
69
|
+
|
|
70
|
+
<p style="font-size: .8em;">
|
|
71
|
+
<span style="color: #aaaaaa;">
|
|
72
|
+
You may paste this link into your browser to view or download your purchases:
|
|
73
|
+
</span>
|
|
74
|
+
<br>
|
|
75
|
+
<br>
|
|
76
|
+
<a href="{1}/u/purchases" style="color: #439fe0; font-weight: normal; text-decoration: none; word-break: break-word;" target="_blank">
|
|
77
|
+
{1}/u/purchases
|
|
78
|
+
</a>
|
|
79
|
+
</p>
|
|
80
|
+
|
|
81
|
+
<p>
|
|
82
|
+
Thank you very much!
|
|
83
|
+
</p>
|
|
84
|
+
|
|
85
|
+
</body>
|
|
86
|
+
</html>
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
SALE_1_TEXT = """
|
|
90
|
+
You made a sale!
|
|
91
|
+
|
|
92
|
+
{0}
|
|
93
|
+
|
|
94
|
+
You may paste this link into your browser to view your sales:
|
|
95
|
+
|
|
96
|
+
\n{1}\n
|
|
97
|
+
|
|
98
|
+
Great job!
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
# 0: subject,
|
|
102
|
+
# 1: shop.absolute_sales_url
|
|
103
|
+
# 2: product_text,
|
|
104
|
+
# 3: total_cost,
|
|
105
|
+
|
|
106
|
+
SALE_1_HTML = """
|
|
107
|
+
<!DOCTYPE html>
|
|
108
|
+
<html>
|
|
109
|
+
<head>
|
|
110
|
+
<title>{0}</title>
|
|
111
|
+
|
|
112
|
+
</head>
|
|
113
|
+
<body>
|
|
114
|
+
<h2>
|
|
115
|
+
You made a <u>sale</u>!
|
|
116
|
+
</h2>
|
|
117
|
+
|
|
118
|
+
<b>${3}</b>
|
|
119
|
+
|
|
120
|
+
{2}
|
|
121
|
+
|
|
122
|
+
<p>
|
|
123
|
+
You may view <a href="{1}" style="font-weight: bold;" target="_blank">all your sales</a> at any time.
|
|
124
|
+
</p>
|
|
125
|
+
|
|
126
|
+
<p style="font-size: .8em;">
|
|
127
|
+
<span style="color: #aaaaaa;">
|
|
128
|
+
You may paste this link into your browser to view your sales:
|
|
129
|
+
</span>
|
|
130
|
+
<br>
|
|
131
|
+
<br>
|
|
132
|
+
<a href="{1}" style="color: #439fe0; font-weight: normal; text-decoration: none; word-break: break-word;" target="_blank">
|
|
133
|
+
{1}
|
|
134
|
+
</a>
|
|
135
|
+
</p>
|
|
136
|
+
|
|
137
|
+
<p>
|
|
138
|
+
Great job!
|
|
139
|
+
</p>
|
|
140
|
+
|
|
141
|
+
</body>
|
|
142
|
+
</html>
|
|
143
|
+
"""
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
# 0: user.email
|
|
147
|
+
# 1: shop.name,
|
|
148
|
+
# 2: log in link.
|
|
149
|
+
INVITE_1_TEXT = """
|
|
150
|
+
Hey There!
|
|
151
|
+
|
|
152
|
+
{0} has invited you to join the {1} shop on Make Post Sell.
|
|
153
|
+
|
|
154
|
+
Click this link to log in.
|
|
155
|
+
|
|
156
|
+
{2}
|
|
157
|
+
|
|
158
|
+
Make Post Sell is a lightweight, open-source, public domain, software as a service ecommerce web application.
|
|
159
|
+
We hope you like our ethical approach to doing business online.
|
|
160
|
+
|
|
161
|
+
Thanks for sharing! <3
|
|
162
|
+
"""
|
|
163
|
+
|
|
164
|
+
# 0: subject,
|
|
165
|
+
# 1: user.email
|
|
166
|
+
# 2: shop.name,
|
|
167
|
+
# 3: log in link.
|
|
168
|
+
|
|
169
|
+
INVITE_1_HTML = """
|
|
170
|
+
<!DOCTYPE html>
|
|
171
|
+
<html>
|
|
172
|
+
<head>
|
|
173
|
+
<title>{0}</title>
|
|
174
|
+
|
|
175
|
+
</head>
|
|
176
|
+
<body>
|
|
177
|
+
|
|
178
|
+
<h2>Hey There!</h2>
|
|
179
|
+
|
|
180
|
+
<p>
|
|
181
|
+
{1} has invited you to join {2} on Make Post Sell.
|
|
182
|
+
</p>
|
|
183
|
+
|
|
184
|
+
<p>
|
|
185
|
+
<a href="{3}">click this link to log in to the shop.</a>
|
|
186
|
+
</p>
|
|
187
|
+
|
|
188
|
+
<p>
|
|
189
|
+
Make Post Sell is a lightweight, open-source, public domain, software as a service ecommerce web application.
|
|
190
|
+
We hope you like our ethical approach to doing business online.
|
|
191
|
+
</p>
|
|
192
|
+
|
|
193
|
+
<p>
|
|
194
|
+
Thanks for sharing! <3
|
|
195
|
+
</p>
|
|
196
|
+
|
|
197
|
+
</body>
|
|
198
|
+
</html>
|
|
199
|
+
|
|
200
|
+
"""
|