# HG changeset patch # User Christophe de Vienne # Date 1407150259 -7200 # Node ID 00e5cb9771c59d23632b73ae3f458abc7c3bfcc3 # Parent b0b8942cdb809aa90e7810d18e83a2918bf095e7 Put the login view in a separate module. Related to #4291173 diff -r b0b8942cdb80 -r 00e5cb9771c5 pyramid_cubicweb/core.py --- a/pyramid_cubicweb/core.py Thu Jul 31 17:48:32 2014 +0200 +++ b/pyramid_cubicweb/core.py Mon Aug 04 13:04:19 2014 +0200 @@ -9,8 +9,7 @@ import cubicweb import cubicweb.web -from pyramid import security, httpexceptions -from pyramid.httpexceptions import HTTPSeeOther +from pyramid import httpexceptions from pyramid_cubicweb import authplugin @@ -110,36 +109,6 @@ return view._stream.getvalue() -def login(request): - repo = request.registry['cubicweb.repository'] - - response = request.response - user_eid = None - - if '__login' in request.params: - login = request.params['__login'] - password = request.params['__password'] - - try: - with repo.internal_cnx() as cnx: - user = repo.authenticate_user(cnx, login, password=password) - user_eid = user.eid - except cubicweb.AuthenticationError: - raise - - if user_eid is not None: - headers = security.remember(request, user_eid) - - raise HTTPSeeOther( - request.params.get('postlogin_path', '/'), - headers=headers) - - response.headerlist.extend(headers) - - response.text = render_view(request, 'login') - return response - - def _cw_cnx(request): cnx = repoapi.ClientConnection(request.cw_session) @@ -218,6 +187,3 @@ _cw_cnx, name='cw_cnx', property=True, reify=True) config.add_request_method( _cw_request, name='cw_request', property=True, reify=True) - - config.add_route('login', '/login') - config.add_view(login, route_name='login') diff -r b0b8942cdb80 -r 00e5cb9771c5 pyramid_cubicweb/defaults.py --- a/pyramid_cubicweb/defaults.py Thu Jul 31 17:48:32 2014 +0200 +++ b/pyramid_cubicweb/defaults.py Mon Aug 04 13:04:19 2014 +0200 @@ -14,3 +14,5 @@ config.set_authentication_policy( SessionAuthenticationPolicy(callback=get_principals)) config.set_authorization_policy(ACLAuthorizationPolicy()) + + config.include('pyramid_cubicweb.login') diff -r b0b8942cdb80 -r 00e5cb9771c5 pyramid_cubicweb/login.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pyramid_cubicweb/login.py Mon Aug 04 13:04:19 2014 +0200 @@ -0,0 +1,41 @@ +from pyramid import security +from pyramid.httpexceptions import HTTPSeeOther + +import cubicweb + +from pyramid_cubicweb.core import render_view + + +def login(request): + repo = request.registry['cubicweb.repository'] + + response = request.response + user_eid = None + + if '__login' in request.params: + login = request.params['__login'] + password = request.params['__password'] + + try: + with repo.internal_cnx() as cnx: + user = repo.authenticate_user(cnx, login, password=password) + user_eid = user.eid + except cubicweb.AuthenticationError: + raise + + if user_eid is not None: + headers = security.remember(request, user_eid) + + raise HTTPSeeOther( + request.params.get('postlogin_path', '/'), + headers=headers) + + response.headerlist.extend(headers) + + response.text = render_view(request, 'login') + return response + + +def includeme(config): + config.add_route('login', '/login') + config.add_view(login, route_name='login')