diff --git a/hc/accounts/models.py b/hc/accounts/models.py
index cc239e30..a67e9396 100644
--- a/hc/accounts/models.py
+++ b/hc/accounts/models.py
@@ -118,12 +118,6 @@ class Profile(models.Model):
}
emails.transfer_request(self.user.email, ctx)
- def send_change_email_link(self):
- token = self.prepare_token("change-email")
- path = reverse("hc-change-email", args=[token])
- ctx = {"button_text": "Change Email", "button_url": settings.SITE_ROOT + path}
- emails.change_email(self.user.email, ctx)
-
def send_sms_limit_notice(self, transport):
ctx = {"transport": transport, "limit": self.sms_limit}
if self.sms_limit != 500 and settings.USE_PAYMENTS:
diff --git a/hc/accounts/tests/test_change_email.py b/hc/accounts/tests/test_change_email.py
index a4aee609..79f1fd16 100644
--- a/hc/accounts/tests/test_change_email.py
+++ b/hc/accounts/tests/test_change_email.py
@@ -1,39 +1,42 @@
-from django.contrib.auth.hashers import make_password
-
from hc.test import BaseTestCase
class ChangeEmailTestCase(BaseTestCase):
- def test_it_shows_form(self):
- self.profile.token = make_password("foo", "change-email")
- self.profile.save()
+ def test_it_requires_sudo_mode(self):
+ self.client.login(username="alice@example.org", password="password")
+
+ r = self.client.get("/accounts/change_email/")
+ self.assertContains(r, "We have sent a confirmation code")
+ def test_it_shows_form(self):
self.client.login(username="alice@example.org", password="password")
+ self.set_sudo_flag()
- r = self.client.get("/accounts/change_email/foo/")
+ r = self.client.get("/accounts/change_email/")
self.assertContains(r, "Change Account's Email Address")
- def test_it_changes_password(self):
- self.profile.token = make_password("foo", "change-email")
- self.profile.save()
-
+ def test_it_updates_email(self):
self.client.login(username="alice@example.org", password="password")
+ self.set_sudo_flag()
payload = {"email": "alice2@example.org"}
- self.client.post("/accounts/change_email/foo/", payload)
+ r = self.client.post("/accounts/change_email/", payload, follow=True)
+ self.assertRedirects(r, "/accounts/change_email/done/")
+ self.assertContains(r, "Email Address Updated")
self.alice.refresh_from_db()
self.assertEqual(self.alice.email, "alice2@example.org")
self.assertFalse(self.alice.has_usable_password())
- def test_it_requires_unique_email(self):
- self.profile.token = make_password("foo", "change-email")
- self.profile.save()
+ # The user should have been logged out:
+ self.assertNotIn("_auth_user_id", self.client.session)
+ def test_it_requires_unique_email(self):
self.client.login(username="alice@example.org", password="password")
+ self.set_sudo_flag()
payload = {"email": "bob@example.org"}
- r = self.client.post("/accounts/change_email/foo/", payload)
+ r = self.client.post("/accounts/change_email/", payload)
self.assertContains(r, "bob@example.org is already registered")
self.alice.refresh_from_db()
diff --git a/hc/accounts/tests/test_profile.py b/hc/accounts/tests/test_profile.py
index f9c8071c..c7d664af 100644
--- a/hc/accounts/tests/test_profile.py
+++ b/hc/accounts/tests/test_profile.py
@@ -75,23 +75,6 @@ class ProfileTestCase(BaseTestCase):
self.assertEqual(len(mail.outbox), 0)
- def test_it_sends_change_email_link(self):
- self.client.login(username="alice@example.org", password="password")
-
- form = {"change_email": "1"}
- r = self.client.post("/accounts/profile/", form)
- assert r.status_code == 302
-
- # profile.token should be set now
- self.profile.refresh_from_db()
- token = self.profile.token
- self.assertTrue(len(token) > 10)
-
- # And an email should have been sent
- self.assertEqual(len(mail.outbox), 1)
- expected_subject = "Change email address on %s" % settings.SITE_NAME
- self.assertEqual(mail.outbox[0].subject, expected_subject)
-
def test_leaving_works(self):
self.client.login(username="bob@example.org", password="password")
diff --git a/hc/accounts/tests/test_set_password.py b/hc/accounts/tests/test_set_password.py
index 54895493..15685a1c 100644
--- a/hc/accounts/tests/test_set_password.py
+++ b/hc/accounts/tests/test_set_password.py
@@ -2,7 +2,7 @@ from hc.test import BaseTestCase
class SetPasswordTestCase(BaseTestCase):
- def test_it_requires_sudo_mod(self):
+ def test_it_requires_sudo_mode(self):
self.client.login(username="alice@example.org", password="password")
r = self.client.get("/accounts/set_password/")
diff --git a/hc/accounts/urls.py b/hc/accounts/urls.py
index 7d9f72ab..15341527 100644
--- a/hc/accounts/urls.py
+++ b/hc/accounts/urls.py
@@ -7,7 +7,6 @@ urlpatterns = [
path("logout/", views.logout, name="hc-logout"),
path("signup/", views.signup, name="hc-signup"),
path("login_link_sent/", views.login_link_sent, name="hc-login-link-sent"),
- path("link_sent/", views.link_sent, name="hc-link-sent"),
path(
"check_token/
- Note: Changing the email address will also - reset your current password +
+ Your password will be reset. + For security purposes, after updating your email address, + {% site_name %} will also reset your current password and log you out.
{% endif %} + + {% if request.user.credentials.exists %} ++ Two-factor authentication is active. + If you are handing this account over to somebody else, + consider disabling two-factor authentication first. +
+ {% endif %} -