Changeset b8ef4ab in OpenWorkouts-current


Ignore:
Timestamp:
Feb 19, 2019, 6:58:39 PM (5 years ago)
Author:
Borja Lopez <borja@…>
Branches:
current, feature/docs, master
Children:
42d775c
Parents:
07f5190
Message:

(#61) Better templates for "verify your account" emails:

  • Send a multipart text/html email (instead text only)
  • Added some styling to the html version of the email, based on our current login page styles.

Important: as the html version contains html code generated using
request.resource_url() and request.static_url(), when running in
development mode under http://localhost, the links to images
and css files in the rendered email point to localhost, so they
won't work outside the machine running openworkouts.

Location:
ow
Files:
2 added
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • ow/mail.py

    r07f5190 rb8ef4ab  
    3939def send_verification_email(request, user):
    4040    subject = _('Welcome to OpenWorkouts')
    41     template = 'ow:templates/mail_verify_account.pt'
     41    txt_template = 'ow:templates/mail_verify_account_txt.pt'
     42    html_template = 'ow:templates/mail_verify_account_html.pt'
    4243    verify_link = request.resource_url(user, 'verify', user.verification_token)
    4344    context = {'user': user, 'verify_link': verify_link}
    4445    mailer = get_mailer(request)
    45     body = render(template, context, request)
    46     message = Message(subject=subject, recipients=[user.email], body=body)
     46    txt_body = render(txt_template, context, request)
     47    html_body = render(html_template, context, request)
     48    message = Message(
     49        subject=subject,
     50        recipients=[user.email],
     51        body=txt_body,
     52        html=html_body
     53    )
    4754    message = idna_encode_recipients(message)
    4855    mailer.send_to_queue(message)
  • ow/static/css/main.css

    r07f5190 rb8ef4ab  
    14861486  font-size: 0.8125rem;
    14871487}
     1488.verify-account-content {
     1489  background-position: center;
     1490  background-size: cover;
     1491  display: flex;
     1492  justify-content: center;
     1493  align-items: center;
     1494  min-height: calc(100vh - 98px);
     1495  padding: 1em 0;
     1496  color: #e1e1e1;
     1497}
     1498.verify-account-content .info {
     1499  max-width: 580px;
     1500  background-color: rgba(21, 21, 21, 0.6);
     1501  border-radius: 6px;
     1502  padding: 2em 1.5em;
     1503}
     1504.verify-account-content .info div {
     1505  margin-bottom: 1.5em;
     1506}
     1507.verify-account-content a {
     1508  color: #e1e1e1;
     1509  font-size: 13px;
     1510  text-decoration: none;
     1511  margin-right: 0.75em;
     1512}
     1513.verify-account-content a:hover {
     1514  color: white;
     1515}
     1516.verify-account-content .button {
     1517  transition: all 500ms ease-in-out;
     1518  background-color: #EE4056;
     1519  color: white;
     1520  text-transform: uppercase;
     1521}
     1522.verify-account-content .button:hover {
     1523  background-color: #e6152f;
     1524}
  • ow/static/less/main.less

    r07f5190 rb8ef4ab  
    3232@import "pages/login.less";
    3333@import "pages/profile.less";
     34@import "pages/verify_account.less";
  • ow/tests/test_mail.py

    r07f5190 rb8ef4ab  
    4141        message.recipients = ['user@example.net']
    4242        m.return_value = message
    43         body = Mock()
    44         r.return_value = body
     43
     44        txt_body = Mock()
     45        html_body = Mock()
     46        r.side_effect = [txt_body, html_body]
     47
    4548        request = DummyRequest()
    4649        request.root = root
     
    4952        verify_link = request.resource_url(
    5053            user, 'verify', user.verification_token)
    51         r.assert_called_once_with(
    52             'ow:templates/mail_verify_account.pt',
    53             {'user': user, 'verify_link': verify_link},
    54             request
    55         )
     54
     55        # two render calls
     56        assert r.call_count == 2
     57
     58        # first call renders the text version of the email
     59        assert r.call_args_list[0][0][0] == (
     60            'ow:templates/mail_verify_account_txt.pt')
     61        assert r.call_args_list[0][0][1] == (
     62            {'user': user, 'verify_link': verify_link})
     63        assert r.call_args_list[0][0][2] == request
     64
     65        # second call renders the html version of the email
     66        assert r.call_args_list[1][0][0] == (
     67            'ow:templates/mail_verify_account_html.pt')
     68        assert r.call_args_list[1][0][1] == (
     69            {'user': user, 'verify_link': verify_link})
     70        assert r.call_args_list[1][0][2] == request
     71
    5672        m.assert_called_once
    5773        m.call_args_list[0][1]['recipients'] == user.email
    58         m.call_args_list[0][1]['body'] == body
     74        m.call_args_list[0][1]['body'] == txt_body
     75        m.call_args_list[0][1]['html'] == html_body
    5976        mailer.send_to_queue.assert_called_once_with(message)
Note: See TracChangeset for help on using the changeset viewer.