19 |
19 |
20 """ |
20 """ |
21 from cubicweb.web import Redirect |
21 from cubicweb.web import Redirect |
22 from cubicweb.web.application import CubicWebPublisher |
22 from cubicweb.web.application import CubicWebPublisher |
23 |
23 |
24 # proof of concept : monkey patch publish method so that if we are in an |
24 # proof of concept : monkey patch handle method so that if we are in an |
25 # anonymous session and __fblogin is found is req.form, the user with the |
25 # anonymous session and __fblogin is found is req.form, the user with the |
26 # given login is created if necessary and then a session is opened for that |
26 # given login is created if necessary and then a session is opened for that |
27 # user |
27 # user |
28 # NOTE: this require "cookie" authentication mode |
28 # NOTE: this require "cookie" authentication mode |
29 def auto_login_publish(self, path, req): |
29 def auto_login_handle_request(self, req, path): |
30 if (not req.cnx or req.cnx.anonymous_connection) and req.form.get('__fblogin'): |
30 if (not req.cnx or req.cnx.anonymous_connection) and req.form.get('__fblogin'): |
31 login = password = req.form.pop('__fblogin') |
31 login = password = req.form.pop('__fblogin') |
32 self.repo.register_user(login, password) |
32 self.repo.register_user(login, password) |
33 req.form['__login'] = login |
33 req.form['__login'] = login |
34 req.form['__password'] = password |
34 req.form['__password'] = password |
38 try: |
38 try: |
39 self.session_handler.set_session(req) |
39 self.session_handler.set_session(req) |
40 except Redirect: |
40 except Redirect: |
41 pass |
41 pass |
42 assert req.user.login == login |
42 assert req.user.login == login |
43 return orig_publish(self, path, req) |
43 return orig_handle(self, req, path) |
44 |
44 |
45 orig_publish = CubicWebPublisher.main_publish |
45 orig_handle = CubicWebPublisher.main_handle_request |
46 CubicWebPublisher.main_publish = auto_login_publish |
46 CubicWebPublisher.main_handle_request = auto_login_handle_request |