Files
tryton/trytond/security.py
T
ced@b2ck.com 9d971a0008 Initial commit
- add license
- add run script
- add config parser
- add service object
- add web_service
- add workflow
- add osv/orm/fields
- add module management
- add ir module
2007-12-10 01:04:13 +01:00

38 lines
1.0 KiB
Python

import pooler
from config import CONFIG
_USER_CACHE = {}
def login(dbname, loginname, password):
cursor = pooler.get_db(dbname).cursor()
cursor.execute('SELECT id FROM res_users '
'WHERE login = %s and password = %s and active',
(loginname.encode('utf-8'), password.encode('utf-8')))
res = cursor.fetchone()
cursor.close()
if res:
return res[0]
else:
return False
def check_super(passwd):
if passwd == CONFIG['admin_passwd']:
return True
else:
raise Exception('AccessDenied')
def check(dbname, user, passwd):
# FIXME: this should be db dependent
if _USER_CACHE.has_key(user) and (_USER_CACHE[user]==passwd):
return True
cursor = pooler.get_db(dbname).cursor()
cursor.execute('SELECT count(*) FROM res_users ' \
'WHERE id = %d AND password = %s', (int(user), passwd))
res = cursor.fetchone()[0]
cursor.close()
if not bool(res):
raise Exception('AccessDenied')
if res:
_USER_CACHE[user] = passwd
return bool(res)