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.

44 lines
1.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # (c) 2015 ACSONE SA/NV, Dhinesh D
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import models
  5. from openerp import http
  6. from openerp.http import root
  7. from openerp.http import request
  8. from os import utime
  9. from os.path import getmtime
  10. from time import time
  11. class ResUsers(models.Model):
  12. _inherit = 'res.users'
  13. def _check_session_validity(self, db, uid, passwd):
  14. if not request:
  15. return
  16. session = request.session
  17. session_store = root.session_store
  18. param_obj = self.pool['ir.config_parameter']
  19. delay, urls = param_obj.get_session_parameters(db)
  20. deadline = time() - delay
  21. path = session_store.get_session_filename(session.sid)
  22. try:
  23. if getmtime(path) < deadline:
  24. if session.db and session.uid:
  25. session.logout(keep_db=True)
  26. elif http.request.httprequest.path not in urls:
  27. # the session is not expired, update the last modification
  28. # and access time.
  29. utime(path, None)
  30. except OSError:
  31. pass
  32. return
  33. def check(self, db, uid, passwd):
  34. res = super(ResUsers, self).check(db, uid, passwd)
  35. self._check_session_validity(db, uid, passwd)
  36. return res