Index: acct_mgr/api.py =================================================================== --- acct_mgr/api.py (revision 1402) +++ acct_mgr/api.py (working copy) @@ -69,6 +69,23 @@ """User deleted """ +class IRegistrationFieldProvider(Interface): + """An interface for adding fields to the registration form. + """ + + def get_registration_fields(req): + """Return an iterable of (fragment, type) where type + is either 'required' or 'optional'. + """ + +def IRegistrationManipulator(Interface): + """An interface to process and validate registrations. + """ + + def validate_registration(req, username, password): + """Should return an iterable of errors (with no items if all is well). + """ + class AccountManager(Component): """The AccountManager component handles all user account management methods provided by the IPasswordStore interface. Index: acct_mgr/web_ui.py =================================================================== --- acct_mgr/web_ui.py (revision 1402) +++ acct_mgr/web_ui.py (working copy) @@ -24,7 +24,7 @@ from trac.web.chrome import INavigationContributor, ITemplateProvider from trac.util import Markup -from api import AccountManager +from api import AccountManager, IRegistrationFieldProvider, IRegistrationManipulator def _create_user(req, env, check_permissions=True): mgr = AccountManager(env) @@ -225,6 +225,9 @@ """ implements(INavigationContributor, IRequestHandler, ITemplateProvider) + + field_providers = ExtensionPoint(IRegistrationFieldProvider) + manipulators = ExtensionPoint(IRegistrationManipulator) #INavigationContributor methods @@ -247,6 +250,11 @@ action = req.args.get('action') if req.method == 'POST' and action == 'create': try: + errors = [] + for m in self.manipulators: + errors += list(m.validate_registration(req)) + if errors: + raise TracError, '\n'.join(errors) _create_user(req, self.env) except TracError, e: req.hdf['registration.error'] = e.message @@ -255,6 +263,11 @@ req.hdf['reset_password_enabled'] = \ (self.env.is_component_enabled(AccountModule) and NotificationSystem(self.env).smtp_enabled) + fields = {} + for provider in self.field_providers: + for frag, type in provider.get_registration_fields(req): + fields[type] = fields.get(type,[]) + [frag] + req.hdf['fields'] = fields return 'register.cs', None Index: acct_mgr/templates/register.cs =================================================================== --- acct_mgr/templates/register.cs (revision 1402) +++ acct_mgr/templates/register.cs (working copy) @@ -34,6 +34,9 @@ class="textwidget" size="20" /> + +
+