equal
deleted
inserted
replaced
|
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) |
|
24 |
|
25 orig_publish = CubicWebPublisher.main_publish |
|
26 CubicWebPublisher.main_publish = auto_login_publish |