Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(198)

Side by Side Diff: trytond/security.py

Issue 1864045: Remove cursor, user and context instead use a Transaction (Closed)
Patch Set: Better Report.parse signature Created 14 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « trytond/res/user.py ('k') | trytond/test/model.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #This file is part of Tryton. The COPYRIGHT file at the top level of 1 #This file is part of Tryton. The COPYRIGHT file at the top level of
2 #this repository contains the full copyright notices and license terms. 2 #this repository contains the full copyright notices and license terms.
3 from __future__ import with_statement
3 from trytond.backend import Database 4 from trytond.backend import Database
4 from trytond.session import Session 5 from trytond.session import Session
5 from trytond.pool import Pool 6 from trytond.pool import Pool
6 from trytond.config import CONFIG 7 from trytond.config import CONFIG
8 from trytond.transaction import Transaction
7 import time 9 import time
8 10
9 11
10 _USER_CACHE = {} 12 _USER_CACHE = {}
11 _USER_TRY = {} 13 _USER_TRY = {}
12 14
13 def login(dbname, loginname, password, cache=True): 15 def login(dbname, loginname, password, cache=True):
14 _USER_TRY.setdefault(dbname, {}) 16 _USER_TRY.setdefault(dbname, {})
15 _USER_TRY[dbname].setdefault(loginname, 0) 17 _USER_TRY[dbname].setdefault(loginname, 0)
16 database = Database(dbname).connect() 18 with Transaction().start(dbname, 0) as transaction:
17 cursor = database.cursor() 19 database_list = Pool.database_list()
18 database_list = Pool.database_list() 20 pool = Pool(dbname)
19 pool = Pool(dbname) 21 if not dbname in database_list:
20 if not dbname in database_list: 22 pool.init()
21 pool.init() 23 user_obj = pool.get('res.user')
22 user_obj = pool.get('res.user') 24 password = password.decode('utf-8')
23 password = password.decode('utf-8') 25 user_id = user_obj.get_login(loginname, password)
24 user_id = user_obj.get_login(cursor, 0, loginname, password) 26 transaction.cursor.commit()
25 cursor.commit()
26 cursor.close()
27 if user_id: 27 if user_id:
28 _USER_TRY[dbname][loginname] = 0 28 _USER_TRY[dbname][loginname] = 0
29 if cache: 29 if cache:
30 _USER_CACHE.setdefault(dbname, {}) 30 _USER_CACHE.setdefault(dbname, {})
31 _USER_CACHE[dbname].setdefault(user_id, []) 31 _USER_CACHE[dbname].setdefault(user_id, [])
32 session = Session(user_id) 32 session = Session(user_id)
33 session.name = loginname 33 session.name = loginname
34 _USER_CACHE[dbname][user_id].append(session) 34 _USER_CACHE[dbname][user_id].append(session)
35 return (user_id, session.session) 35 return (user_id, session.session)
36 else: 36 else:
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 79
80 def get_connections(dbname, user): 80 def get_connections(dbname, user):
81 res = 0 81 res = 0
82 now = time.time() 82 now = time.time()
83 timeout = int(CONFIG['session_timeout']) 83 timeout = int(CONFIG['session_timeout'])
84 if _USER_CACHE.get(dbname, {}).has_key(int(user)): 84 if _USER_CACHE.get(dbname, {}).has_key(int(user)):
85 for _, session in enumerate(_USER_CACHE[dbname][int(user)]): 85 for _, session in enumerate(_USER_CACHE[dbname][int(user)]):
86 if abs(session.timestamp - now) < timeout: 86 if abs(session.timestamp - now) < timeout:
87 res += 1 87 res += 1
88 return res 88 return res
OLDNEW
« no previous file with comments | « trytond/res/user.py ('k') | trytond/test/model.py » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b