Skip to content

Commit

Permalink
all email letters have been refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-moroz committed Apr 10, 2018
1 parent a8ca542 commit 5fd4418
Show file tree
Hide file tree
Showing 12 changed files with 245 additions and 114 deletions.
1 change: 1 addition & 0 deletions babel.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[python: **.py]
[jinja2: **/templates/**.txt]
[jinja2: **/templates/**.html]
extensions=jinja2.ext.autoescape,jinja2.ext.with_
15 changes: 12 additions & 3 deletions forum/auth/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import render_template, redirect, request, url_for, flash
from flask import render_template, redirect, request, url_for, flash, current_app
from flask_babel import lazy_gettext, gettext
from flask_login import login_user, logout_user, login_required, current_user

Expand All @@ -14,8 +14,11 @@
def check_confirmed():
if current_user.is_authenticated:
current_user.ping()
if (not current_user.confirmed and request.endpoint and
request.endpoint[:5] != 'auth.' and request.endpoint != 'static'):
if (not current_user.confirmed and
request.endpoint and
request.endpoint[:5] != 'auth.' and
request.endpoint != 'main.set_locale' and
request.endpoint != 'static'):
return redirect(url_for('auth.unconfirmed'))


Expand Down Expand Up @@ -65,6 +68,12 @@ def register():
body=render_template('auth/email/confirm.txt', user=user, token=token),
html=render_template('auth/email/confirm.html', user=user, token=token)
)
send_email.delay(
recipients=[current_app.config['APP_ADMIN']],
subject='New user',
body=render_template('email/new_user.txt', user=user),
html=render_template('email/new_user.html', user=user)
)
flash(lazy_gettext('A confirmation email has been sent to you by email.'))
return redirect(url_for('auth.login'))
return render_template('auth/register.html', form=form)
Expand Down
1 change: 1 addition & 0 deletions forum/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ class PollVote(db.Model):
created_at = db.Column(db.DateTime, default=func.now())
deleted = db.Column(db.Boolean, index=True, default=False)


db.event.listen(Message.body, 'set', on_changed_body_set_body_html)
db.event.listen(Topic.body, 'set', on_changed_body_set_body_html)
db.event.listen(Comment.body, 'set', on_changed_body_set_body_html)
22 changes: 14 additions & 8 deletions forum/templates/auth/email/confirm.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<p>Dear {{ user.username }},</p>
<p>Welcome to <b>4RUM</b>!</p>
<p>To confirm your account please <a href="{{ url_for('auth.confirm', token=token, _external=True) }}">click here</a>.</p>
<p>Alternatively, you can paste the following link in your browser's address bar:</p>
<p>{{ url_for('auth.confirm', token=token, _external=True) }}</p>
<p>Sincerely,</p>
<p>The 4RUM Team</p>
<p><small>Note: replies to this email address are not monitored.</small></p>
{{ _('Dear') }} <b>{{ user.username }}</b>,
<p>
{{ _('Welcome to <b>4RUM</b>!') }}
<br>{{ _('To confirm your account please') }} <a href="{{ url_for('auth.confirm', token=token, _external=True) }}">{{ _('click here') }}</a>.
<br>{{ _('Alternatively, you can paste the following link in your browser\'s address bar:') }}
<br>{{ url_for('auth.confirm', token=token, _external=True) }}
</p>
<p>
{{ _('Sincerely') }},
<br>{{ _('The 4RUM Team') }}
</p>
<p>
<small>{{ _('Note: replies to this email address are not monitored.') }}</small>
</p>
15 changes: 6 additions & 9 deletions forum/templates/auth/email/confirm.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
Dear {{ user.username }},

Welcome to 4RUM!

To confirm your account please click on the following link:
{{ _('Dear') }} {{ user.username }},

{{ _('Welcome to 4RUM!') }}
{{ _('To confirm your account please click on the following link:') }}
{{ url_for('auth.confirm', token=token, _external=True) }}

Sincerely,

The 4RUM Team
{{ _('Sincerely') }},
{{ _('The 4RUM Team') }}

Note: replies to this email address are not monitored.
{{ _('Note: replies to this email address are not monitored.') }}
22 changes: 14 additions & 8 deletions forum/templates/auth/email/confirm_new_email.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<p>Dear {{ user.username }},</p>
<p>You have changed your email for <b>4RUM</b> account.</p>
<p>To confirm your new email please <a href="{{ url_for('auth.confirm_new_email', token=token, _external=True) }}">click here</a>.</p>
<p>Alternatively, you can paste the following link in your browser's address bar:</p>
<p>{{ url_for('auth.confirm_new_email', token=token, _external=True) }}</p>
<p>Sincerely,</p>
<p>The 4RUM Team</p>
<p><small>Note: replies to this email address are not monitored.</small></p>
{{ _('Dear') }} <b>{{ user.username }}</b>,
<p>
{{ _('You have changed your email for <b>4RUM</b> account.') }}
<br>{{ _('To confirm your new email please') }} <a href="{{ url_for('auth.confirm_new_email', token=token, _external=True) }}">{{ _('click here') }}</a>.
<br>{{ _('Alternatively, you can paste the following link in your browser\'s address bar:') }}
<br>{{ url_for('auth.confirm_new_email', token=token, _external=True) }}
</p>
<p>
{{ _('Sincerely') }},
<br>{{ _('The 4RUM Team') }}
</p>
<p>
<small>{{ _('Note: replies to this email address are not monitored.') }}</small>
</p>
15 changes: 6 additions & 9 deletions forum/templates/auth/email/confirm_new_email.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
Dear {{ user.username }},

You have changed your email for 4RUM account.

To confirm your new email please click on the following link:
{{ _('Dear') }} {{ user.username }},

{{ _('You have changed your email for 4RUM account.') }}
{{ _('To confirm your new email please click on the following link:') }}
{{ url_for('auth.confirm_new_email', token=token, _external=True) }}

Sincerely,

The 4RUM Team
{{ _('Sincerely') }},
{{ _('The 4RUM Team') }}

Note: replies to this email address are not monitored.
{{ _('Note: replies to this email address are not monitored.') }}
24 changes: 15 additions & 9 deletions forum/templates/auth/email/reset_password.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<p>Dear {{ user.username }},</p>
<p>You have requested password reset for <b>4RUM</b> account.</p>
<p>To reset your password please <a href="{{ url_for('auth.reset_password', token=token, _external=True) }}">click here</a>.</p>
<p>Alternatively, you can paste the following link in your browser's address bar:</p>
<p>{{ url_for('auth.reset_password', token=token, _external=True) }}</p>
<p>If you have not requested a password reset simply ignore this message.</p>
<p>Sincerely,</p>
<p>The 4RUM Team</p>
<p><small>Note: replies to this email address are not monitored.</small></p>
{{ _('Dear') }} <b>{{ user.username }}</b>,
<p>
{{ _('You have requested password reset for <b>4RUM</b> account.') }}
<br>{{ _('To reset your password please') }} <a href="{{ url_for('auth.reset_password', token=token, _external=True) }}">{{ _('click here') }}</a>.
<br>{{ _('Alternatively, you can paste the following link in your browser\'s address bar:') }}
<br>{{ url_for('auth.reset_password', token=token, _external=True) }}
<br>{{ _('If you have not requested a password reset simply ignore this message.') }}
</p>
<p>
{{ _('Sincerely') }},
<br>{{ _('The 4RUM Team') }}
</p>
<p>
<small>{{ _('Note: replies to this email address are not monitored.') }}</small>
</p>
18 changes: 7 additions & 11 deletions forum/templates/auth/email/reset_password.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
Dear {{ user.username }},

You have requested password reset for 4RUM account.

To reset your password please click on the following link:
{{ _('Dear') }} {{ user.username }},

{{ _('You have requested password reset for 4RUM account.') }}
{{ _('To reset your password please click on the following link:') }}
{{ url_for('auth.reset_password', token=token, _external=True) }}
{{ _('If you have not requested a password reset simply ignore this message.') }}

If you have not requested a password reset simply ignore this message.

Sincerely,

The 4RUM Team
{{ _('Sincerely') }},
{{ _('The 4RUM Team') }}

Note: replies to this email address are not monitored.
{{ _('Note: replies to this email address are not monitored.') }}
7 changes: 6 additions & 1 deletion forum/templates/email/new_user.html
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
User <b>{{ user.username }}</b> has joined.
New user has joined.
<p>
Username: {{ user.username }}
<br>Email: {{ user.email }}
<br>Profile: {{ url_for('main.user', username=user.username, _external=True) }}
</p>
6 changes: 5 additions & 1 deletion forum/templates/email/new_user.txt
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
User {{ user.username }} has joined.
New user has joined.

Username: {{ user.username }}
Email: {{ user.email }}
Profile: {{ url_for('main.user', username=user.username, _external=True) }}
Loading

0 comments on commit 5fd4418

Please sign in to comment.