equal
deleted
inserted
replaced
|
1 from pyramid import security |
|
2 from pyramid.httpexceptions import HTTPSeeOther |
|
3 |
|
4 import cubicweb |
|
5 |
|
6 from pyramid_cubicweb.core import render_view |
|
7 |
|
8 |
|
9 def login(request): |
|
10 repo = request.registry['cubicweb.repository'] |
|
11 |
|
12 response = request.response |
|
13 user_eid = None |
|
14 |
|
15 if '__login' in request.params: |
|
16 login = request.params['__login'] |
|
17 password = request.params['__password'] |
|
18 |
|
19 try: |
|
20 with repo.internal_cnx() as cnx: |
|
21 user = repo.authenticate_user(cnx, login, password=password) |
|
22 user_eid = user.eid |
|
23 except cubicweb.AuthenticationError: |
|
24 raise |
|
25 |
|
26 if user_eid is not None: |
|
27 headers = security.remember(request, user_eid) |
|
28 |
|
29 raise HTTPSeeOther( |
|
30 request.params.get('postlogin_path', '/'), |
|
31 headers=headers) |
|
32 |
|
33 response.headerlist.extend(headers) |
|
34 |
|
35 response.text = render_view(request, 'login') |
|
36 return response |
|
37 |
|
38 |
|
39 def includeme(config): |
|
40 config.add_route('login', '/login') |
|
41 config.add_view(login, route_name='login') |