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.

62 lines
2.2 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. # This file is part of inactive_session_timeout, an Odoo module.
  4. #
  5. # Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>)
  6. #
  7. # inactive_session_timeout is free software: you can redistribute it
  8. # and/or modify it under the terms of the GNU Affero General Public License
  9. # as published by the Free Software Foundation, either version 3 of
  10. # the License, or (at your option) any later version.
  11. #
  12. # inactive_session_timeout is distributed in the hope that it will
  13. # be useful, 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
  18. # GNU Affero General Public License
  19. # along with inactive_session_timeout.
  20. # If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. ##############################################################################
  23. from openerp import models
  24. from openerp import http
  25. from openerp.http import root
  26. from openerp.http import request
  27. from os import utime
  28. from os.path import getmtime
  29. from time import time
  30. class ResUsers(models.Model):
  31. _inherit = 'res.users'
  32. def _check_session_validity(self, db, uid, passwd):
  33. if not request:
  34. return
  35. session = request.session
  36. session_store = root.session_store
  37. param_obj = self.pool['ir.config_parameter']
  38. delay, urls = param_obj.get_session_parameters(db)
  39. deadline = time() - delay
  40. path = session_store.get_session_filename(session.sid)
  41. try:
  42. if getmtime(path) < deadline:
  43. if session.db and session.uid:
  44. session.logout(keep_db=True)
  45. elif http.request.httprequest.path not in urls:
  46. # the session is not expired, update the last modification
  47. # and access time.
  48. utime(path, None)
  49. except OSError:
  50. pass
  51. return
  52. def check(self, db, uid, passwd):
  53. res = super(ResUsers, self).check(db, uid, passwd)
  54. self._check_session_validity(db, uid, passwd)
  55. return res