Changeset 4519
- Timestamp:
- 04/27/08 12:18:25 (9 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
projects/tgrepozewho/trunk/tgrepozewho/middleware.py
r4516 r4519 3 3 class SQLAuthenticatorPlugin: 4 4 def __init__(self, user_class, session_factory, user_criterion, 5 user_id_col): #, password_compare):5 user_id_col): 6 6 self.user_class = user_class 7 7 self.user_criterion = user_criterion 8 8 self.session_factory = session_factory 9 #self.compare_fn = password_compare10 9 self.user_id_col = user_id_col 11 10 … … 23 22 24 23 if user: 25 #if self.compare_fn(identity['password'], user.password):26 24 if user.validate_password(identity['password']): 27 25 # 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) 35 29 36 30 class SQLMetadataProviderPlugin: … … 46 40 47 41 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 pass54 55 42 user = query.get(id_) 56 43 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 58 46 identity['user'] = user 59 47 … … 63 51 64 52 # 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] 66 55 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... 70 60 identity['groups'] = list() 71 61 identity['permissions'] = list() 72 73 #def plaintext_password_compare(provided, stored):74 # return provided == stored75 62 76 63 def make_who_middleware(app, config, user_class, user_criterion, user_id_col, … … 78 65 """A sample configuration of repoze.who authentication for TurboGears 2 79 66 """ 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) 82 69 83 70 allmd = SQLMetadataProviderPlugin(user_class, session_factory, … … 96 83 challengers = [('form', form)] 97 84 mdproviders = [('all', allmd)] 98 #mdproviders = [('user', usermd), ('group', groupmd),99 # ('permission', permissionmd)]100 85 101 86 from repoze.who.classifiers import default_challenge_decider