Permalink
Browse files

Merge pull request #545 from AnishShah/login-issue

fixed login-redirect issue for authenticated user
  • Loading branch information...
mitechie committed Jan 8, 2015
2 parents fa8f669 + 4aee763 commit 1f1716bd4e8cf32e2a624eff47093081162aa35a
Showing with 36 additions and 2 deletions.
  1. +25 −0 bookie/tests/test_auth/test_api_base.py
  2. +11 −2 bookie/views/auth.py
@@ -123,3 +123,28 @@ def test_login_null(self):
self.assertTrue(
'Failed login' in str(res),
"Should have 'Failed login' in the resp: " + str(res))
+
+ def test_redirect_for_authenticated_user(self):
+ """Verify if authenticated user gets redirect when
+ it hits login URL"""
+
+ user_data = {
+ 'login': u'admin',
+ 'password': u'admin',
+ 'form.submitted': u'true'
+ }
+
+ res = self.testapp.post('/login',
+ params=user_data)
+
+ self.assertEqual(
+ res.status,
+ "302 Found",
+ msg='status is 302 Found, ' + res.status)
+
+ res = self.testapp.get('/login')
+
+ self.assertEqual(
+ res.status,
+ "302 Found",
+ msg='status is 302 Found, ' + res.status)
View
@@ -12,8 +12,11 @@
from bookie.bcelery import tasks
from bookie.lib.applog import AuthLog
from bookie.models import IntegrityError
-from bookie.models.auth import UserMgr
-from bookie.models.auth import ActivationMgr
+from bookie.models.auth import (
+ UserMgr,
+ User,
+ ActivationMgr,
+)
LOG = logging.getLogger(__name__)
@@ -82,6 +85,12 @@ def login(request):
message = "Failed login"
AuthLog.login(login, False, password=password)
+ if isinstance(request.user, User) and request.user.activated:
+ return HTTPFound(
+ location=request.route_url(
+ 'user_bmark_recent',
+ username=request.user.username))
+
return {
'message': message,
'came_from': came_from,

0 comments on commit 1f1716b

Please sign in to comment.