forked from zulip/zulip
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change-email: Implement confirmation flow.
Partially fixes zulip#734.
- Loading branch information
1 parent
287b84d
commit a4a71dd
Showing
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.4 on 2017-01-17 09:16 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('confirmation', '0002_realmcreationkey'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='EmailChangeConfirmation', | ||
fields=[ | ||
], | ||
options={ | ||
'proxy': True, | ||
}, | ||
bases=('confirmation.confirmation',), | ||
), | ||
] |
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
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,16 @@ | ||
Hi there, | ||
|
||
Can you please confirm the ownership of this email address by clicking the | ||
link below? | ||
|
||
{{ activate_url }} | ||
|
||
{% if verbose_support_offers %} | ||
Feel free to give us a shout at <{{ support_email }}> if you have any questions. | ||
{% else %} | ||
If you are having issues, please contact your Zulip administrator at <{{ support_email }}>. | ||
{% endif %} | ||
|
||
Cheers, | ||
|
||
The Zulip Team |
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 @@ | ||
Please confirm your new email address |
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,14 @@ | ||
Hi there, | ||
|
||
The email address associated with your Zulip account was changed recently. If | ||
you did this then ignore this email otherwise contact us immediately. | ||
|
||
{% if verbose_support_offers %} | ||
Feel free to give us a shout at <{{ support_email }}> if you have any questions. | ||
{% else %} | ||
Please contact your Zulip administrator at <{{ support_email }}>. | ||
{% endif %} | ||
|
||
Cheers, | ||
|
||
The Zulip Team |
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 @@ | ||
Email change attempt |
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,29 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.4 on 2017-01-17 09:18 | ||
from __future__ import unicode_literals | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('zerver', '0049_userprofile_pm_content_in_desktop_notifications'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='EmailChangeStatus', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('new_email', models.EmailField(max_length=254)), | ||
('old_email', models.EmailField(max_length=254)), | ||
('updated_at', models.DateTimeField(auto_now=True)), | ||
('status', models.IntegerField(default=0)), | ||
('realm', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='zerver.Realm')), | ||
('user_profile', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
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,66 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import | ||
|
||
import datetime | ||
from typing import Any | ||
|
||
import django | ||
import mock | ||
from django.conf import settings | ||
from django.http import HttpResponse | ||
from django.urls import reverse | ||
|
||
from confirmation.models import EmailChangeConfirmation, generate_key | ||
from zerver.lib.actions import do_start_email_change_process | ||
from zerver.lib.test_classes import ( | ||
ZulipTestCase, | ||
) | ||
from zerver.models import get_user_profile_by_email, EmailChangeStatus | ||
|
||
|
||
class EmailChangeTestCase(ZulipTestCase): | ||
def test_confirm_email_change_with_non_existent_key(self): | ||
# type: () -> None | ||
self.login('hamlet@zulip.com') | ||
key = generate_key() | ||
url = EmailChangeConfirmation.objects.get_activation_url(key) | ||
response = self.client_get(url) | ||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(response.url, "/?ec=0#settings") | ||
|
||
def test_confirm_email_change_with_invalid_key(self): | ||
# type: () -> None | ||
self.login('hamlet@zulip.com') | ||
key = 'invalid key' | ||
url = EmailChangeConfirmation.objects.get_activation_url(key) | ||
response = self.client_get(url) | ||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(response.url, "/?ec=0#settings") | ||
|
||
def test_confirm_email_change(self): | ||
# type: () -> None | ||
old_email = 'hamlet@zulip.com' | ||
new_email = 'hamlet-new@zulip.com' | ||
self.login(old_email) | ||
user_profile = get_user_profile_by_email(old_email) | ||
obj = EmailChangeStatus.objects.create(new_email=new_email, | ||
old_email=old_email, | ||
user_profile=user_profile) | ||
key = generate_key() | ||
EmailChangeConfirmation.objects.create(content_object=obj, | ||
date_sent=datetime.datetime.now(), | ||
confirmation_key=key) | ||
url = EmailChangeConfirmation.objects.get_activation_url(key) | ||
response = self.client_get(url) | ||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(response.url, "/?ec=1#settings") | ||
user_profile = get_user_profile_by_email(new_email) | ||
self.assertTrue(bool(user_profile)) | ||
obj.refresh_from_db() | ||
self.assertEqual(obj.status, 1) | ||
|
||
def test_start_email_change_process(self): | ||
# type: () -> None | ||
user_profile = get_user_profile_by_email('hamlet@zulip.com') | ||
do_start_email_change_process(user_profile, 'hamlet-new@zulip.com') | ||
self.assertEqual(EmailChangeStatus.objects.count(), 1) |
Oops, something went wrong.