##// END OF EJS Templates
Simplified last_login call on user, and changed login to use User model directly
marcink -
r1400:0d7b56b9 beta
parent child Browse files
Show More
@@ -35,6 +35,7 b' from pylons import request, response, se'
35 import rhodecode.lib.helpers as h
35 import rhodecode.lib.helpers as h
36 from rhodecode.lib.auth import AuthUser, HasPermissionAnyDecorator
36 from rhodecode.lib.auth import AuthUser, HasPermissionAnyDecorator
37 from rhodecode.lib.base import BaseController, render
37 from rhodecode.lib.base import BaseController, render
38 from rhodecode.model.db import User
38 from rhodecode.model.forms import LoginForm, RegisterForm, PasswordResetForm
39 from rhodecode.model.forms import LoginForm, RegisterForm, PasswordResetForm
39 from rhodecode.model.user import UserModel
40 from rhodecode.model.user import UserModel
40
41
@@ -63,7 +64,7 b' class LoginController(BaseController):'
63 c.form_result = login_form.to_python(dict(request.POST))
64 c.form_result = login_form.to_python(dict(request.POST))
64 #form checks for username/password, now we're authenticated
65 #form checks for username/password, now we're authenticated
65 username = c.form_result['username']
66 username = c.form_result['username']
66 user = UserModel().get_by_username(username,
67 user = User.by_username(username,
67 case_insensitive=True)
68 case_insensitive=True)
68 auth_user = AuthUser(user.user_id)
69 auth_user = AuthUser(user.user_id)
69 auth_user.set_authenticated()
70 auth_user.set_authenticated()
@@ -225,31 +225,31 b' class User(Base, BaseModel):'
225 def short_contact(self):
225 def short_contact(self):
226 return '%s %s' % (self.name, self.lastname)
226 return '%s %s' % (self.name, self.lastname)
227
227
228
229 @property
228 @property
230 def is_admin(self):
229 def is_admin(self):
231 return self.admin
230 return self.admin
232
231
233 def __repr__(self):
232 def __repr__(self):
234 return "<%s('id:%s:%s')>" % (self.__class__.__name__,
233 try:
235 self.user_id, self.username)
234 return "<%s('id:%s:%s')>" % (self.__class__.__name__,
235 self.user_id, self.username)
236 except:
237 return self.__class__.__name__
236
238
237 @classmethod
239 @classmethod
238 def by_username(cls, username):
240 def by_username(cls, username, case_insensitive=False):
239 return Session.query(cls).filter(cls.username == username).one()
241 if case_insensitive:
240
242 return Session.query(cls).filter(cls.username.like(username)).one()
243 else:
244 return Session.query(cls).filter(cls.username == username).one()
241
245
242 def update_lastlogin(self):
246 def update_lastlogin(self):
243 """Update user lastlogin"""
247 """Update user lastlogin"""
244
248
245 try:
249 self.last_login = datetime.datetime.now()
246 session = Session.object_session(self)
250 Session.add(self)
247 self.last_login = datetime.datetime.now()
251 Session.commit()
248 session.add(self)
252 log.debug('updated user %s lastlogin', self.username)
249 session.commit()
250 log.debug('updated user %s lastlogin', self.username)
251 except (DatabaseError,):
252 session.rollback()
253
253
254
254
255 class UserLog(Base, BaseModel):
255 class UserLog(Base, BaseModel):
@@ -463,13 +463,13 b' class Repository(Base, BaseModel):'
463
463
464 @property
464 @property
465 def scm_instance(self):
465 def scm_instance(self):
466 return self.__get_instance(self.repo_name)
466 return self.__get_instance()
467
467
468 @property
468 @property
469 def scm_instance_cached(self):
469 def scm_instance_cached(self):
470 @cache_region('long_term')
470 @cache_region('long_term')
471 def _c(repo_name):
471 def _c(repo_name):
472 return self.__get_instance(repo_name)
472 return self.__get_instance()
473
473
474 inv = self.invalidate
474 inv = self.invalidate
475 if inv:
475 if inv:
@@ -481,7 +481,7 b' class Repository(Base, BaseModel):'
481
481
482 return _c(self.repo_name)
482 return _c(self.repo_name)
483
483
484 def __get_instance(self, repo_name):
484 def __get_instance(self):
485
485
486 repo_full_path = self.repo_full_path
486 repo_full_path = self.repo_full_path
487
487
General Comments 0
You need to be logged in to leave comments. Login now