diff options
| author | Yannick Tivisse <yti@odoo.com> | 2016-07-29 15:17:03 +0200 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2016-07-29 15:17:03 +0200 |
| commit | 6a4899ea8f53a2dd355b49ee1c1fb475235a3d79 (patch) | |
| tree | 008e9749d2937872dc05823a4620ea6e43b4c992 /addons/auth_ldap/models/res_users.py | |
| parent | e6ab21be581729fbacc95639757d8e4916d3be00 (diff) | |
| parent | c4c716579a73af80cd4c86fdc6f29226225d9af6 (diff) | |
[MERGE] auth_ldap: Migrate to new API
Diffstat (limited to 'addons/auth_ldap/models/res_users.py')
| -rw-r--r-- | addons/auth_ldap/models/res_users.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/addons/auth_ldap/models/res_users.py b/addons/auth_ldap/models/res_users.py new file mode 100644 index 00000000000..e527f86f2a1 --- /dev/null +++ b/addons/auth_ldap/models/res_users.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.exceptions import AccessDenied + +from odoo import api, models, registry, SUPERUSER_ID + + +class Users(models.Model): + _inherit = "res.users" + + def _login(self, db, login, password): + user_id = super(Users, self)._login(db, login, password) + if user_id: + return user_id + with registry(db).cursor() as cr: + env = api.Environment(cr, SUPERUSER_ID, {}) + cr.execute("SELECT id FROM res_users WHERE lower(login)=%s", (login,)) + res = cr.fetchone() + if res: + return False + Ldap = env['res.company.ldap'] + for conf in Ldap.get_ldap_dicts(): + entry = Ldap.authenticate(conf, login, password) + if entry: + user_id = Ldap.sudo().get_or_create_user(conf, login, entry) + if user_id: + break + return user_id + + @api.model + def check_credentials(self, password): + try: + super(Users, self).check_credentials(password) + except AccessDenied: + if self.env.user.active: + Ldap = self.env['res.company.ldap'] + for conf in Ldap.get_ldap_dicts(): + if Ldap.authenticate(conf, self.env.user.login, password): + return + raise |
