Add logout method
This commit is contained in:
1 parent
c5c72b9724
commit
2f04fe8645
6 files changed
+40
No files matched your search
@@ -1,3 +1,4 @@
|
||||
* Add logout method
|
||||
* Move BrowseRecord cache onto the cursor
|
||||
* Don't order search result if order value is []
|
||||
* Add reload of modules if files have changed
|
||||
|
||||
@@ -36,6 +36,12 @@ def dispatch(host, port, protocol, database_name, user, session, object_type,
|
||||
(msg, user, host, port, protocol, database_name))
|
||||
Cache.resets(database_name)
|
||||
return res or False
|
||||
elif method == 'logout':
|
||||
name = security.logout(database_name, user, session)
|
||||
logger = logging.getLogger('dispatcher')
|
||||
logger.info('logout \'%s\' from %s:%d using %s on database \'%s\'' % \
|
||||
(name, host, port, protocol, database_name))
|
||||
return True
|
||||
elif method == 'version':
|
||||
return VERSION
|
||||
elif method == 'timezone_get':
|
||||
|
||||
@@ -7,6 +7,7 @@ from trytond.wizard import Wizard
|
||||
from lxml import etree
|
||||
from trytond.tools import Cache
|
||||
from trytond.backend import TableHandler
|
||||
from trytond.security import get_connections
|
||||
import string
|
||||
import random
|
||||
|
||||
@@ -38,6 +39,8 @@ class User(ModelSQL, ModelView):
|
||||
status_bar = fields.Function('get_status_bar', type='char',
|
||||
string="Status Bar")
|
||||
warnings = fields.One2Many('res.user.warning', 'user', 'Warnings')
|
||||
connections = fields.Function('get_connections', type='integer',
|
||||
string='Connections')
|
||||
|
||||
def __init__(self):
|
||||
super(User, self).__init__()
|
||||
@@ -108,6 +111,12 @@ class User(ModelSQL, ModelView):
|
||||
res[user.id] = user.name
|
||||
return res
|
||||
|
||||
def get_connections(self, cursor, user, ids, name, arg, context=None):
|
||||
res = {}
|
||||
for user_id in ids:
|
||||
res[user_id] = get_connections(cursor.database_name, user_id)
|
||||
return res
|
||||
|
||||
def _convert_vals(self, cursor, user, vals, context=None):
|
||||
vals = vals.copy()
|
||||
action_obj = self.pool.get('ir.action')
|
||||
|
||||
@@ -99,6 +99,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<tree string="Users">
|
||||
<field name="name" select="1"/>
|
||||
<field name="login" select="1"/>
|
||||
<field name="connections"/>
|
||||
<field name="active" select="1"/>
|
||||
</tree>
|
||||
]]>
|
||||
|
||||
@@ -39,6 +39,7 @@ def login(dbname, loginname, password, cache=True):
|
||||
_USER_CACHE.setdefault(dbname, {})
|
||||
_USER_CACHE[dbname].setdefault(user_id, [])
|
||||
session = Session(user_id)
|
||||
session.name = loginname
|
||||
_USER_CACHE[dbname][user_id].append(session)
|
||||
return (user_id, session.session)
|
||||
else:
|
||||
@@ -52,6 +53,17 @@ def login(dbname, loginname, password, cache=True):
|
||||
_USER_TRY[dbname][0] += 1
|
||||
return False
|
||||
|
||||
def logout(dbname, user, session):
|
||||
name = ''
|
||||
if _USER_CACHE.get(dbname, {}).has_key(user):
|
||||
for i, real_session \
|
||||
in enumerate(_USER_CACHE[dbname][user]):
|
||||
if real_session.session == session:
|
||||
name = real_session.name
|
||||
del _USER_CACHE[dbname][user][i]
|
||||
break
|
||||
return name
|
||||
|
||||
def check_super(passwd):
|
||||
if passwd == CONFIG['admin_passwd']:
|
||||
return True
|
||||
@@ -78,3 +90,13 @@ def check(dbname, user, session):
|
||||
if result:
|
||||
return result
|
||||
raise Exception('NotLogged')
|
||||
|
||||
def get_connections(dbname, user):
|
||||
res = 0
|
||||
now = time.time()
|
||||
timeout = int(CONFIG['session_timeout'])
|
||||
if _USER_CACHE.get(dbname, {}).has_key(int(user)):
|
||||
for i, session in enumerate(_USER_CACHE[dbname][int(user)]):
|
||||
if abs(session.timestamp - now) < timeout:
|
||||
res += 1
|
||||
return res
|
||||
@@ -11,6 +11,7 @@ class Session(int):
|
||||
self.__data = {
|
||||
'session': str(random.random()),
|
||||
'timestamp': time.time(),
|
||||
'name': '',
|
||||
}
|
||||
|
||||
def __getattr__(self, name):
|
||||
|
||||
Reference in new issue
Block a user