[snowy] Improve login page look and error handling



commit 88356f730b70b0706aac2abffd79a88c4db9cab7
Author: Adam Ziolkowski <adam adsized com>
Date:   Wed Dec 29 23:03:02 2010 +0100

    Improve login page look and error handling
    
    - Show error after failed user/pass login
    - Align username/password text field icons to the left
    - Use the new auth_login page for adding OpenIDs to an existing account

 accounts/templates/accounts/login.html       |    7 ++++++-
 accounts/templates/accounts/preferences.html |    2 +-
 accounts/urls.py                             |    4 ----
 accounts/views.py                            |   11 ++++++++++-
 site_media/css/accounts.css                  |    6 ++++--
 5 files changed, 21 insertions(+), 9 deletions(-)
---
diff --git a/accounts/templates/accounts/login.html b/accounts/templates/accounts/login.html
index fcb286c..7af6231 100644
--- a/accounts/templates/accounts/login.html
+++ b/accounts/templates/accounts/login.html
@@ -21,6 +21,9 @@
 <br />
 {% endfor %}
 {% endif %}
+{% if auth_form.errors %}
+	<div class="error center" style="color: red;">{% trans "Your username and password didn't match. Please try again." %}</div>
+{% endif %}
 <div id="login-container">
     <h2>
         {% if user.is_authenticated %}
@@ -29,7 +32,8 @@
         <h1>{% trans "Log in to" %} {{ site.name }}</h1>
         {% endif %}
     </h2>
-    <form method="post" id="auth-login-form" action="{% url registration_login %}">
+    {% if not user.is_authenticated %}
+    <form method="post" id="auth-login-form" action="{% url auth_login %}">
         <b>{{ auth_form.username.label_tag }}</b>
         {{ auth_form.username }}
         <br />
@@ -39,6 +43,7 @@
         <input type="submit" value="{% trans "Log in" %}">
     </form>
     <h2>...{% trans"or log in with" %}:</h2>
+    {% endif %}
     <div id="main-openid-provider-buttons">
         {% comment %}Initially visible provider buttons are inserted here{% endcomment %}
         <a id="openid-url-provider-button" href="#" class="openid-provider-button"><img src="{{ MEDIA_URL }}img/accounts/openid/openid.png" /></a>
diff --git a/accounts/templates/accounts/preferences.html b/accounts/templates/accounts/preferences.html
index b82fe58..6defcaa 100644
--- a/accounts/templates/accounts/preferences.html
+++ b/accounts/templates/accounts/preferences.html
@@ -77,7 +77,7 @@
     <table class="input-form">
         <tr>
             <th>
-                <a href="{% url openid-login %}">{% trans "Add OpenID account" %}</a>
+                <a href="{% url auth_login %}">{% trans "Add OpenID account" %}</a>
             </th>
             <td></td>
         </tr>
diff --git a/accounts/urls.py b/accounts/urls.py
index f731dcc..ff0beaf 100644
--- a/accounts/urls.py
+++ b/accounts/urls.py
@@ -60,10 +60,6 @@ urlpatterns = patterns('',
         name='auth_password_reset_complete'),
     url(r'^password/reset/done/$', auth_views.password_reset_done,
         name='auth_password_reset_done'),
-    # name this url auth login because some libraries expects the "default login"
-    # url to be called auth_login
-    url(r'^register/login/$', auth_views.login, {'template_name': 'accounts/login.html'},
-        name='registration_login'),
     url(r'^register/$', register, {'form_class': RegistrationFormUniqueUser},
         name='registration_register'),
     url(r'^register/complete/$', direct_to_template,
diff --git a/accounts/views.py b/accounts/views.py
index bed73b2..05bc4fd 100644
--- a/accounts/views.py
+++ b/accounts/views.py
@@ -40,6 +40,7 @@ from django_openid_auth.models import UserOpenID
 from django_openid_auth.forms import OpenIDLoginForm
 
 import django_openid_auth.views
+import django.contrib.auth.views
 
 def openid_registration(request, template_name='registration/registration_form.html'):
     registration_form = OpenIDRegistrationFormUniqueUser(request.POST or None)
@@ -133,7 +134,15 @@ def accounts_login(request, template_name='accounts/login.html', *args, **kwargs
     openid_form = OpenIDLoginForm()
     # change the label text to something nicer
     openid_form.fields['openid_identifier'].label = _("OpenID")
-    auth_form = AuthenticationForm()
+    if request.method == "POST":
+        auth_form = AuthenticationForm(data=request.POST)
+        # If is_valid() returns true we can be 99% certain there won't be an error when loggging in
+        if auth_form.is_valid():
+            # Pass control to django_auth and return the result
+            return django.contrib.auth.views.login(request, auth_form.get_user())
+    else:
+        auth_form = AuthenticationForm()
+
     return render_to_response(template_name, {
         'auth_form': auth_form,
         'openid_form': openid_form },
diff --git a/site_media/css/accounts.css b/site_media/css/accounts.css
index 2374809..a76933c 100644
--- a/site_media/css/accounts.css
+++ b/site_media/css/accounts.css
@@ -36,13 +36,15 @@
 /* username input field */
 #login-container #id_username {
     background: url('/site_media/img/accounts/users.png') no-repeat;
-    background-position: 95%;
+    background-position: 2%;
+    padding-left: 3.5em;
 }
 
 /* password input field */
 #login-container #id_password {
     background: url('/site_media/img/accounts/keyring.png') no-repeat;
-    background-position: 95%;
+    background-position: 2%;
+    padding-left: 3.5em;
 }
 
 /* text input fields */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]