# HG changeset patch # User Marcin Kuzminski # Date 2011-06-28 23:49:53 # Node ID 0d7b56b979534e423a265333d54d84e1c380fa25 # Parent 4134af931e916371d7b33eb6ab04363de12152ba Simplified last_login call on user, and changed login to use User model directly diff --git a/rhodecode/controllers/login.py b/rhodecode/controllers/login.py --- a/rhodecode/controllers/login.py +++ b/rhodecode/controllers/login.py @@ -35,6 +35,7 @@ from pylons import request, response, se import rhodecode.lib.helpers as h from rhodecode.lib.auth import AuthUser, HasPermissionAnyDecorator from rhodecode.lib.base import BaseController, render +from rhodecode.model.db import User from rhodecode.model.forms import LoginForm, RegisterForm, PasswordResetForm from rhodecode.model.user import UserModel @@ -63,7 +64,7 @@ class LoginController(BaseController): c.form_result = login_form.to_python(dict(request.POST)) #form checks for username/password, now we're authenticated username = c.form_result['username'] - user = UserModel().get_by_username(username, + user = User.by_username(username, case_insensitive=True) auth_user = AuthUser(user.user_id) auth_user.set_authenticated() diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -225,31 +225,31 @@ class User(Base, BaseModel): def short_contact(self): return '%s %s' % (self.name, self.lastname) - @property def is_admin(self): return self.admin def __repr__(self): - return "<%s('id:%s:%s')>" % (self.__class__.__name__, - self.user_id, self.username) + try: + return "<%s('id:%s:%s')>" % (self.__class__.__name__, + self.user_id, self.username) + except: + return self.__class__.__name__ @classmethod - def by_username(cls, username): - return Session.query(cls).filter(cls.username == username).one() - + def by_username(cls, username, case_insensitive=False): + if case_insensitive: + return Session.query(cls).filter(cls.username.like(username)).one() + else: + return Session.query(cls).filter(cls.username == username).one() def update_lastlogin(self): """Update user lastlogin""" - try: - session = Session.object_session(self) - self.last_login = datetime.datetime.now() - session.add(self) - session.commit() - log.debug('updated user %s lastlogin', self.username) - except (DatabaseError,): - session.rollback() + self.last_login = datetime.datetime.now() + Session.add(self) + Session.commit() + log.debug('updated user %s lastlogin', self.username) class UserLog(Base, BaseModel): @@ -463,13 +463,13 @@ class Repository(Base, BaseModel): @property def scm_instance(self): - return self.__get_instance(self.repo_name) + return self.__get_instance() @property def scm_instance_cached(self): @cache_region('long_term') def _c(repo_name): - return self.__get_instance(repo_name) + return self.__get_instance() inv = self.invalidate if inv: @@ -481,7 +481,7 @@ class Repository(Base, BaseModel): return _c(self.repo_name) - def __get_instance(self, repo_name): + def __get_instance(self): repo_full_path = self.repo_full_path