equal
deleted
inserted
replaced
7 from cubicweb import repoapi |
7 from cubicweb import repoapi |
8 |
8 |
9 import cubicweb |
9 import cubicweb |
10 import cubicweb.web |
10 import cubicweb.web |
11 |
11 |
12 from pyramid import security, httpexceptions |
12 from pyramid import httpexceptions |
13 from pyramid.httpexceptions import HTTPSeeOther |
|
14 |
13 |
15 from pyramid_cubicweb import authplugin |
14 from pyramid_cubicweb import authplugin |
16 |
15 |
17 import logging |
16 import logging |
18 |
17 |
108 view.set_stream() |
107 view.set_stream() |
109 view.render() |
108 view.render() |
110 return view._stream.getvalue() |
109 return view._stream.getvalue() |
111 |
110 |
112 |
111 |
113 def login(request): |
|
114 repo = request.registry['cubicweb.repository'] |
|
115 |
|
116 response = request.response |
|
117 user_eid = None |
|
118 |
|
119 if '__login' in request.params: |
|
120 login = request.params['__login'] |
|
121 password = request.params['__password'] |
|
122 |
|
123 try: |
|
124 with repo.internal_cnx() as cnx: |
|
125 user = repo.authenticate_user(cnx, login, password=password) |
|
126 user_eid = user.eid |
|
127 except cubicweb.AuthenticationError: |
|
128 raise |
|
129 |
|
130 if user_eid is not None: |
|
131 headers = security.remember(request, user_eid) |
|
132 |
|
133 raise HTTPSeeOther( |
|
134 request.params.get('postlogin_path', '/'), |
|
135 headers=headers) |
|
136 |
|
137 response.headerlist.extend(headers) |
|
138 |
|
139 response.text = render_view(request, 'login') |
|
140 return response |
|
141 |
|
142 |
|
143 def _cw_cnx(request): |
112 def _cw_cnx(request): |
144 cnx = repoapi.ClientConnection(request.cw_session) |
113 cnx = repoapi.ClientConnection(request.cw_session) |
145 |
114 |
146 def cleanup(request): |
115 def cleanup(request): |
147 if request.exception is not None: |
116 if request.exception is not None: |
216 _cw_session, name='cw_session', property=True, reify=True) |
185 _cw_session, name='cw_session', property=True, reify=True) |
217 config.add_request_method( |
186 config.add_request_method( |
218 _cw_cnx, name='cw_cnx', property=True, reify=True) |
187 _cw_cnx, name='cw_cnx', property=True, reify=True) |
219 config.add_request_method( |
188 config.add_request_method( |
220 _cw_request, name='cw_request', property=True, reify=True) |
189 _cw_request, name='cw_request', property=True, reify=True) |
221 |
|
222 config.add_route('login', '/login') |
|
223 config.add_view(login, route_name='login') |
|