Changeset 1549
- Timestamp:
- 11/12/06 23:48:39 (2 years ago)
- Files:
-
- accountmanagerplugin/0.10/acct_mgr/admin.py (modified) (1 diff)
- accountmanagerplugin/0.10/acct_mgr/api.py (modified) (1 diff)
- accountmanagerplugin/0.10/acct_mgr/http.py (added)
- accountmanagerplugin/0.10/acct_mgr/templates/account.cs (modified) (2 diffs)
- accountmanagerplugin/0.10/acct_mgr/templates/admin_users.cs (modified) (3 diffs)
- accountmanagerplugin/0.10/acct_mgr/web_ui.py (modified) (5 diffs)
- accountmanagerplugin/0.10/setup.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
accountmanagerplugin/0.10/acct_mgr/admin.py
r1548 r1549 80 80 def _do_users(self, req): 81 81 perm = PermissionSystem(self.env) 82 listing_enabled = self.account_manager.supports('get_users') 83 create_enabled = self.account_manager.supports('set_password') 84 delete_enabled = self.account_manager.supports('delete_user') 85 86 req.hdf['listing_enabled'] = listing_enabled 87 req.hdf['create_enabled'] = create_enabled 88 req.hdf['delete_enabled'] = delete_enabled 89 82 90 if req.method == 'POST': 83 91 if req.args.get('add'): 84 try: 85 _create_user(req, self.env, check_permissions=False) 86 except TracError, e: 87 req.hdf['registration.error'] = e.message 92 if create_enabled: 93 try: 94 _create_user(req, self.env, check_permissions=False) 95 except TracError, e: 96 req.hdf['registration.error'] = e.message 97 else: 98 req.hdf['registration_error'] = 'The password store does ' \ 99 'not support creating users' 88 100 elif req.args.get('remove'): 89 sel = req.args.get('sel') 90 sel = isinstance(sel, list) and sel or [sel] 91 for account in sel: 92 self.account_manager.delete_user(account) 101 if delete_enabled: 102 sel = req.args.get('sel') 103 sel = isinstance(sel, list) and sel or [sel] 104 for account in sel: 105 self.account_manager.delete_user(account) 106 else: 107 req.hdf['deletion_error'] = 'The password store does not ' \ 108 'support deleting users' 109 if listing_enabled: 110 accounts = {} 111 for username in self.account_manager.get_users(): 112 accounts[username] = {'username': username} 93 113 94 accounts = {} 95 for username in self.account_manager.get_users(): 96 accounts[username] = {'username': username} 114 for username, name, email in self.env.get_known_users(): 115 account = accounts.get(username) 116 if account: 117 account['name'] = name 118 account['email'] = email 97 119 98 for username, name, email in self.env.get_known_users(): 99 account = accounts.get(username) 100 if account: 101 account['name'] = name 102 account['email'] = email 120 db = self.env.get_db_cnx() 121 cursor = db.cursor() 122 cursor.execute("SELECT sid,last_visit FROM session WHERE authenticated=1") 123 for username, last_visit in cursor: 124 account = accounts.get(username) 125 if account and last_visit: 126 account['last_visit'] = format_datetime(last_visit) 103 127 104 db = self.env.get_db_cnx() 105 cursor = db.cursor() 106 cursor.execute("SELECT sid,last_visit FROM session WHERE authenticated=1") 107 for username, last_visit in cursor: 108 account = accounts.get(username) 109 if account and last_visit: 110 account['last_visit'] = format_datetime(last_visit) 111 112 req.hdf['accounts'] = sorted(accounts.itervalues(), 113 key=lambda acct: acct['username']) 128 req.hdf['accounts'] = sorted(accounts.itervalues(), 129 key=lambda acct: acct['username']) 114 130 115 131 return 'admin_users.cs', None accountmanagerplugin/0.10/acct_mgr/api.py
r1068 r1549 108 108 self._notify('deleted', user) 109 109 110 def supports(self, operation): 111 return hasattr(self.password_store, operation) 112 110 113 def password_store(self): 111 114 try: accountmanagerplugin/0.10/acct_mgr/templates/account.cs
r76 r1549 38 38 </form> 39 39 40 <?cs if:delete_enabled ?> 40 41 <form method="post" action="" 41 42 onsubmit="return confirm('Are you sure you want to delete your account?');"> … … 43 44 <input type="submit" value="Delete account" /> 44 45 </form> 46 <?cs /if ?> 45 47 46 48 </div> accountmanagerplugin/0.10/acct_mgr/templates/admin_users.cs
r1548 r1549 1 1 <h2>Manage User Accounts</h2> 2 2 3 <?cs if:create_enabled ?> 3 4 <form id="addaccount" class="addnew" method="post"> 4 5 <fieldset> … … 29 30 </fieldset> 30 31 </form> 32 <?cs /if ?> 31 33 34 <?cs if:!listing_enabled ?> 35 <div class="system-message"> 36 <p>This password store does not support listing users</p> 37 </div> 38 <?cs else ?> 32 39 <form method="post"> 40 <?cs if:deletion_error ?><div class="system-message"><p><?cs var:deletion_error ?></p></div><?cs /if ?> 33 41 <table class="listing" id="accountlist"> 34 42 <thead> 35 <tr><th class="sel"> </th><th>Account</th><th>Name</th><th>Email</th><th>Last Login</th></tr> 43 <tr> 44 <?cs if:delete_enabled ?><th class="sel"> </th><?cs /if ?> 45 <th>Account</th><th>Name</th><th>Email</th><th>Last Login</th> 46 </tr> 36 47 </thead><tbody><?cs 37 48 each:account = accounts ?> 38 49 <tr> 39 <td><input type="checkbox" name="sel" value="<?cs var:account.username ?>" /></td> 50 <?cs if:delete_enabled ?> 51 <td><input type="checkbox" name="sel" value="<?cs var:account.username ?>" /></td> 52 <?cs /if ?> 40 53 <td><?cs var:account.username ?></td> 41 54 <td><?cs var:account.name ?></td> … … 45 58 /each ?></tbody> 46 59 </table> 60 <?cs if:delete_enabled ?> 47 61 <div class="buttons"> 48 62 <input type="submit" name="remove" value="Remove selected accounts" /> 49 63 </div> 64 <?cs /if ?> 50 65 </form> 66 <?cs /if ?> 51 67 52 accountmanagerplugin/0.10/acct_mgr/web_ui.py
r1535 r1549 123 123 'account.') 124 124 125 def __init__(self): 126 self._write_check(log=True) 127 128 def _write_check(self, log=False): 129 writable = AccountManager(self.env).supports('set_password') 130 if not writable and log: 131 self.log.warn('AccountModule is disabled because the password ' 132 'store does not support writing.') 133 return writable 134 125 135 #INavigationContributor methods 126 136 def get_active_navigation_item(self, req): … … 128 138 129 139 def get_navigation_items(self, req): 140 if not self._write_check(): 141 return 130 142 if req.authname != 'anonymous': 131 143 yield 'metanav', 'account', Markup('<a href="%s">My Account</a>', … … 134 146 # IRequestHandler methods 135 147 def match_request(self, req): 136 return req.path_info in ('/account', '/reset_password') 148 return (req.path_info in ('/account', '/reset_password') 149 and self._write_check(log=True)) 137 150 138 151 def process_request(self, req): … … 148 161 req.redirect(self.env.href.wiki()) 149 162 action = req.args.get('action') 163 delete_enabled = AccountManager(self.env).supports('delete_user') 164 req.hdf['delete_enabled'] = delete_enabled 150 165 if req.method == 'POST': 151 166 if action == 'change_password': … … 231 246 232 247 def _enable_check(self, log=False): 248 writable = AccountManager(self.env).supports('set_password') 233 249 ignore_case = auth.LoginModule(self.env).ignore_case 234 if log and ignore_case: 235 self.log.warn('RegistrationModule is disabled because ' 236 'ignore_auth_case is enabled in trac.ini. ' 237 'This setting needs disabled to support ' 238 'registration.') 239 return not ignore_case 250 if log: 251 if not writable: 252 self.log.warn('RegistrationModule is disabled because the ' 253 'password store does not support writing.') 254 if ignore_case: 255 self.log.warn('RegistrationModule is disabled because ' 256 'ignore_auth_case is enabled in trac.ini. ' 257 'This setting needs disabled to support ' 258 'registration.') 259 return writable and not ignore_case 240 260 241 261 #INavigationContributor methods accountmanagerplugin/0.10/setup.py
r1502 r1549 5 5 setup( 6 6 name = 'TracAccountManager', 7 version = '0.1. 2',7 version = '0.1.3', 8 8 author = 'Matthew Good', 9 9 author_email = 'trac@matt-good.net', … … 29 29 'acct_mgr.web_ui = acct_mgr.web_ui', 30 30 'acct_mgr.htfile = acct_mgr.htfile', 31 'acct_mgr.http = acct_mgr.http', 31 32 'acct_mgr.api = acct_mgr.api', 32 33 'acct_mgr.admin = acct_mgr.admin',
