comparison rhodecode/lib/auth.py @ 1749:8ecc6b8229a5 beta

commit less models - models don't do any commits(with few exceptions) - all db transactions should be handled by higher level modules like controllers, celery tasks
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 02 Dec 2011 22:31:13 +0200
parents 07e56179633e
children ff788e390497
comparison
equal deleted inserted replaced
1748:a3ee2611e6e8 1749:8ecc6b8229a5
33 from pylons import config, session, url, request 33 from pylons import config, session, url, request
34 from pylons.controllers.util import abort, redirect 34 from pylons.controllers.util import abort, redirect
35 from pylons.i18n.translation import _ 35 from pylons.i18n.translation import _
36 36
37 from rhodecode import __platform__, PLATFORM_WIN, PLATFORM_OTHERS 37 from rhodecode import __platform__, PLATFORM_WIN, PLATFORM_OTHERS
38 from rhodecode.model.meta import Session
38 39
39 if __platform__ in PLATFORM_WIN: 40 if __platform__ in PLATFORM_WIN:
40 from hashlib import sha256 41 from hashlib import sha256
41 if __platform__ in PLATFORM_OTHERS: 42 if __platform__ in PLATFORM_OTHERS:
42 import bcrypt 43 import bcrypt
223 } 224 }
224 225
225 if user_model.create_ldap(username, password, user_dn, 226 if user_model.create_ldap(username, password, user_dn,
226 user_attrs): 227 user_attrs):
227 log.info('created new ldap user %s', username) 228 log.info('created new ldap user %s', username)
228 229
230 Session.commit()
229 return True 231 return True
230 except (LdapUsernameError, LdapPasswordError,): 232 except (LdapUsernameError, LdapPasswordError,):
231 pass 233 pass
232 except (Exception,): 234 except (Exception,):
233 log.error(traceback.format_exc()) 235 log.error(traceback.format_exc())
235 return False 237 return False
236 238
237 def login_container_auth(username): 239 def login_container_auth(username):
238 user = User.get_by_username(username) 240 user = User.get_by_username(username)
239 if user is None: 241 if user is None:
240 user_model = UserModel()
241 user_attrs = { 242 user_attrs = {
242 'name': username, 243 'name': username,
243 'lastname': None, 244 'lastname': None,
244 'email': None, 245 'email': None,
245 } 246 }
246 user = user_model.create_for_container_auth(username, user_attrs) 247 user = UserModel().create_for_container_auth(username, user_attrs)
247 if not user: 248 if not user:
248 return None 249 return None
249 log.info('User %s was created by container authentication', username) 250 log.info('User %s was created by container authentication', username)
250 251
251 if not user.active: 252 if not user.active:
252 return None 253 return None
253 254
254 user.update_lastlogin() 255 user.update_lastlogin()
256 Session.commit()
257
255 log.debug('User %s is now logged in by container authentication', 258 log.debug('User %s is now logged in by container authentication',
256 user.username) 259 user.username)
257 return user 260 return user
258 261
259 def get_container_username(environ, config): 262 def get_container_username(environ, config):
378 :param config: current pylons config instance 381 :param config: current pylons config instance
379 382
380 """ 383 """
381 log.info('getting information about all available permissions') 384 log.info('getting information about all available permissions')
382 try: 385 try:
383 sa = meta.Session() 386 sa = meta.Session
384 all_perms = sa.query(Permission).all() 387 all_perms = sa.query(Permission).all()
385 except: 388 except:
386 pass 389 pass
387 finally: 390 finally:
388 meta.Session.remove() 391 meta.Session.remove()