Changeset - 95bc1801d480
[Not reviewed]
default
0 2 0
Søren Løvborg - 10 years ago 2015-09-09 12:21:25
sorenl@unity3d.com
auth: inline AuthUser.set_authenticated

This makes the following commits easier to follow, and makes it more
explicit that something weird is going on, with more cleanup needed.
2 files changed with 4 insertions and 6 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/auth.py
Show inline comments
 
@@ -623,16 +623,12 @@ class AuthUser(object):
 
            return False
 

	
 
    def __repr__(self):
 
        return "<AuthUser('id:%s[%s] auth:%s')>"\
 
            % (self.user_id, self.username, self.is_authenticated)
 

	
 
    def set_authenticated(self, authenticated=True):
 
        if not self.is_default_user:
 
            self.is_authenticated = authenticated
 

	
 
    def to_cookie(self):
 
        """ Serializes this login session to a cookie `dict`. """
 
        return {
 
            'user_id': self.user_id,
 
            'is_authenticated': self.is_authenticated,
 
            'is_external_auth': self.is_external_auth,
 
@@ -647,13 +643,14 @@ class AuthUser(object):
 
        au = AuthUser(
 
            user_id=cookie.get('user_id'),
 
            is_external_auth=cookie.get('is_external_auth', False),
 
        )
 
        if not au.is_authenticated and au.user_id is not None:
 
            # user is not authenticated and not empty
 
            au.set_authenticated(cookie.get('is_authenticated'))
 
            if not au.is_default_user:
 
                au.is_authenticated = cookie.get('is_authenticated')
 
        return au
 

	
 
    @classmethod
 
    def get_allowed_ips(cls, user_id, cache=False, inherit_from_default=False):
 
        _set = set()
 

	
kallithea/lib/base.py
Show inline comments
 
@@ -113,13 +113,14 @@ def log_in_user(user, remember, is_exter
 
    """
 
    user.update_lastlogin()
 
    meta.Session().commit()
 

	
 
    auth_user = AuthUser(dbuser=user,
 
                         is_external_auth=is_external_auth)
 
    auth_user.set_authenticated()
 
    if not auth_user.is_default_user:
 
        auth_user.is_authenticated = True
 

	
 
    # Start new session to prevent session fixation attacks.
 
    session.invalidate()
 
    session['authuser'] = cookie = auth_user.to_cookie()
 

	
 
    # If they want to be remembered, update the cookie.
0 comments (0 inline, 0 general)