Skip to content

Commit 31af5ba

Browse files
authored
Merge pull request #18 from tiphub-io/email
Tip success and error emails
2 parents bfeb078 + bb67d87 commit 31af5ba

File tree

14 files changed

+496
-29
lines changed

14 files changed

+496
-29
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ GITHUB_CLIENT_SECRET="abc..."
2020

2121
GITLAB_CLIENT_ID="123..."
2222
GITLAB_CLIENT_SECRET="abc..."
23+
24+
# SendGrid Credentials. Optional, emails won't send without them.
25+
SENDGRID_API_KEY="123..."

backend/boltathon/models/tip.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import datetime
22
from boltathon.extensions import ma, db
3-
from boltathon.util import gen_random_id
3+
from boltathon.util import gen_random_id, frontend_url
4+
from boltathon.util.mail import send_email
45

56
class Tip(db.Model):
67
__tablename__ = 'tip'
@@ -31,6 +32,16 @@ def __init__(
3132
self.payment_request = payment_request
3233
self.rhash = rhash
3334
self.date_created = datetime.now()
35+
36+
def confirm(self, amount):
37+
self.amount = amount
38+
db.session.add(self)
39+
db.session.flush()
40+
send_email(self.recipient, 'tip_received', {
41+
'tip': self,
42+
'tips_url': frontend_url('/user/me')
43+
})
44+
3445

3546
class TipSchema(ma.Schema):
3647
class Meta:

backend/boltathon/settings.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,13 @@
1616
GITHUB_CLIENT_SECRET = os.getenv('GITHUB_CLIENT_SECRET')
1717
GITLAB_CLIENT_ID = os.getenv('GITLAB_CLIENT_ID')
1818
GITLAB_CLIENT_SECRET = os.getenv('GITLAB_CLIENT_SECRET')
19+
20+
SENDGRID_API_KEY = os.getenv('SENDGRID_API_KEY')
21+
SENDGRID_DEFAULT_FROM = '[email protected]'
22+
SENDGRID_DEFAULT_FROMNAME = 'TipHub'
23+
24+
UI = {
25+
'NAME': 'TipHub',
26+
'PRIMARY': '#E85420',
27+
'SECONDARY': '#333333'
28+
}
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
<!-- THIS EMAIL WAS BUILT AND TESTED WITH LITMUS http://litmus.com -->
2+
<!-- IT WAS RELEASED UNDER THE MIT LICENSE https://opensource.org/licenses/MIT -->
3+
<!-- QUESTIONS? TWEET US @LITMUSAPP -->
4+
<!DOCTYPE html>
5+
<html>
6+
<head>
7+
<title></title>
8+
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
9+
<meta content="width=device-width, initial-scale=1" name="viewport">
10+
<meta content="IE=edge" http-equiv="X-UA-Compatible"/>
11+
<style type="text/css">
12+
/* FONTS */
13+
@import url('https://fonts.googleapis.com/css?family=Nunito+Sans');
14+
15+
/* CLIENT-SPECIFIC STYLES */
16+
body, table, td, a {
17+
-webkit-text-size-adjust: 100%;
18+
-ms-text-size-adjust: 100%;
19+
}
20+
21+
table, td {
22+
mso-table-lspace: 0pt;
23+
mso-table-rspace: 0pt;
24+
}
25+
26+
img {
27+
-ms-interpolation-mode: bicubic;
28+
}
29+
30+
/* RESET STYLES */
31+
img {
32+
border: 0;
33+
height: auto;
34+
line-height: 100%;
35+
outline: none;
36+
text-decoration: none;
37+
}
38+
39+
table {
40+
border-collapse: collapse !important;
41+
}
42+
43+
body {
44+
height: 100% !important;
45+
margin: 0 !important;
46+
padding: 0 !important;
47+
width: 100% !important;
48+
}
49+
50+
/* iOS BLUE LINKS */
51+
a[x-apple-data-detectors] {
52+
color: inherit !important;
53+
text-decoration: none !important;
54+
font-size: inherit !important;
55+
font-family: inherit !important;
56+
font-weight: inherit !important;
57+
line-height: inherit !important;
58+
}
59+
60+
/* MOBILE STYLES */
61+
@media screen and (max-width: 600px) {
62+
h1 {
63+
font-size: 32px !important;
64+
line-height: 32px !important;
65+
}
66+
}
67+
68+
/* ANDROID CENTER FIX */
69+
div[style*="margin: 16px 0;"] {
70+
margin: 0 !important;
71+
}
72+
</style>
73+
</head>
74+
<body style="background-color: #f4f4f4; margin: 0 !important; padding: 0 !important;">
75+
76+
<!-- HIDDEN PREHEADER TEXT -->
77+
<div style="display: none; font-size: 1px; color: #fefefe; line-height: 1px; font-family: 'Nunito Sans', Helvetica, Arial, sans-serif; max-height: 0px; max-width: 0px; opacity: 0; overflow: hidden;">
78+
{{ args.preview }}
79+
</div>
80+
81+
<table border="0" cellpadding="0" cellspacing="0" width="100%">
82+
<!-- LOGO -->
83+
<tr>
84+
<td align="center" bgcolor="{{ UI.SECONDARY }}">
85+
<!--[if (gte mso 9)|(IE)]>
86+
<table align="center" border="0" cellspacing="0" cellpadding="0" width="600">
87+
<tr>
88+
<td align="center" valign="top" width="600">
89+
<![endif]-->
90+
<table border="0" cellpadding="0" cellspacing="0" style="max-width: 600px;" width="100%">
91+
<tr>
92+
<td align="center" style="padding: 40px 10px 40px 10px;" valign="top">
93+
<a href="{{ args.home_url }}" target="_blank">
94+
<img alt="{{ UI.NAME }} logo" border="0" height="44" src="https://i.imgur.com/4OEWT4f.png"
95+
style="display: block; width: 220px; max-width: 220px; min-width: 220px; font-family: 'Nunito Sans', Helvetica, Arial, sans-serif; color: #ffffff; font-size: 18px;"
96+
width="220">
97+
</a>
98+
</td>
99+
</tr>
100+
</table>
101+
<!--[if (gte mso 9)|(IE)]>
102+
</td>
103+
</tr>
104+
</table>
105+
<![endif]-->
106+
</td>
107+
</tr>
108+
<!-- TITLE -->
109+
<tr>
110+
<td align="center" bgcolor="{{ UI.SECONDARY }}" style="padding: 0px 10px 0px 10px;">
111+
<!--[if (gte mso 9)|(IE)]>
112+
<table align="center" border="0" cellspacing="0" cellpadding="0" width="600">
113+
<tr>
114+
<td align="center" valign="top" width="600">
115+
<![endif]-->
116+
<table border="0" cellpadding="0" cellspacing="0" style="max-width: 600px;" width="100%">
117+
<tr>
118+
<td align="center" bgcolor="#ffffff" style="padding: 40px 20px 20px 20px; border-radius: 4px 4px 0px 0px; color: #221F1F; font-family: 'Nunito Sans', Helvetica, Arial, sans-serif; font-size: 48px; font-weight: 400; letter-spacing: 2px; line-height: 48px;"
119+
valign="top">
120+
<h1 style="font-size: 42px; font-weight: 400; margin: 0;">
121+
{{ args.title }}
122+
</h1>
123+
</td>
124+
</tr>
125+
</table>
126+
<!--[if (gte mso 9)|(IE)]>
127+
</td>
128+
</tr>
129+
</table>
130+
<![endif]-->
131+
</td>
132+
</tr>
133+
<!-- BODY -->
134+
<tr>
135+
<td align="center" bgcolor="#f4f4f4" style="padding: 0px 10px 0px 10px;">
136+
<!--[if (gte mso 9)|(IE)]>
137+
<table align="center" border="0" cellspacing="0" cellpadding="0" width="600">
138+
<tr>
139+
<td align="center" valign="top" width="600">
140+
<![endif]-->
141+
<table border="0" cellpadding="0" cellspacing="0" style="max-width: 600px;" width="100%">
142+
<tr>
143+
<td bgcolor="#ffffff"
144+
style="padding: 20px 30px 40px 30px; color: #666666; font-family: 'Nunito Sans', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px; border-radius: 0px 0px 4px 4px;">
145+
{{ args.body }}
146+
</td>
147+
</tr>
148+
</table>
149+
<!--[if (gte mso 9)|(IE)]>
150+
</td>
151+
</tr>
152+
</table>
153+
<![endif]-->
154+
</td>
155+
</tr>
156+
<!-- FOOTER -->
157+
<tr>
158+
<td align="center" bgcolor="#f4f4f4" style="padding: 0px 10px 0px 10px;">
159+
<!--[if (gte mso 9)|(IE)]>
160+
<table align="center" border="0" cellspacing="0" cellpadding="0" width="600">
161+
<tr>
162+
<td align="center" valign="top" width="600">
163+
<![endif]-->
164+
<table border="0" cellpadding="0" cellspacing="0" style="max-width: 600px;" width="100%">
165+
<!-- NAVIGATION -->
166+
<tr>
167+
<td align="center" bgcolor="#f4f4f4"
168+
style="padding: 30px 30px 30px 30px; color: #666666; font-family: 'Nunito Sans', Helvetica, Arial, sans-serif; font-size: 14px; font-weight: 400; line-height: 18px;">
169+
<p style="margin: 0;">
170+
<a href="{{ args.home_url }}" style="color: #221F1F; font-weight: 700;" target="_blank">
171+
{{ UI.NAME }}
172+
</a>
173+
-
174+
<a href="{{ args.account_url }}" style="color: #221F1F; font-weight: 700;" target="_blank">
175+
Your Account
176+
</a>
177+
</p>
178+
</td>
179+
</tr>
180+
<!-- UNSUBSCRIBE -->
181+
<tr>
182+
<td align="center" bgcolor="#f4f4f4"
183+
style="padding: 0px 30px 30px 30px; color: #666666; font-family: 'Nunito Sans', Helvetica, Arial, sans-serif; font-size: 14px; font-weight: 400; line-height: 18px;">
184+
<p style="margin: 0;">
185+
Don’t want any more emails? Remove your email from
186+
<a href="{{ args.unsubscribe_url }}" style="color: #221F1F; font-weight: 700;"
187+
target="_blank">
188+
your settings here
189+
</a>
190+
.
191+
</p>
192+
</td>
193+
</tr>
194+
</table>
195+
<!--[if (gte mso 9)|(IE)]>
196+
</td>
197+
</tr>
198+
</table>
199+
<![endif]-->
200+
</td>
201+
</tr>
202+
</table>
203+
204+
</body>
205+
</html>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{{ args.body }}
2+
3+
===============
4+
5+
Sent from TipHub.io
6+
7+
Don't want any more emails? Just remove your email from settings: {{ args.unsubscribe_url }}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<p style="margin: 0 0 20px;">
2+
We tried to generate an invoice for someone to tip you, but were unable to
3+
contact your node. We got back the following error:
4+
</p>
5+
6+
<p style="margin: 10px 0; padding: 20px; background: #fff8f8; border: 1px solid #dea9a9; color: #862727;">
7+
“{{ args.error }}”
8+
</p>
9+
10+
<p style="margin: 0 0 20px;">
11+
You can update your node's connection settings below. If you need help
12+
fixing the problem, don't hesitate to post in our
13+
<a href="{{ args.support_url }}" style="color: {{ UI.PRIMARY }};">GitHub issue queue</a>.
14+
</p>
15+
16+
<table width="100%" border="0" cellspacing="0" cellpadding="0">
17+
<tr>
18+
<td bgcolor="#ffffff" align="center" style="padding: 20px 30px 0 30px;">
19+
<table border="0" cellspacing="0" cellpadding="0">
20+
<tr>
21+
<td align="center" style="border-radius: 3px;" bgcolor="{{ UI.PRIMARY }}">
22+
<a href="{{ args.config_url }}" target="_blank"
23+
style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; color: #ffffff; text-decoration: none; padding: 20px 50px; border-radius: 4px; border: 1px solid {{ UI.PRIMARY }}; display: inline-block;">
24+
Change Node Config
25+
</a>
26+
</td>
27+
</tr>
28+
</table>
29+
</td>
30+
</tr>
31+
</table>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
We tried to generate an invoice for someone to tip you, but were unable to
2+
contact your node. We got back the following error:
3+
4+
> {{ args.error }}
5+
6+
You can update your node's connection settings here: {{ args.config_url }}
7+
8+
If you need help fixing the problem, don't hesitate to post in our GitHub issue queue: {{ args.support_url }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<p style="margin: 0 0 20px;">
2+
You just received a tip from
3+
<strong>{{args.tip.sender or 'an anonymous user'}}</strong>
4+
for
5+
<strong>{{ args.tip.amount }} sats</strong>!
6+
{% if args.tip.message %}
7+
They also added the following message:
8+
{% endif %}
9+
</p>
10+
11+
{% if args.tip.message %}
12+
<p style="margin: 10px 0; padding: 20px; background: #F8F8F8;">
13+
“{{ args.tip.message }}”
14+
</p>
15+
{% endif %}
16+
17+
<table width="100%" border="0" cellspacing="0" cellpadding="0">
18+
<tr>
19+
<td bgcolor="#ffffff" align="center" style="padding: 20px 30px 0 30px;">
20+
<table border="0" cellspacing="0" cellpadding="0">
21+
<tr>
22+
<td align="center" style="border-radius: 3px;" bgcolor="{{ UI.PRIMARY }}">
23+
<a href="{{ args.tips_url }}" target="_blank"
24+
style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; color: #ffffff; text-decoration: none; padding: 20px 50px; border-radius: 4px; border: 1px solid {{ UI.PRIMARY }}; display: inline-block;">
25+
View your Tips
26+
</a>
27+
</td>
28+
</tr>
29+
</table>
30+
</td>
31+
</tr>
32+
</table>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
You just received a tip from {{ args.tip.sender or 'an anonymous user' }} for {{ args.tip.amount }} satoshis.
2+
{% if args.tip.message %}
3+
They also added the following message:
4+
5+
> {{ args.tip.message }}
6+
{% endif %}
7+
8+
You can view all of your tips at {{ args.tips_url }}

0 commit comments

Comments
 (0)