@ -1,39 +1,42 @@ | |||||
from django.contrib.auth.hashers import make_password | |||||
from hc.test import BaseTestCase | from hc.test import BaseTestCase | ||||
class ChangeEmailTestCase(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="[email protected]", 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="[email protected]", password="password") | self.client.login(username="[email protected]", 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") | 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="[email protected]", password="password") | self.client.login(username="[email protected]", password="password") | ||||
self.set_sudo_flag() | |||||
payload = {"email": "[email protected]"} | payload = {"email": "[email protected]"} | ||||
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.alice.refresh_from_db() | ||||
self.assertEqual(self.alice.email, "[email protected]") | self.assertEqual(self.alice.email, "[email protected]") | ||||
self.assertFalse(self.alice.has_usable_password()) | 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="[email protected]", password="password") | self.client.login(username="[email protected]", password="password") | ||||
self.set_sudo_flag() | |||||
payload = {"email": "[email protected]"} | payload = {"email": "[email protected]"} | ||||
r = self.client.post("/accounts/change_email/foo/", payload) | |||||
r = self.client.post("/accounts/change_email/", payload) | |||||
self.assertContains(r, "[email protected] is already registered") | self.assertContains(r, "[email protected] is already registered") | ||||
self.alice.refresh_from_db() | self.alice.refresh_from_db() | ||||
@ -75,23 +75,6 @@ class ProfileTestCase(BaseTestCase): | |||||
self.assertEqual(len(mail.outbox), 0) | self.assertEqual(len(mail.outbox), 0) | ||||
def test_it_sends_change_email_link(self): | |||||
self.client.login(username="[email protected]", 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): | def test_leaving_works(self): | ||||
self.client.login(username="[email protected]", password="password") | self.client.login(username="[email protected]", password="password") | ||||
@ -2,7 +2,7 @@ from hc.test import BaseTestCase | |||||
class SetPasswordTestCase(BaseTestCase): | class SetPasswordTestCase(BaseTestCase): | ||||
def test_it_requires_sudo_mod(self): | |||||
def test_it_requires_sudo_mode(self): | |||||
self.client.login(username="[email protected]", password="password") | self.client.login(username="[email protected]", password="password") | ||||
r = self.client.get("/accounts/set_password/") | r = self.client.get("/accounts/set_password/") | ||||
@ -20,44 +20,49 @@ | |||||
</p> | </p> | ||||
{% if request.user.has_usable_password %} | {% if request.user.has_usable_password %} | ||||
<p> | |||||
Note: Changing the email address will also | |||||
<strong>reset your current password</strong> | |||||
<p class="alert alert-warning"> | |||||
<strong>Your password will be reset.</strong> | |||||
For security purposes, after updating your email address, | |||||
{% site_name %} will also reset your current password | |||||
and log you out. | and log you out. | ||||
</p> | </p> | ||||
{% endif %} | {% endif %} | ||||
{% if request.user.credentials.exists %} | |||||
<p class="alert alert-warning"> | |||||
<strong>Two-factor authentication is active.</strong> | |||||
If you are handing this account over to somebody else, | |||||
consider disabling two-factor authentication first. | |||||
</p> | |||||
{% endif %} | |||||
</div> | </div> | ||||
<form class="form-horizontal" method="post"> | |||||
<form method="post"> | |||||
{% csrf_token %} | {% csrf_token %} | ||||
<div class="form-group"> | <div class="form-group"> | ||||
<label class="col-sm-3 control-label">Current Email</label> | |||||
<div class="col-sm-9"> | |||||
<input | |||||
type="text" | |||||
class="form-control" | |||||
disabled | |||||
value="{{ request.user.email }}"> | |||||
</div> | |||||
<label class="control-label">Current Email</label> | |||||
<input | |||||
type="text" | |||||
class="form-control input-lg" | |||||
disabled | |||||
value="{{ request.user.email }}"> | |||||
</div> | </div> | ||||
<div class="form-group {{ form.email.css_classes }}"> | <div class="form-group {{ form.email.css_classes }}"> | ||||
<label for="ce-email" class="col-sm-3 control-label">New Email</label> | |||||
<div class="col-sm-9"> | |||||
<input | |||||
type="email" | |||||
class="form-control" | |||||
id="ce-email" | |||||
name="email" | |||||
placeholder="[email protected]"> | |||||
{% if form.email.errors %} | |||||
<div class="help-block"> | |||||
{{ form.email.errors|join:"" }} | |||||
</div> | |||||
{% endif %} | |||||
<label for="ce-email" class="control-label">New Email</label> | |||||
<input | |||||
type="email" | |||||
class="form-control input-lg" | |||||
id="ce-email" | |||||
name="email" | |||||
placeholder="[email protected]"> | |||||
{% if form.email.errors %} | |||||
<div class="help-block"> | |||||
{{ form.email.errors|join:"" }} | |||||
</div> | |||||
{% endif %} | |||||
</div> | |||||
</div> | </div> | ||||
<div class="clearfix"> | <div class="clearfix"> | ||||
@ -1,18 +0,0 @@ | |||||
{% extends "base.html" %} | |||||
{% block content %} | |||||
<div class="row"> | |||||
<div class="col-sm-6 col-sm-offset-3"> | |||||
<div class="hc-dialog"> | |||||
<h1>Email with Instructions Sent!</h1> | |||||
<br /> | |||||
<p> | |||||
We've sent you an email with further instructions. | |||||
Please check your inbox! | |||||
</p> | |||||
</div> | |||||
</div> | |||||
</div> | |||||
{% endblock %} |
@ -1,13 +0,0 @@ | |||||
{% extends "emails/base.html" %} | |||||
{% load hc_extras %} | |||||
{% block content %} | |||||
Hello,<br /> | |||||
To change the email address for your account on {% site_name %}, please press | |||||
the button below:</p> | |||||
{% endblock %} | |||||
{% block content_more %} | |||||
Regards,<br /> | |||||
The {% site_name %} Team | |||||
{% endblock %} |
@ -1,11 +0,0 @@ | |||||
{% load hc_extras %} | |||||
Hello, | |||||
Here's a link to change the email address for your account on {% site_name %}: | |||||
{{ button_url }} | |||||
-- | |||||
Regards, | |||||
{% site_name %} |
@ -1,2 +0,0 @@ | |||||
{% load hc_extras %} | |||||
Change email address on {% site_name %} |