[damned-lies] Don't show login form when the user is authenticated



commit 4bcfd3fea7fbbe04ba0cd5ef46aec92a5c902123
Author: Claude Paroz <claude 2xlibre net>
Date:   Mon Dec 24 09:40:54 2018 +0100

    Don't show login form when the user is authenticated
    
    Thanks Tom Tryfonidis for the initial patch.

 people/tests.py      | 6 ++++++
 templates/login.html | 6 +++---
 2 files changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/people/tests.py b/people/tests.py
index 0c155e84..aec93787 100644
--- a/people/tests.py
+++ b/people/tests.py
@@ -72,6 +72,12 @@ class PeopleTestCase(TestCase):
             'You have not joined any translation team yet. '
             'You can do it from <a href="/users/team_join/">your profile</a>.'
         )
+        response = self.client.get(reverse('login'))
+        self.assertContains(
+            response,
+            'You are already logged in as jn.'
+        )
+        self.assertNotContains(response, 'id="login-form"')
 
     def test_login_by_email(self):
         self.pn = self._create_person()
diff --git a/templates/login.html b/templates/login.html
index cb82a803..dc4a0ef9 100644
--- a/templates/login.html
+++ b/templates/login.html
@@ -7,6 +7,9 @@
 <div class="col-sm-8 col-md-6 col-centered">
 <h1>{% trans "User Login" %}</h1>
 
+{% if user.is_authenticated %}
+  <p>{% blocktrans with user.username as username %}You are already logged in as {{ username }}.{% 
endblocktrans %}</p>
+{% else %}
 <p>{% trans 'Log in with your username (or email) and password:' %}</p>
 <form action="{% url 'login' %}" method="post" id="login-form" class="form">
   {% csrf_token %}
@@ -33,9 +36,6 @@
 
 <hr>
 <p class="text-center main_feature" style="margin-bottom: 30px;">Don't have an account?</p>
-{% if user.is_authenticated %}
-  <p>{% blocktrans with user.username as username %}You are already logged in as {{ username }}.{% 
endblocktrans %}</p>
-{% else %}
 {% url 'register' as link %}
   <a href="{{ link }}" class="btn btn-action btn-block">{% trans "Register" %}</a>
 


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