Unify the URL name handling in ietfauth, i.e. just refer directly to

the view behind the URL instead of naming it.
 - Legacy-Id: 11172
This commit is contained in:
Ole Laursen 2016-05-06 12:58:10 +00:00
parent 4d4cf93f22
commit b83e0d2c78
15 changed files with 36 additions and 34 deletions

View file

@ -85,9 +85,10 @@ class ResetPasswordForm(forms.Form):
username = forms.EmailField(label="Your email (lowercase)")
def clean_username(self):
import ietf.ietfauth.views
username = self.cleaned_data["username"]
if not User.objects.filter(username=username).exists():
raise forms.ValidationError(mark_safe("Didn't find a matching account. If you don't have an account yet, you can <a href=\"{}\">create one</a>.".format(urlreverse("create_account"))))
raise forms.ValidationError(mark_safe("Didn't find a matching account. If you don't have an account yet, you can <a href=\"{}\">create one</a>.".format(urlreverse(ietf.ietfauth.views.create_account))))
return username

View file

@ -5,6 +5,7 @@ from urlparse import urlsplit
from pyquery import PyQuery
from django.core.urlresolvers import reverse as urlreverse
import django.contrib.auth.views
from django.contrib.auth.models import User
from django.conf import settings
@ -14,6 +15,7 @@ from ietf.utils.mail import outbox, empty_outbox
from ietf.person.models import Person, Email
from ietf.group.models import Group, Role, RoleName
from ietf.ietfauth.htpasswd import update_htpasswd_file
import ietf.ietfauth.views
class IetfAuthTests(TestCase):
def setUp(self):
@ -36,29 +38,29 @@ class IetfAuthTests(TestCase):
settings.HTDIGEST_REALM = self.saved_htdigest_realm
def test_index(self):
self.assertEqual(self.client.get(urlreverse("ietf.ietfauth.views.index")).status_code, 200)
self.assertEqual(self.client.get(urlreverse(ietf.ietfauth.views.index)).status_code, 200)
def test_login_and_logout(self):
make_test_data()
# try logging in without a next
r = self.client.get(urlreverse("account_login"))
r = self.client.get(urlreverse(django.contrib.auth.views.login))
self.assertEqual(r.status_code, 200)
r = self.client.post(urlreverse("account_login"), {"username":"plain", "password":"plain+password"})
r = self.client.post(urlreverse(django.contrib.auth.views.login), {"username":"plain", "password":"plain+password"})
self.assertEqual(r.status_code, 302)
self.assertEqual(urlsplit(r["Location"])[2], "/accounts/profile/")
self.assertEqual(urlsplit(r["Location"])[2], urlreverse(ietf.ietfauth.views.profile))
# try logging out
r = self.client.get(urlreverse("account_logout"))
r = self.client.get(urlreverse(django.contrib.auth.views.logout))
self.assertEqual(r.status_code, 200)
r = self.client.get(urlreverse("account_profile"))
r = self.client.get(urlreverse(ietf.ietfauth.views.profile))
self.assertEqual(r.status_code, 302)
self.assertEqual(urlsplit(r["Location"])[2], "/accounts/login/")
self.assertEqual(urlsplit(r["Location"])[2], urlreverse(django.contrib.auth.views.login))
# try logging in with a next
r = self.client.post(urlreverse("account_login") + "?next=/foobar", {"username":"plain", "password":"plain+password"})
r = self.client.post(urlreverse(django.contrib.auth.views.login) + "?next=/foobar", {"username":"plain", "password":"plain+password"})
self.assertEqual(r.status_code, 302)
self.assertEqual(urlsplit(r["Location"])[2], "/foobar")
@ -87,7 +89,7 @@ class IetfAuthTests(TestCase):
def test_create_account(self):
make_test_data()
url = urlreverse('create_account')
url = urlreverse(ietf.ietfauth.views.create_account)
# get
r = self.client.get(url)
@ -126,7 +128,7 @@ class IetfAuthTests(TestCase):
username = "plain"
email_address = Email.objects.filter(person__user__username=username).first().address
url = urlreverse('account_profile')
url = urlreverse(ietf.ietfauth.views.profile)
login_testing_unauthorized(self, username, url)
@ -228,7 +230,7 @@ class IetfAuthTests(TestCase):
def test_reset_password(self):
url = urlreverse('password_reset')
url = urlreverse(ietf.ietfauth.views.password_reset)
user = User.objects.create(username="someone@example.com", email="someone@example.com")
user.set_password("forgotten")

