-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement user email change functionality; #1996
- Loading branch information
1 parent
98c7557
commit b2d07ad
Showing
14 changed files
with
279 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import re | ||
|
||
from django.conf import settings | ||
from django.core.mail import EmailMultiAlternatives | ||
from django.template import loader | ||
|
||
|
||
bad_mail_regex = list(map(re.compile, settings.BAD_MAIL_PROVIDER_REGEX)) | ||
|
||
|
||
def is_email_address_bad(email): | ||
if '@' in email: | ||
domain = email.split('@')[-1].lower() | ||
return domain in settings.BAD_MAIL_PROVIDERS or any(regex.match(domain) for regex in bad_mail_regex) | ||
return False | ||
|
||
|
||
def send_mail( | ||
subject_template_name, | ||
email_template_name, | ||
context, | ||
from_email, | ||
to_email, | ||
html_email_template_name, | ||
): | ||
subject = loader.render_to_string(subject_template_name, context) | ||
# Email subject *must not* contain newlines | ||
subject = ''.join(subject.splitlines()) | ||
body = loader.render_to_string(email_template_name, context) | ||
|
||
email_message = EmailMultiAlternatives(subject, body, from_email, [to_email]) | ||
if html_email_template_name is not None: | ||
html_email = loader.render_to_string(html_email_template_name, context) | ||
email_message.attach_alternative(html_email, 'text/html') | ||
|
||
email_message.send() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block media %} | ||
<style> | ||
.errorlist { | ||
list-style-type: none; | ||
margin-block-start: 0; | ||
margin-block-end: 0.5em; | ||
padding: 0; | ||
} | ||
</style> | ||
{% endblock %} | ||
|
||
{% block body %} | ||
<div class="centered-form" style="text-align: center"> | ||
<form action="" method="post" class="form-area"> | ||
{% csrf_token %} | ||
<table border="0" class="django-as-table">{{ form.as_table() }}</table> | ||
<hr> | ||
<button class="submit-bar" type="submit">{{ _('Request email change') }}</button> | ||
</form> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<div style="border:2px solid #fd0;margin:4px 0;"><div style="background:#000;border:6px solid #000;"> | ||
<a href="{{ protocol }}://{{ domain }}"><img src="{{ protocol }}://{{ domain }}/static/icons/logo.svg" alt="{{ site_name }}" width="160" height="44"></a> | ||
</div></div> | ||
|
||
<div style="border:2px solid #337ab7;margin:4px 0;"><div style="background:#fafafa;border:12px solid #fafafa;font-family:segoe ui,lucida grande,Arial,sans-serif;font-size:14px;"> | ||
<br><br> | ||
{{ user.get_username() }}, | ||
<br> | ||
{% trans %}You have requested to change your email address to this email for your user account at {{ site_name }}.{% endtrans %} | ||
<br><br> | ||
{% trans trimmed count=expiry_minutes %} | ||
Please click the link to confirm this email change. The link will expire in {{ count }} minute. | ||
{% pluralize %} | ||
Please click the link to confirm this email change. The link will expire in {{ count }} minutes. | ||
{% endtrans %} | ||
<br> | ||
<a href="{{ protocol }}://{{ domain }}{{ url('email_change_activate', activation_key=activation_key) }}">{{ protocol }}://{{ domain }}{{ url('email_change_activate', activation_key=activation_key) }}</a> | ||
<br><br> | ||
{% if site_admin_email %} | ||
{% with link='<a href="mailto:%(email)s">%(email)s</a>'|safe|format(email=site_admin_email) %} | ||
{{ _('If you have encounter any problems, feel free to shoot us an email at %(email)s.', email=link) }} | ||
{% endwith %} | ||
{% endif %} | ||
</div></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{{ user.get_username() }}, | ||
|
||
{% trans %}You have requested to change your email address to this email for your user account at {{ site_name }}.{% endtrans %} | ||
|
||
{% trans trimmed count=expiry_minutes %} | ||
Please go to this page to confirm this email change. The link will expire in {{ count }} minute. | ||
{% pluralize %} | ||
Please go to this page to confirm this email change. The link will expire in {{ count }} minutes. | ||
{% endtrans %} | ||
|
||
{{ protocol }}://{{ domain }}{{ url('email_change_activate', activation_key=activation_key) }} | ||
|
||
{% if site_admin_email %} | ||
{{ _('If you have encounter any problems, feel free to shoot us an email at %(email)s.', email=site_admin_email) }} | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% trans %}Email change request on {{ site_name }}{% endtrans %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<div style="border:2px solid #fd0;margin:4px 0;"><div style="background:#000;border:6px solid #000;"> | ||
<a href="{{ protocol }}://{{ domain }}"><img src="{{ protocol }}://{{ domain }}/static/icons/logo.svg" alt="{{ site_name }}" width="160" height="44"></a> | ||
</div></div> | ||
|
||
<div style="border:2px solid #337ab7;margin:4px 0;"><div style="background:#fafafa;border:12px solid #fafafa;font-family:segoe ui,lucida grande,Arial,sans-serif;font-size:14px;"> | ||
<br><br> | ||
{{ user.get_username() }}, | ||
<br> | ||
{% trans %}You have requested to change your email address to {{ new_email }} for your user account at {{ site_name }}.{% endtrans %} | ||
<br><br> | ||
{{ _('If this was you, no further action is required.') }} | ||
|
||
<br> | ||
<b> | ||
{% if site_admin_email %} | ||
{% with link='<a href="mailto:%(email)s">%(email)s</a>'|safe|format(email=site_admin_email) %} | ||
{{ _('If this was not you, please email us immediately at %(email)s.', email=link) }} | ||
{% endwith %} | ||
{% else %} | ||
{{ _('If this was not you, please reply to this email immediately.') }} | ||
{% endif %} | ||
</b> | ||
</div></div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{{ user.get_username() }}, | ||
{% trans %}You have requested to change your email address to {{ new_email }} for your user account at {{ site_name }}.{% endtrans %} | ||
|
||
{{ _('If this was you, no further action is required.') }} | ||
{% if site_admin_email %} | ||
{{ _('If this was not you, please email us immediately at %(email)s.', email=site_admin_email) }} | ||
{% else %} | ||
{{ _('If this was not you, please reply to this email immediately.') }} | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{% trans %}Alert: Email change request on {{ site_name }}{% endtrans %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters