Permalink
Browse files

Merge pull request #137 from groovecoder/734193-remove-logout-from-login

734193 remove logout from login
  • Loading branch information...
2 parents b02ff17 + 685ccf2 commit 489cdc4fd11e2cd8957df66c6f20708e5becff6f @lmorchard lmorchard committed Mar 21, 2012
Showing with 51 additions and 11 deletions.
  1. +13 −7 apps/users/templates/users/login.html
  2. +30 −0 apps/users/tests/test_views.py
  3. +0 −2 apps/users/utils.py
  4. +8 −2 apps/users/views.py
View
20 apps/users/templates/users/login.html
@@ -9,14 +9,20 @@
<section id="content">
<div class="wrap">
<div id="content-main" class="full">
- <article id="login" class="main" data-browserid-signin-html="{{ url('users.browserid_signin_html') }}?next={{ next_url }}">
- {% if use_browserid %}
- {% include "users/browserid_signin.html" %}
- {% else %}
- <h1>{{ _('Log In') }}</h1>
- {% include "users/login_form.html" %}
- {% endif %}
+ {% if request.user.is_authenticated() %}
+ <article class="main">
+ <h3>{{ _('You are already logged in.') }}</h3>
</article>
+ {% else %}
+ <article id="login" class="main" data-browserid-signin-html="{{ url('users.browserid_signin_html') }}?next={{ next_url }}">
+ {% if use_browserid %}
+ {% include "users/browserid_signin.html" %}
+ {% else %}
+ <h1>{{ _('Log In') }}</h1>
+ {% include "users/login_form.html" %}
+ {% endif %}
+ </article>
+ {% endif %}
</div>
</div>
</section>
View
30 apps/users/tests/test_views.py
@@ -81,6 +81,36 @@ def test_django_login_wont_redirect_to_login(self, get_current):
doc = pq(response.content)
eq_('testuser', doc.find('ul.user-state a:first').text())
+ @mock.patch_object(Site.objects, 'get_current')
+ def test_logged_in_message(self, get_current):
+ get_current.return_value.domain = 'dev.mo.org'
+ login_uri = reverse('users.login')
+
+ response = self.client.post(login_uri,
+ {'username': 'testuser',
+ 'password': 'testpass'},
+ follow=True)
+ eq_(200, response.status_code)
+ response = self.client.get(login_uri, follow=True)
+ eq_(200, response.status_code)
+ doc = pq(response.content)
+ eq_("You are already logged in.", doc.find('div#content-main').text())
+
+ @mock.patch_object(Site.objects, 'get_current')
+ def test_django_login_redirects_to_next(self, get_current):
+ get_current.return_value.domain = 'dev.mo.org'
+ login_uri = reverse('users.login')
+
+ response = self.client.post(login_uri,
+ {'username': 'testuser',
+ 'password': 'testpass'},
+ follow=True)
+ eq_(200, response.status_code)
+ response = self.client.get(login_uri, {'next': '/en-US/demos/submit'},
+ follow=True)
+ eq_('http://testserver/en-US/demos/submit',
+ response.redirect_chain[0][0])
+
@mock_mindtouch_login
@mock_get_deki_user
@mock_put_mindtouch_user
View
2 apps/users/utils.py
@@ -11,8 +11,6 @@
def handle_login(request, only_active=True):
- auth.logout(request)
-
if request.method == 'POST':
form = AuthenticationForm(data=request.POST, only_active=only_active)
if form.is_valid():
View
10 apps/users/views.py
@@ -258,10 +258,16 @@ def browserid_register(request):
@ssl_required
def login(request):
"""Try to log the user in."""
- next_url = _clean_next_url(request) or reverse('home')
+ next_url = _clean_next_url(request)
+ if request.method == 'GET' and request.user.is_authenticated():
+ if next_url:
+ return HttpResponseRedirect(next_url)
+ else:
+ next_url = _clean_next_url(request) or reverse('home')
form = handle_login(request)
- if request.user.is_authenticated():
+ if form.is_valid() and request.user.is_authenticated():
+ next_url = next_url or reverse('home')
return _redirect_with_mindtouch_login(next_url,
form.cleaned_data.get('username'),
form.cleaned_data.get('password'))

0 comments on commit 489cdc4

Please sign in to comment.