2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2010-2011 OpenERP s.a. (<http://openerp.com>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
21 from openerp.osv import osv, fields
22 import openerp.exceptions
27 class res_users(osv.osv):
28 _inherit = 'res.users'
30 # TODO create helper fields for autofill openid_url and openid_email -> http://pad.openerp.com/web-openid
33 'openid_url': fields.char('OpenID URL', size=1024),
34 'openid_email': fields.char('OpenID Email', size=256,
35 help="Used for disambiguation in case of a shared OpenID URL"),
36 'openid_key': fields.char('OpenID Key', size=utils.KEY_LENGTH,
40 def _check_openid_url_email(self, cr, uid, ids, context=None):
41 return all(self.search_count(cr, uid, [('active', '=', True), ('openid_url', '=', u.openid_url), ('openid_email', '=', u.openid_email)]) == 1 \
42 for u in self.browse(cr, uid, ids, context) if u.active and u.openid_url)
44 def _check_openid_url_email_msg(self, cr, uid, ids, context):
45 return "There is already an active user with this OpenID Email for this OpenID URL"
48 (_check_openid_url_email, lambda self, *a, **kw: self._check_openid_url_email_msg(*a, **kw), ['active', 'openid_url', 'openid_email']),
51 def copy(self, cr, uid, rid, defaults=None, context=None):
52 reset_fields = 'openid_url openid_email'.split()
53 reset_values = dict.fromkeys(reset_fields, False)
55 defaults = reset_values
57 defaults = dict(reset_values, **defaults)
59 defaults['openid_key'] = False
60 return super(res_users, self).copy(cr, uid, rid, defaults, context)
62 def login(self, db, login, password):
63 result = super(res_users, self).login(db, login, password)
67 with utils.cursor(db) as cr:
68 cr.execute('UPDATE res_users SET date=now() WHERE login=%s AND openid_key=%s AND active=%s RETURNING id',
69 (tools.ustr(login), tools.ustr(password), True))
72 return res[0] if res else False
75 def check(self, db, uid, passwd):
77 return super(res_users, self).check(db, uid, passwd)
78 except openerp.exceptions.AccessDenied:
81 with utils.cursor(db) as cr:
82 cr.execute('''SELECT COUNT(1)
87 (int(uid), passwd, True))
88 if not cr.fetchone()[0]:
90 self._uid_cache.setdefault(db, {})[uid] = passwd
96 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: