You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
2.1 KiB

11 years ago
11 years ago
10 years ago
11 years ago
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # This module copyright (C) 2014 Therp BV (<http://therp.nl>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp.addons.web.http import WebRequest, JsonRequest
  22. from openerp.addons.web.controllers import main as web_main
  23. old_init = WebRequest.init
  24. def init(self, params):
  25. old_init(self, params)
  26. if self.httprequest.authorization and not self.session._login:
  27. dbs = web_main.db_list(self)
  28. self.session.authenticate(
  29. dbs and dbs[0],
  30. self.httprequest.authorization.username,
  31. self.httprequest.authorization.password,
  32. dict(
  33. base_location=self.httprequest.url_root.rstrip('/'),
  34. HTTP_HOST=self.httprequest.environ['HTTP_HOST'],
  35. REMOTE_ADDR=self.httprequest.environ['REMOTE_ADDR']
  36. )
  37. )
  38. WebRequest.init = init
  39. old_dispatch = JsonRequest.dispatch
  40. def dispatch(self, method):
  41. response = old_dispatch(self, method)
  42. if method.im_func == web_main.Session.destroy.im_func:
  43. response.status = '301 logout'
  44. response.headers.add(
  45. 'Location',
  46. self.httprequest.url.replace('://', '://logout@'))
  47. return response
  48. JsonRequest.dispatch = dispatch