Changeset - 7e979933ffec
[Not reviewed]
beta
0 5 0
Marcin Kuzminski - 14 years ago 2012-02-23 02:39:35
marcin@python-works.com
more work on improving info logging
5 files changed with 20 insertions and 13 deletions:
0 comments (0 inline, 0 general)
rhodecode/__init__.py
Show inline comments
 
@@ -86,7 +86,7 @@ BACKENDS = {
 
    'git': 'Git repository',
 
}
 

	
 
CELERY_ON = False
 

	
 
# link to config for pylons
 
CONFIG = None
 
CONFIG = {}
rhodecode/lib/auth.py
Show inline comments
 
@@ -170,22 +170,22 @@ def authenticate(username, password):
 
    user = User.get_by_username(username)
 

	
 
    log.debug('Authenticating user using RhodeCode account')
 
    if user is not None and not user.ldap_dn:
 
        if user.active:
 
            if user.username == 'default' and user.active:
 
                log.info('user %s authenticated correctly as anonymous user',
 
                log.info('user %s authenticated correctly as anonymous user' %
 
                         username)
 
                return True
 

	
 
            elif user.username == username and check_password(password,
 
                                                              user.password):
 
                log.info('user %s authenticated correctly' % username)
 
                return True
 
        else:
 
            log.warning('user %s is disabled' % username)
 
            log.warning('user %s tried auth but is disabled' % username)
 

	
 
    else:
 
        log.debug('Regular authentication failed')
 
        user_obj = User.get_by_username(username, case_insensitive=True)
 

	
 
        if user_obj is not None and not user_obj.ldap_dn:
 
@@ -431,19 +431,23 @@ class LoginRequired(object):
 
        if self.api_access:
 
            log.debug('Checking API KEY access for %s' % cls)
 
            if user.api_key == request.GET.get('api_key'):
 
                api_access_ok = True
 
            else:
 
                log.debug("API KEY token not valid")
 

	
 
        log.debug('Checking if %s is authenticated @ %s' % (user.username, cls))
 
        loc = "%s:%s" % (cls.__class__.__name__, func.__name__)
 
        log.debug('Checking if %s is authenticated @ %s' % (user.username, loc))
 
        if user.is_authenticated or api_access_ok:
 
            log.debug('user %s is authenticated' % user.username)
 
            log.info('user %s is authenticated and granted access to %s' % (
 
                       user.username, loc)
 
            )
 
            return func(*fargs, **fkwargs)
 
        else:
 
            log.warn('user %s NOT authenticated' % user.username)
 
            log.warn('user %s NOT authenticated on func: %s' % (
 
                user, loc)
 
            )
 
            p = url.current()
 

	
 
            log.debug('redirecting to login page with %s' % p)
 
            return redirect(url('login_home', came_from=p))
 

	
 

	
 
@@ -499,13 +503,13 @@ class PermsDecorator(object):
 

	
 
        if self.check_permissions():
 
            log.debug('Permission granted for %s %s' % (cls, self.user))
 
            return func(*fargs, **fkwargs)
 

	
 
        else:
 
            log.warning('Permission denied for %s %s' % (cls, self.user))
 
            log.debug('Permission denied for %s %s' % (cls, self.user))
 
            anonymous = self.user.username == 'default'
 

	
 
            if anonymous:
 
                p = url.current()
 

	
 
                import rhodecode.lib.helpers as h
 
@@ -646,13 +650,13 @@ class PermsFunction(object):
 
        if self.check_permissions():
 
            log.debug('Permission granted %s @ %s', self.granted_for,
 
                      check_Location or 'unspecified location')
 
            return True
 

	
 
        else:
 
            log.warning('Permission denied for %s @ %s', self.granted_for,
 
            log.debug('Permission denied for %s @ %s', self.granted_for,
 
                        check_Location or 'unspecified location')
 
            return False
 

	
 
    def check_permissions(self):
 
        """Dummy function for overriding"""
 
        raise Exception('You have to write this function in child class')
rhodecode/lib/base.py
Show inline comments
 
@@ -144,15 +144,18 @@ class BaseController(WSGIController):
 
                       self.rhodecode_user.user_id is not None:
 
                self.rhodecode_user\
 
                    .set_authenticated(cookie_store.get('is_authenticated'))
 

	
 
            session['rhodecode_user'] = self.rhodecode_user.get_cookie_store()
 
            session.save()
 
            log.info('User: %s accessed %s' % (auth_user, 
 
                                               environ.get('PATH_INFO')))
 
            return WSGIController.__call__(self, environ, start_response)
 
        finally:
 
            log.debug('Request time: %.3fs' % (time.time() - start))
 
            log.info('Request to %s time: %.3fs' % (environ.get('PATH_INFO'),
 
                                                    time.time() - start))
 
            meta.Session.remove()
 

	
 

	
 
class BaseRepoController(BaseController):
 
    """
 
    Base class for controllers responsible for loading all needed data for
rhodecode/lib/vcs/utils/__init__.py
Show inline comments
 
@@ -39,13 +39,13 @@ def safe_unicode(str_, from_encoding=Non
 
    :returns: unicode object
 
    """
 
    if isinstance(str_, unicode):
 
        return str_
 
    if not from_encoding:
 
        import rhodecode
 
        DEFAULT_ENCODING = rhodecode.CONFIG.get('default_encoding','utf8')
 
        DEFAULT_ENCODING = rhodecode.CONFIG.get('default_encoding', 'utf8')
 
        from_encoding = DEFAULT_ENCODING
 
    try:
 
        return unicode(str_)
 
    except UnicodeDecodeError:
 
        pass
 

	
 
@@ -77,13 +77,13 @@ def safe_str(unicode_, to_encoding=None)
 
    """
 

	
 
    if isinstance(unicode_, str):
 
        return unicode_
 
    if not to_encoding:
 
        import rhodecode
 
        DEFAULT_ENCODING = rhodecode.CONFIG.get('default_encoding','utf8')
 
        DEFAULT_ENCODING = rhodecode.CONFIG.get('default_encoding', 'utf8')
 
        to_encoding = DEFAULT_ENCODING
 
    try:
 
        return unicode_.encode(to_encoding)
 
    except UnicodeEncodeError:
 
        pass
 

	
rhodecode/model/forms.py
Show inline comments
 
@@ -253,13 +253,13 @@ class ValidAuth(formencode.validators.Fa
 
                    self.message('disabled_account',
 
                    state=State_obj),
 
                    value, state,
 
                    error_dict=self.e_dict_disable
 
                )
 
            else:
 
                log.warning('user %s not authenticated' % username)
 
                log.warning('user %s failed to authenticate' % username)
 
                raise formencode.Invalid(
 
                    self.message('invalid_password',
 
                    state=State_obj), value, state,
 
                    error_dict=self.e_dict
 
                )
 

	
0 comments (0 inline, 0 general)