View file

@ -4,18 +4,18 @@ from django.conf.urls import patterns, url
from django.contrib.auth.views import login, logout
urlpatterns = patterns('ietf.ietfauth.views',
url(r'^$', 'index', name='account_index'),
url(r'^$', 'index'),
# url(r'^login/$', 'ietf_login'),
url(r'^login/$', login, name="account_login"),
url(r'^logout/$', logout, name="account_logout"),
url(r'^logout/$', logout),
# url(r'^loggedin/$', 'ietf_loggedin'),
# url(r'^loggedout/$', 'logged_out'),
url(r'^profile/$', 'profile', name="account_profile"),
url(r'^profile/$', 'profile'),
# (r'^login/(?P<user>[a-z0-9.@]+)/(?P<passwd>.+)$', 'url_login'),
url(r'^testemail/$', 'test_email'),
url(r'^create/$', 'create_account', name='create_account'),
url(r'^create/confirm/(?P<auth>[^/]+)/$', 'confirm_account', name='confirm_account'),
url(r'^reset/$', 'password_reset', name='password_reset'),
url(r'^reset/confirm/(?P<auth>[^/]+)/$', 'confirm_password_reset', name='confirm_password_reset'),
url(r'^confirmnewemail/(?P<auth>[^/]+)/$', 'confirm_new_email', name='confirm_new_email'),
url(r'^create/$', 'create_account'),
url(r'^create/confirm/(?P<auth>[^/]+)/$', 'confirm_account'),
url(r'^reset/$', 'password_reset'),
url(r'^reset/confirm/(?P<auth>[^/]+)/$', 'confirm_password_reset'),
url(r'^confirmnewemail/(?P<auth>[^/]+)/$', 'confirm_new_email'),
)

View file

@ -114,7 +114,7 @@ def confirm_account(request, auth):
raise Http404("Invalid or expired auth")
if User.objects.filter(username=email).exists():
return redirect("account_profile")
return redirect(profile)
success = False
if request.method == 'POST':

View file

@ -45,8 +45,7 @@ class ScheduleEditTests(StaticLiveServerTestCase):
return '%s%s'%(self.live_server_url,urlreverse(*args,**kwargs))
def login(self):
#url = self.absreverse('ietf.ietfauth.views.login')
url = '%s%s'%(self.live_server_url,'/accounts/login')
url = '%s%s'%(self.live_server_url, urlreverse('django.contrib.auth.views.login'))
self.driver.get(url)
self.driver.find_element_by_name('username').send_keys('plain')
self.driver.find_element_by_name('password').send_keys('plain+password')

View file

@ -22,7 +22,7 @@
{% endif %}
{% endif %}
<li><a href="{% url "create_account" %}">{% if request.user.is_authenticated %}Manage account{% else %}New account{% endif %}</a></li>
<li><a href="{% url "ietf.ietfauth.views.create_account" %}">{% if request.user.is_authenticated %}Manage account{% else %}New account{% endif %}</a></li>
<li><a href="{%url "ietf.cookies.views.preferences" %}" rel="nofollow">Preferences</a></li>
{% if user|has_role:"Area Director" %}

View file

@ -16,7 +16,7 @@
<h1>Change document shepherd<br><small>{{ doc.name }}-{{ doc.rev }}</small></h1>
<p>The shepherd needs to have a Datatracker account. A new account can be
<a href="{% url "create_account" %}">created here</a>.</p>
<a href="{% url "ietf.ietfauth.views.create_account" %}">created here</a>.</p>
<form enctype="multipart/form-data" method="post">
{% csrf_token %}

