# HG changeset patch # User Samuel Trégouët # Date 1484303811 -3600 # Node ID 4c949c28ce599bd5cdcd67fc1f03b842f5f27c73 # Parent acfb9aa4845e16c941f3457dfb36f1ea27ae3563 [pyramid] fix login route with language-mode = url-prefix diff -r acfb9aa4845e -r 4c949c28ce59 cubicweb/pyramid/login.py --- a/cubicweb/pyramid/login.py Fri Nov 18 10:28:41 2016 +0100 +++ b/cubicweb/pyramid/login.py Fri Jan 13 11:36:51 2017 +0100 @@ -81,5 +81,13 @@ def includeme(config): """ Create the 'login' route ('/login') and load this module views""" + cwconfig = config.registry['cubicweb.config'] config.add_route('login', '/login') + if cwconfig.get('language-mode') == 'url-prefix': + config.add_route('login-lang', '/{lang}/login') + config.add_view(login_already_loggedin, route_name='login-lang', + effective_principals=security.Authenticated) + config.add_view(login_form, route_name='login-lang') + config.add_view(login_password_login, route_name='login-lang', + request_param=('__login', '__password')) config.scan('cubicweb.pyramid.login') diff -r acfb9aa4845e -r 4c949c28ce59 cubicweb/pyramid/test/test_login.py --- a/cubicweb/pyramid/test/test_login.py Fri Nov 18 10:28:41 2016 +0100 +++ b/cubicweb/pyramid/test/test_login.py Fri Jan 13 11:36:51 2017 +0100 @@ -3,8 +3,25 @@ from cubicweb.pyramid.test import PyramidCWTest +class LoginTestLangUrlPrefix(PyramidCWTest): + + @classmethod + def setUpClass(cls): + super(LoginTestLangUrlPrefix, cls).setUpClass() + cls.config.global_set_option('language-mode', 'url-prefix') + + def test_login_password_login_lang_prefix(self): + res = self.webapp.post('/fr/login', { + '__login': self.admlogin, '__password': self.admpassword}) + self.assertEqual(res.status_int, 303) + + res = self.webapp.get('/fr/login') + self.assertEqual(res.status_int, 303) + + class LoginTest(PyramidCWTest): + def test_login_form(self): res = self.webapp.get('/login') self.assertIn('__login', res.text)