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.

36 lines
1.1 KiB

9 years ago
9 years ago
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2015 GRAP - Sylvain LE GAL
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo import _, api, fields, models
  5. class ResAuthenticationAttempt(models.Model):
  6. _name = 'res.authentication.attempt'
  7. _order = 'attempt_date desc'
  8. _ATTEMPT_RESULT = [
  9. ('successfull', _('Successfull')),
  10. ('failed', _('Failed')),
  11. ('banned', _('Banned')),
  12. ]
  13. # Column Section
  14. attempt_date = fields.Datetime(string='Attempt Date')
  15. login = fields.Char(string='Tried Login')
  16. remote = fields.Char(string='Remote ID')
  17. result = fields.Selection(
  18. selection=_ATTEMPT_RESULT, string='Authentication Result')
  19. # Custom Section
  20. @api.model
  21. def search_last_failed(self, remote):
  22. last_ok = self.search(
  23. [('result', '=', 'successfull'), ('remote', '=', remote)],
  24. order='attempt_date desc', limit=1)
  25. if last_ok:
  26. return self.search([
  27. ('remote', '=', remote),
  28. ('attempt_date', '>', last_ok.attempt_date)])
  29. else:
  30. return self.search([('remote', '=', remote)])