|
|
@ -19,6 +19,7 @@ |
|
|
|
# |
|
|
|
############################################################################## |
|
|
|
import logging |
|
|
|
import psycopg2 |
|
|
|
import openerp.exceptions |
|
|
|
from openerp import pooler, SUPERUSER_ID |
|
|
|
from openerp.osv import orm, fields |
|
|
@ -35,6 +36,12 @@ class ResUsersLogin(orm.Model): |
|
|
|
'login_dt': fields.date('Latest connection'), |
|
|
|
} |
|
|
|
|
|
|
|
_sql_constraints = [ |
|
|
|
('user_id_unique', |
|
|
|
'unique(user_id)', |
|
|
|
'The user can only have one login line !') |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
class ResUsers(orm.Model): |
|
|
|
|
|
|
@ -72,13 +79,18 @@ class ResUsers(orm.Model): |
|
|
|
user_id = False |
|
|
|
cr = pooler.get_db(db).cursor() |
|
|
|
try: |
|
|
|
cr.autocommit(True) |
|
|
|
# check if user exists |
|
|
|
res = self.search(cr, SUPERUSER_ID, [('login', '=', login)]) |
|
|
|
if res: |
|
|
|
user_id = res[0] |
|
|
|
try: |
|
|
|
# check credentials |
|
|
|
self.check_credentials(cr, user_id, password) |
|
|
|
except openerp.exceptions.AccessDenied: |
|
|
|
_logger.info("Login failed for db:%s login:%s", db, login) |
|
|
|
user_id = False |
|
|
|
|
|
|
|
if user_id: |
|
|
|
try: |
|
|
|
update_clause = ('NO KEY UPDATE' |
|
|
|
if cr._cnx.server_version >= 90300 |
|
|
@ -96,13 +108,14 @@ class ResUsers(orm.Model): |
|
|
|
cr.execute("UPDATE res_users_login " |
|
|
|
"SET login_dt = now() AT TIME ZONE 'UTC' " |
|
|
|
"WHERE user_id=%s", (user_id,)) |
|
|
|
except Exception: |
|
|
|
_logger.debug("Failed to update last_login " |
|
|
|
cr.commit() |
|
|
|
except psycopg2.OperationalError: |
|
|
|
_logger.warning("Failed to update last_login " |
|
|
|
"for db:%s login:%s", |
|
|
|
db, login, exc_info=True) |
|
|
|
except openerp.exceptions.AccessDenied: |
|
|
|
_logger.info("Login failed for db:%s login:%s", db, login) |
|
|
|
user_id = False |
|
|
|
cr.rollback() |
|
|
|
except Exception: |
|
|
|
pass |
|
|
|
finally: |
|
|
|
cr.close() |
|
|
|
|
|
|
|