0001-WIP-warn-user-after-account-self-deletion-26910.patch
src/authentic2/registration_backend/views.py | ||
---|---|---|
389 | 389 |
return kwargs |
390 | 390 | |
391 | 391 |
def form_valid(self, form): |
392 |
email = self.request.user.email |
|
393 |
ou = self.request.user.ou |
|
394 |
context = { |
|
395 |
'full_name': self.request.user.get_full_name(), |
|
396 |
'site': self.request.get_host()} |
|
392 | 397 |
models.DeletedUser.objects.delete_user(self.request.user) |
393 | 398 |
self.request.user.email += '#%d' % random.randint(1, 10000000) |
394 | 399 |
self.request.user.email_verified = False |
... | ... | |
397 | 402 |
hooks.call_hooks('event', name='delete-account', user=self.request.user) |
398 | 403 |
messages.info(self.request, |
399 | 404 |
_('Your account has been scheduled for deletion. You cannot use it anymore.')) |
405 |
utils.send_account_deletion_mail(self.request, email, ou, context) |
|
400 | 406 |
return super(DeleteView, self).form_valid(form) |
401 | 407 | |
402 | 408 |
registration_completion = valid_token(RegistrationCompletionView.as_view()) |
src/authentic2/templates/authentic2/account_delete_notification_body.html | ||
---|---|---|
1 |
{% load i18n %} |
|
2 |
<html> |
|
3 |
<body style="max-width: 90ex"> |
|
4 |
{% blocktrans %} |
|
5 |
<p>{{ full_name }},</p> |
|
6 |
<p>Your account deletion request on {{ site }} has been received.</p> |
|
7 |
{% endblocktrans %} |
|
8 |
</body> |
|
9 |
</html> |
src/authentic2/templates/authentic2/account_delete_notification_body.txt | ||
---|---|---|
1 |
{% load i18n %}{% autoescape off %}{% blocktrans %}{{ full_name }}, |
|
2 | ||
3 |
Your account deletion request on {{ site }} has been received. |
|
4 |
{% endblocktrans %}{% endautoescape %} |
src/authentic2/templates/authentic2/account_delete_notification_subject.txt | ||
---|---|---|
1 |
{% load i18n %}{% autoescape off %}{% trans "Account deletion request on" %} {{ site }}{% endautoescape %} |
src/authentic2/utils.py | ||
---|---|---|
693 | 693 |
registration_url) |
694 | 694 | |
695 | 695 | |
696 |
def send_account_deletion_mail(request, email, ou, context=None, template_names=None): |
|
697 |
'''Send an account deletion notification mail to an user. |
|
698 | ||
699 |
Can raise an smtplib.SMTPException |
|
700 |
''' |
|
701 |
logger = logging.getLogger(__name__) |
|
702 |
if not template_names: |
|
703 |
template_names = ['authentic2/account_delete_notification'] |
|
704 | ||
705 |
send_templated_mail(email, template_names, request=request, context=context) |
|
706 |
logger.info(u'account deletion mail sent to %s', email) |
|
707 | ||
708 | ||
696 | 709 |
def build_reset_password_url(user, request=None, next_url=None, set_random_password=True): |
697 | 710 |
'''Build a reset password URL''' |
698 | 711 |
from .compat import default_token_generator |
tests/test_views.py | ||
---|---|---|
21 | 21 |
page = page.form.submit('cancel').follow() |
22 | 22 | |
23 | 23 | |
24 |
def test_account_delete(app, simple_user): |
|
24 |
def test_account_delete(app, simple_user, mailoutbox):
|
|
25 | 25 |
assert simple_user.is_active |
26 |
assert not len(mailoutbox) |
|
26 | 27 |
page = login(app, simple_user, path=reverse('delete_account')) |
27 | 28 |
page.form.set('password', simple_user.username) |
28 | 29 |
# FIXME: webtest does not set the Referer header, so the logout page will always ask for |
29 | 30 |
# confirmation under tests |
30 | 31 |
response = page.form.submit(name='submit').follow() |
31 | 32 |
response = response.form.submit() |
33 |
assert len(mailoutbox) == 1 |
|
32 | 34 |
assert not User.objects.get(pk=simple_user.pk).is_active |
33 | 35 |
assert urlparse(response.location).path == '/' |
34 | 36 |
response = response.follow().follow() |
35 |
- |