View file

@ -32,7 +32,7 @@
<p class="alert alert-info">Note that persons with authorization to manage information, e.g.
chairs and delegates, need a datatracker account to actually do
so. New accounts can be <a href="{% url "create_account" %}">created here</a>.</p>
so. New accounts can be <a href="{% url "ietf.ietfauth.views.create_account" %}">created here</a>.</p>
<form class="form-horizontal" method="post">
{% csrf_token %}

View file

@ -27,7 +27,7 @@
<p>
Delegates can be assigned with permission to do the tasks of the
chair{{ chairs|pluralize }}. Note that in order to actually do so, the delegates need a
datatracker account. New accounts can be <a href="{% url "create_account" %}">created here</a>.
datatracker account. New accounts can be <a href="{% url "ietf.ietfauth.views.create_account" %}">created here</a>.
</p>
<form method="post">

View file

@ -3,7 +3,7 @@ Hello,
{% filter wordwrap:73 %}We have received a request to add the email address {{ email }} to the user account '{{ person.user }}' at {{ domain }}. If you requested this change, please confirm that this is your email address by clicking on following link:{% endfilter %}
https://{{ domain }}{% url "confirm_new_email" auth %}
https://{{ domain }}{% url "ietf.ietfauth.views.confirm_new_email" auth %}
This link will expire in {{ expire }} days.

View file

@ -13,7 +13,7 @@
<h1>Account creation successful</h1>
<p>Your account with login {{ email }} has been created, using the password you have selected.</p>
<a type="a" class="btn btn-primary" href="{% url "account_login" %}" rel="nofollow">Sign in</a>
<a type="a" class="btn btn-primary" href="{% url "django.contrib.auth.views.login" %}" rel="nofollow">Sign in</a>
{% else %}
<h1>Complete account creation</h1>

View file

@ -14,13 +14,13 @@
{% bootstrap_form_errors form %}
<p>
<a class="btn btn-default" href="{% url "account_profile" %}">Edit profile</a>
<a class="btn btn-default" href="{% url "ietf.ietfauth.views.profile" %}">Edit profile</a>
</p>
{% elif new_email_obj %}
<p>Your account {{ username }} has been updated to include the email address {{ email }}.</p>
<p>
<a class="btn btn-default" href="{% url "account_profile" %}">Edit profile</a>
<a class="btn btn-default" href="{% url "ietf.ietfauth.views.profile" %}">Edit profile</a>
</p>
{% else %}
<p>Confirm that you want to add the email address {{ email }} to your account {{ username }}.</p>

View file

@ -47,7 +47,7 @@
please simply
</p>
<p>
<a class="btn btn-warning" href="{% url "password_reset" %}">Reset your password</a>
<a class="btn btn-warning" href="{% url "ietf.ietfauth.views.password_reset" %}">Reset your password</a>
</p>
</div>
</div>

View file

@ -3,7 +3,7 @@ Hello,
{% filter wordwrap:73 %}We have received an account creation request for {{ username }} at {{ domain }}. In order to set a new password for the {{ username }} account, please go to the following link and follow the instructions there:{% endfilter %}
https://{{ domain }}{% url "confirm_account" auth %}
https://{{ domain }}{% url "ietf.ietfauth.views.confirm_account" auth %}
This link will expire in {{ expire }} days.

View file

@ -3,7 +3,7 @@ Hello,
{% filter wordwrap:73 %}We have received a password reset request for {{ username }} at {{ domain }}. In order to set a new password for the {{ username }} account, please go to the following link and follow the instructions there:{% endfilter %}
https://{{ domain }}{% url "confirm_password_reset" auth %}
https://{{ domain }}{% url "ietf.ietfauth.views.confirm_password_reset" auth %}
This link will expire in {{ expire }} days.