From d041c995efaea91c5bdbd999d4b3b95bdad20fa5 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Fri, 21 Mar 2014 14:03:56 +0100 Subject: [PATCH] [IMP] move 'if' test to avoid useless call to check_credentials function if user_id == SUPERUSER_ID. (Courtesy of Stefan Rijnhart). --- auth_admin_passkey/model/res_users.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/auth_admin_passkey/model/res_users.py b/auth_admin_passkey/model/res_users.py index 9cc6599dc..3172a1f40 100644 --- a/auth_admin_passkey/model/res_users.py +++ b/auth_admin_passkey/model/res_users.py @@ -47,18 +47,18 @@ class res_users(Model): """ Authenticate the user 'login' is password is ok or if is admin password. In the second case, send mail to user and admin.""" user_id = super(res_users, self).authenticate(db, login, password, user_agent_env) - cr = pooler.get_db(db).cursor() - try: - # directly use parent 'check_credentials' function - # to really know if credentials are ok and if it's admin password - super(res_users, self).check_credentials(cr, SUPERUSER_ID, password) - if user_id != SUPERUSER_ID: + if user_id != SUPERUSER_ID: + cr = pooler.get_db(db).cursor() + try: + # directly use parent 'check_credentials' function + # to really know if credentials are ok or if it was admin password + super(res_users, self).check_credentials(cr, SUPERUSER_ID, password) self._send_email_passkey(cr, user_id, user_agent_env) cr.commit() - except exceptions.AccessDenied: - pass - finally: - cr.close() + except exceptions.AccessDenied: + pass + finally: + cr.close() return user_id def check_credentials(self, cr, uid, password):