Merge branch 'boxer'
This commit is contained in:
commit
1f9479a230
2 changed files with 61 additions and 6 deletions
|
@ -4,6 +4,12 @@
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
<title>{{ subject }}</title>
|
<title>{{ subject }}</title>
|
||||||
|
|
||||||
|
{% if action_metadata %}
|
||||||
|
<script type="application/ld+json">
|
||||||
|
{{ action_metadata }}
|
||||||
|
</script>
|
||||||
|
{% endif %}
|
||||||
</head>
|
</head>
|
||||||
<body bgcolor="#FFFFFF" style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: none; width: 100% !important; height: 100%; margin: 0; padding: 0;"><style type="text/css">
|
<body bgcolor="#FFFFFF" style="font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: none; width: 100% !important; height: 100%; margin: 0; padding: 0;"><style type="text/css">
|
||||||
@media only screen and (max-width: 600px) {
|
@media only screen and (max-width: 600px) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import logging
|
import logging
|
||||||
import traceback
|
import traceback
|
||||||
|
import json
|
||||||
|
|
||||||
from flask.ext.mail import Message
|
from flask.ext.mail import Message
|
||||||
|
|
||||||
|
@ -13,7 +14,42 @@ template_env = get_template_env("emails")
|
||||||
class CannotSendEmailException(Exception):
|
class CannotSendEmailException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def send_email(recipient, subject, template_file, parameters):
|
class GmailAction(object):
|
||||||
|
""" Represents an action that can be taken in Gmail in response to the email. """
|
||||||
|
def __init__(self, metadata):
|
||||||
|
self.metadata = metadata
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def confirm(name, url, description):
|
||||||
|
return GmailAction({
|
||||||
|
"@context": "http://schema.org",
|
||||||
|
"@type": "EmailMessage",
|
||||||
|
"action": {
|
||||||
|
"@type": 'ConfirmAction',
|
||||||
|
"name": name,
|
||||||
|
"handler": {
|
||||||
|
"@type": "HttpActionHandler",
|
||||||
|
"url": get_app_url() + '/' + url
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"description": description
|
||||||
|
})
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def view(name, url, description):
|
||||||
|
return GmailAction({
|
||||||
|
"@context": "http://schema.org",
|
||||||
|
"@type": "EmailMessage",
|
||||||
|
"action": {
|
||||||
|
"@type": 'ViewAction',
|
||||||
|
"name": name,
|
||||||
|
"url": get_app_url() + '/' + url
|
||||||
|
},
|
||||||
|
"description": description
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def send_email(recipient, subject, template_file, parameters, action=None):
|
||||||
app_title = app.config['REGISTRY_TITLE_SHORT']
|
app_title = app.config['REGISTRY_TITLE_SHORT']
|
||||||
app_url = get_app_url()
|
app_url = get_app_url()
|
||||||
|
|
||||||
|
@ -29,7 +65,8 @@ def send_email(recipient, subject, template_file, parameters):
|
||||||
'app_logo': 'https://quay.io/static/img/quay-logo.png', # TODO: make this pull from config
|
'app_logo': 'https://quay.io/static/img/quay-logo.png', # TODO: make this pull from config
|
||||||
'app_url': app_url,
|
'app_url': app_url,
|
||||||
'app_title': app_title,
|
'app_title': app_title,
|
||||||
'app_link': app_link_handler
|
'app_link': app_link_handler,
|
||||||
|
'action_metadata': json.dumps(action.metadata) if action else None
|
||||||
})
|
})
|
||||||
|
|
||||||
rendered_html = template_env.get_template(template_file + '.html').render(parameters)
|
rendered_html = template_env.get_template(template_file + '.html').render(parameters)
|
||||||
|
@ -61,25 +98,34 @@ def send_change_email(username, email, token):
|
||||||
})
|
})
|
||||||
|
|
||||||
def send_confirmation_email(username, email, token):
|
def send_confirmation_email(username, email, token):
|
||||||
|
action = GmailAction.confirm('Confirm E-mail', 'confirm?code=' + token,
|
||||||
|
'Verification of e-mail address')
|
||||||
|
|
||||||
send_email(email, 'Please confirm your e-mail address', 'confirmemail', {
|
send_email(email, 'Please confirm your e-mail address', 'confirmemail', {
|
||||||
'username': username,
|
'username': username,
|
||||||
'token': token
|
'token': token
|
||||||
})
|
}, action=action)
|
||||||
|
|
||||||
def send_repo_authorization_email(namespace, repository, email, token):
|
def send_repo_authorization_email(namespace, repository, email, token):
|
||||||
|
action = GmailAction.confirm('Verify E-mail', 'authrepoemail?code=' + token,
|
||||||
|
'Verification of e-mail address')
|
||||||
|
|
||||||
subject = 'Please verify your e-mail address for repository %s/%s' % (namespace, repository)
|
subject = 'Please verify your e-mail address for repository %s/%s' % (namespace, repository)
|
||||||
send_email(email, subject, 'repoauthorizeemail', {
|
send_email(email, subject, 'repoauthorizeemail', {
|
||||||
'namespace': namespace,
|
'namespace': namespace,
|
||||||
'repository': repository,
|
'repository': repository,
|
||||||
'token': token
|
'token': token
|
||||||
})
|
}, action=action)
|
||||||
|
|
||||||
def send_recovery_email(email, token):
|
def send_recovery_email(email, token):
|
||||||
|
action = GmailAction.view('Recover Account', 'recovery?code=' + token,
|
||||||
|
'Recovery of an account')
|
||||||
|
|
||||||
subject = 'Account recovery'
|
subject = 'Account recovery'
|
||||||
send_email(email, subject, 'recovery', {
|
send_email(email, subject, 'recovery', {
|
||||||
'email': email,
|
'email': email,
|
||||||
'token': token
|
'token': token
|
||||||
})
|
}, action=action)
|
||||||
|
|
||||||
def send_payment_failed(email, username):
|
def send_payment_failed(email, username):
|
||||||
send_email(email, 'Subscription Payment Failure', 'paymentfailure', {
|
send_email(email, 'Subscription Payment Failure', 'paymentfailure', {
|
||||||
|
@ -87,12 +133,15 @@ def send_payment_failed(email, username):
|
||||||
})
|
})
|
||||||
|
|
||||||
def send_org_invite_email(member_name, member_email, orgname, team, adder, code):
|
def send_org_invite_email(member_name, member_email, orgname, team, adder, code):
|
||||||
|
action = GmailAction.view('Join %s' % team, 'confirminvite?code=' + code,
|
||||||
|
'Invitation to join a team')
|
||||||
|
|
||||||
send_email(member_email, 'Invitation to join team', 'teaminvite', {
|
send_email(member_email, 'Invitation to join team', 'teaminvite', {
|
||||||
'inviter': adder,
|
'inviter': adder,
|
||||||
'token': code,
|
'token': code,
|
||||||
'organization': orgname,
|
'organization': orgname,
|
||||||
'teamname': team
|
'teamname': team
|
||||||
})
|
}, action=action)
|
||||||
|
|
||||||
|
|
||||||
def send_invoice_email(email, contents):
|
def send_invoice_email(email, contents):
|
||||||
|
|
Reference in a new issue