Only access once to _cw.message in the login form
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 01 Jun 2016 17:05:16 +0200
changeset 11280 eb1d74ce6b61
parent 11279 e4f11ef1face
child 11281 2cb8b383a519
Only access once to _cw.message in the login form else the first access may pop the message and the second won't get anything to display. This works on default message implementation but doesn't on the pyramid's one, leading to no message displayed on erroneous authentication attempt, which is not very user friendly.
cubicweb/web/test/unittest_views_basetemplates.py
cubicweb/web/views/basetemplates.py
--- a/cubicweb/web/test/unittest_views_basetemplates.py	Thu Jun 16 15:53:01 2016 +0200
+++ b/cubicweb/web/test/unittest_views_basetemplates.py	Wed Jun 01 17:05:16 2016 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -34,6 +34,12 @@
         self.set_option('allow-email-login', 'no')
         self.assertEqual(self._login_labels(), ['login', 'password'])
 
+    def test_display_message(self):
+        with self.admin_access.web_request() as req:
+            req.set_message(u'houla hop')
+            page = self.view('logform', req=req, id='loginBox', klass='', template=None)
+            self.assertIn(u'houla hop', page.raw_text)
+
 
 class MainNoTopTemplateTC(CubicWebTC):
 
--- a/cubicweb/web/views/basetemplates.py	Thu Jun 16 15:53:01 2016 +0200
+++ b/cubicweb/web/views/basetemplates.py	Wed Jun 01 17:05:16 2016 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -508,8 +508,9 @@
                 stitle = u'&#160;'
             w(u'<div class="loginTitle">%s</div>' % stitle)
         w(u'<div class="loginContent">\n')
-        if showmessage and self._cw.message:
-            w(u'<div class="loginMessage">%s</div>\n' % self._cw.message)
+        message = self._cw.message  # don't call self._cw.message twice
+        if showmessage and message:
+            w(u'<div class="loginMessage">%s</div>\n' % message)
         config = self._cw.vreg.config
         if config['auth-mode'] != 'http':
             self.login_form(id) # Cookie authentication