author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Thu, 14 May 2009 11:38:40 +0200 | |
branch | tls-sprint |
changeset 1802 | d628defebc17 |
parent 0 | b97547f5f1fa |
child 1977 | 606923dff11b |
permissions | -rw-r--r-- |
0 | 1 |
from cubicweb.web import Redirect |
2 |
from cubicweb.web.application import CubicWebPublisher |
|
3 |
||
4 |
# proof of concept : monkey patch publish method so that if we are in an |
|
5 |
# anonymous session and __fblogin is found is req.form, the user with the |
|
6 |
# given login is created if necessary and then a session is opened for that |
|
7 |
# user |
|
8 |
# NOTE: this require "cookie" authentication mode |
|
9 |
def auto_login_publish(self, path, req): |
|
10 |
if (req.cnx is None or req.cnx.anonymous_connection) and req.form.get('__fblogin'): |
|
11 |
login = password = req.form.pop('__fblogin') |
|
12 |
self.repo.register_user(login, password) |
|
13 |
req.form['__login'] = login |
|
14 |
req.form['__password'] = password |
|
15 |
if req.cnx: |
|
16 |
req.cnx.close() |
|
17 |
req.cnx = None |
|
18 |
try: |
|
19 |
self.session_handler.set_session(req) |
|
20 |
except Redirect: |
|
21 |
pass |
|
22 |
assert req.user.login == login |
|
23 |
return orig_publish(self, path, req) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
24 |
|
0 | 25 |
orig_publish = CubicWebPublisher.main_publish |
26 |
CubicWebPublisher.main_publish = auto_login_publish |