Changeset 988
- Timestamp:
- 07/02/06 13:22:07 (2 years ago)
- Files:
-
- accountmanagerplugin/sandbox/modular/acct_mgr/api.py (modified) (6 diffs)
- accountmanagerplugin/sandbox/modular/acct_mgr/htfile.py (deleted)
- accountmanagerplugin/sandbox/modular/acct_mgr/__init__.py (modified) (1 diff)
- accountmanagerplugin/sandbox/modular/acct_mgr/md5crypt.py (deleted)
- accountmanagerplugin/sandbox/modular/acct_mgr/model.py (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
accountmanagerplugin/sandbox/modular/acct_mgr/api.py
r706 r988 11 11 12 12 from trac.core import * 13 from trac.config import * 13 14 14 class IPasswordStore(Interface): 15 """An interface for Components that provide a storage method for users and 16 passwords. 17 """ 15 class AccountError(TracError): 16 """ A generic account error. """ 18 17 19 def config_key(self):20 """Returns a string used to identify this implementation in the config.21 This password storage implementation will be used if the value of 22 the config property "account-manager.password_format" matches. 23 """18 class UnknownUserError(AccountError): 19 """ Raise this on an action against an unknown user name. """ 20 21 class IAccountStore(Interface): 22 """An interface for Components that provide a storage method for accounts.""" 24 23 25 24 def get_users(self): … … 30 29 """Returns whether the user account exists. 31 30 """ 31 32 def add_user(self, user): 33 """Create a new user. 34 """ 35 36 def delete_user(self, user): 37 """Deletes the user account.""" 38 39 class IPasswordStore(Interface): 40 """An interface for Components that provide a storage method for passwords.""" 32 41 33 42 def set_password(self, user, password): 34 """Sets the password for the user. This should create the user account 35 if it doesn't already exist. 36 Returns True if a new account was created, False if an existing account 37 was updated. 43 """Sets the password for the user. If you do not define this 44 method, it is assumed you cannot change passwords in this store. 38 45 """ 39 46 … … 42 49 """ 43 50 44 def delete_user(self, user):45 """Deletes the user account.46 Returns True if the account existed and was deleted, False otherwise.47 """48 49 51 class IAccountChangeListener(Interface): 50 52 """An interface for receiving account change events. 51 53 """ 52 54 53 def user_created(self, user , password):55 def user_created(self, user): 54 56 """New user 55 57 """ 56 58 57 def user_password_changed(self, user , password):59 def user_password_changed(self, user): 58 60 """Password changed 59 61 """ … … 63 65 """ 64 66 67 class IAccountActionController(Interface): 68 """An interface for providing and manipluation account actions. 69 """ 70 71 def get_account_actions(req, account): 72 """ Return an interable of (action, label). 73 """ 74 75 def apply_account_action(req, account, action): 76 """ Perform the given action on an account. 77 """ 78 79 def intercept_account_action(req, account, action): 80 """ Intercept, and possibly alter, an account action. 81 """ 82 65 83 class AccountManager(Component): 66 84 """The AccountManager component handles all user account management methods 67 provided by the I PasswordStore interface.85 provided by the IAccountStore and IPasswordStore interfaces. 68 86 69 87 The methods will be handled by the underlying password storage … … 74 92 implements(IAccountChangeListener) 75 93 76 stores = ExtensionPoint(IPasswordStore) 94 account_store = OrderedExtensionsOption('account-manager','account_store',IAccountStore, 95 include_missing=False, 96 doc="Which account storage backends to use.") 97 98 password_store = OrderedExtensionsOption('account-manager','password_store',IPasswordStore, 99 include_missing=False, 100 doc="Which password storage backends to use.") 101 77 102 change_listeners = ExtensionPoint(IAccountChangeListener) 103 action_controllers = ExtensionPoint(IAccountActionController) 104 105 store_key = Option('account-manager','password_format', 106 doc='Short-code for the desired password store') 78 107 79 108 # Public API 109 110 def account_actions(self, req, user): 111 """Return a dictionary of the form {action:(label, controller)}.""" 112 actions = {} 113 for controller in self.action_controllers: 114 for action, label in controller.get_account_actions(req, user) 115 assert action not in actions, "Action %s already registered by %s" % \ 116 (action, actions[action][1].__class__.__name__) 117 actions[action] = (label, controller) 118 return actions 80 119 81 120 def get_users(self): 82 return self.password_store.get_users() 121 for store in self.account_stores: 122 for user in store.get_users(): 123 yield user 83 124 84 125 def has_user(self, user): 85 return self.password_store.has_user(user) 86 87 def set_password(self, user, password): 88 if self.password_store.set_password(user, password): 89 self._notify('created', user, password) 90 else: 91 self._notify('password_changed', user, password) 92 93 def check_password(self, user, password): 94 return self.password_store.check_password(user, password) 95 96 def delete_user(self, user): 97 if self.password_store.delete_user(user): 98 self._notify('deleted', user) 99 100 def password_store(self): 101 fmt = self.config.get('account-manager', 'password_format') 102 for store in self.stores: 103 if store.config_key() == fmt: 104 return store 105 raise TracError('No password store found. Please configure ' 106 '"account-manager.password_format" in trac.ini.') 107 password_store = property(password_store) 108 109 def _notify(self, func, *args): 110 func = 'user_' + func 111 for l in self.change_listeners: 112 getattr(l, func)(*args) 113 126 for store in self.account_stores: 127 if store.has_user(user): 128 return True 129 return False 130 114 131 # IAccountChangeListener methods 115 132 … … 117 134 self.log.info('Created new user: %s' % user) 118 135 119 def user_password_changed(self, user , password):136 def user_password_changed(self, user): 120 137 self.log.info('Updated password for user: %s' % user) 121 138 accountmanagerplugin/sandbox/modular/acct_mgr/__init__.py
r76 r988 1 from acct_mgr.api import *2 from acct_mgr.htfile import *3 from acct_mgr.web_ui import *
