Changeset 4519

Show
Ignore:
Timestamp:
04/27/08 12:18:25 (9 months ago)
Author:
chrism
Message:

Remove code which attempted to convert ids into integers; this depends on repoze.who 0.9.1.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • projects/tgrepozewho/trunk/tgrepozewho/middleware.py

    r4516 r4519  
    33class SQLAuthenticatorPlugin: 
    44    def __init__(self, user_class, session_factory, user_criterion, 
    5             user_id_col): #, password_compare): 
     5            user_id_col): 
    66        self.user_class = user_class 
    77        self.user_criterion = user_criterion 
    88        self.session_factory = session_factory 
    9         #self.compare_fn = password_compare 
    109        self.user_id_col = user_id_col 
    1110 
     
    2322 
    2423        if user: 
    25             #if self.compare_fn(identity['password'], user.password): 
    2624            if user.validate_password(identity['password']): 
    2725                # grab the attr value that serves as a unique identifier 
    28                 # for the user column 
    29                 id_ = getattr(user, self.user_id_col) 
    30  
    31                 if isinstance(id_, int): 
    32                     id_ = unicode(id_) 
    33  
    34                 return id_ 
     26                # for the user column; this may be either an integer, 
     27                # a string, or a unicode value 
     28                return getattr(user, self.user_id_col) 
    3529 
    3630class SQLMetadataProviderPlugin: 
     
    4640 
    4741        id_ = identity['repoze.who.userid'] 
    48  
    49         # if id_ is convertable to int then do so... this is an ugly hack :( 
    50         try: 
    51             id_ = int(id) 
    52         except: 
    53             pass 
    54  
    5542        user = query.get(id_) 
    5643 
    57         # at this point, identity['user'] is either None or a yourapp.model.User class 
     44        # at this point, identity['user'] is either None or a 
     45        # yourapp.model.User class 
    5846        identity['user'] = user 
    5947 
     
    6351 
    6452            # identity['permissions'] will be a list of permission names 
    65             identity['permissions'] = [permission.permission_name for permission in user.permissions] 
     53            identity['permissions'] = [permission.permission_name for 
     54                                       permission in user.permissions] 
    6655        else: 
    67             # TODO: I'd like a to be able to give permissions to anonymous users explicitly 
    68             # this means passing a default user object to the sql authenticator so it can be injected 
    69             # when the user is not found... 
     56            # TODO: I'd like a to be able to give permissions to 
     57            # anonymous users explicitly this means passing a default 
     58            # user object to the sql authenticator so it can be 
     59            # injected when the user is not found... 
    7060            identity['groups'] = list() 
    7161            identity['permissions'] = list() 
    72  
    73 #def plaintext_password_compare(provided, stored): 
    74 #    return provided == stored 
    7562 
    7663def make_who_middleware(app, config, user_class, user_criterion, user_id_col, 
     
    7865    """A sample configuration of repoze.who authentication for TurboGears 2 
    7966    """ 
    80     sqlauth = SQLAuthenticatorPlugin(user_class, session_factory, user_criterion, 
    81             user_id_col) #, plaintext_password_compare
     67    sqlauth = SQLAuthenticatorPlugin(user_class, session_factory, 
     68                                     user_criterion, user_id_col
    8269 
    8370    allmd = SQLMetadataProviderPlugin(user_class, session_factory, 
     
    9683    challengers = [('form', form)] 
    9784    mdproviders = [('all', allmd)] 
    98     #mdproviders = [('user', usermd), ('group', groupmd), 
    99     #                ('permission', permissionmd)] 
    10085 
    10186    from repoze.who.classifiers import default_challenge_decider