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.

51 lines
1.9 KiB

  1. # -*- coding: utf-8 -*-
  2. # Florent de Labarre - 2016
  3. import openerp
  4. from openerp import api, fields, models
  5. class ResUsers(models.Model):
  6. _inherit = 'res.users'
  7. oauth_access_token_ids = fields.One2many('auth.oauth.multi.token', 'user_id', 'Tokens', copy=False)
  8. oauth_access_max_token = fields.Integer('Number of simultaneous connections', default=5, required=True)
  9. @api.model
  10. def _auth_oauth_signin(self, provider, validation, params):
  11. res = super(ResUsers, self)._auth_oauth_signin(provider, validation, params)
  12. oauth_uid = validation['user_id']
  13. user_ids = self.search([('oauth_uid', '=', oauth_uid), ('oauth_provider_id', '=', provider)]).ids
  14. if not user_ids:
  15. raise openerp.exceptions.AccessDenied()
  16. assert len(user_ids) == 1
  17. self.oauth_access_token_ids.create({'user_id': user_ids[0],
  18. 'oauth_access_token': params['access_token'],
  19. 'active_token': True,
  20. })
  21. return res
  22. @api.multi
  23. def clear_token(self):
  24. for users in self:
  25. for token in users.oauth_access_token_ids:
  26. token.write({
  27. 'oauth_access_token': "****************************",
  28. 'active_token': False})
  29. @api.model
  30. def check_credentials(self, password):
  31. try:
  32. return super(ResUsers, self).check_credentials(password)
  33. except openerp.exceptions.AccessDenied:
  34. res = self.env['auth.oauth.multi.token'].sudo().search([
  35. ('user_id', '=', self.env.uid),
  36. ('oauth_access_token', '=', password),
  37. ('active_token', '=', True),
  38. ])
  39. if not res:
  40. raise
  41. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: