security.py 650 B

123456789101112131415161718192021
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. import odoo
  4. import odoo.exceptions
  5. def check(db, uid, passwd):
  6. res_users = odoo.registry(db)['res.users']
  7. return res_users.check(db, uid, passwd)
  8. def compute_session_token(session, env):
  9. self = env['res.users'].browse(session.uid)
  10. return self._compute_session_token(session.sid)
  11. def check_session(session, env):
  12. self = env['res.users'].browse(session.uid)
  13. expected = self._compute_session_token(session.sid)
  14. if expected and odoo.tools.misc.consteq(expected, session.session_token):
  15. return True
  16. return False