mirror of
https://github.com/bringout/oca-ocb-security.git
synced 2026-04-23 09:52:09 +02:00
19.0 vanilla
This commit is contained in:
parent
20ddc1b4a3
commit
c0efcc53f5
1162 changed files with 125577 additions and 105287 deletions
|
|
@ -1,19 +1,19 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from odoo import api, models
|
||||
from odoo.addons.auth_totp.controllers.home import TRUSTED_DEVICE_AGE
|
||||
from odoo import models
|
||||
from odoo.addons.auth_totp.controllers.home import TRUSTED_DEVICE_AGE_DAYS
|
||||
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AuthTotpDevice(models.Model):
|
||||
class Auth_TotpDevice(models.Model):
|
||||
|
||||
# init is overriden in res.users.apikeys to create a secret column 'key'
|
||||
# use a different model to benefit from the secured methods while not mixing
|
||||
# two different concepts
|
||||
|
||||
_name = "auth_totp.device"
|
||||
_inherit = "res.users.apikeys"
|
||||
_name = 'auth_totp.device'
|
||||
_inherit = ["res.users.apikeys"]
|
||||
_description = "Authentication Device"
|
||||
_auto = False
|
||||
|
||||
|
|
@ -22,10 +22,17 @@ class AuthTotpDevice(models.Model):
|
|||
assert uid, "uid is required"
|
||||
return self._check_credentials(scope=scope, key=key) == uid
|
||||
|
||||
@api.autovacuum
|
||||
def _gc_device(self):
|
||||
self._cr.execute("""
|
||||
DELETE FROM auth_totp_device
|
||||
WHERE create_date < (NOW() AT TIME ZONE 'UTC' - INTERVAL '%s SECONDS')
|
||||
""", [TRUSTED_DEVICE_AGE])
|
||||
_logger.info("GC'd %d totp devices entries", self._cr.rowcount)
|
||||
def _get_trusted_device_age(self):
|
||||
ICP = self.env['ir.config_parameter'].sudo()
|
||||
try:
|
||||
nbr_days = int(ICP.get_param('auth_totp.trusted_device_age', TRUSTED_DEVICE_AGE_DAYS))
|
||||
if nbr_days <= 0:
|
||||
nbr_days = None
|
||||
except ValueError:
|
||||
nbr_days = None
|
||||
|
||||
if nbr_days is None:
|
||||
_logger.warning("Invalid value for 'auth_totp.trusted_device_age', using default value.")
|
||||
nbr_days = TRUSTED_DEVICE_AGE_DAYS
|
||||
|
||||
return nbr_days * 86400 # seconds
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue