linamh/www-apps/trac-acct_mgr/files/RegistrationConfirmationPatch.diff
geos_one 083ae0a5aa correct patch
git-svn-id: https://svn.disconnected-by-peer.at/svn/linamh/trunk/linamh@874 6952d904-891a-0410-993b-d76249ca496b
2009-03-15 07:30:24 +00:00

122 lines
4.5 KiB
Diff

Submitted By: Mario Fetka (mario dot fetka at gmail dot com)
Date: 2009-03-15
Initial Package Version: 0.2.1
Origin: http://trac-hacks.org/wiki/RegistrationConfirmationPatch
Upstream Status: unknown
Description: This is a patch for AccountManagerPlugin that adds an
IRegistrationConfirmation extension point that enables pluggable
verifications for new user registration.
diff -Naur trac-acct_mgr-0.2.1.orig/acct_mgr/api.py trac-acct_mgr-0.2.1/acct_mgr/api.py
--- trac-acct_mgr-0.2.1.orig/acct_mgr/api.py 2009-03-15 07:26:49.412311159 +0000
+++ trac-acct_mgr-0.2.1/acct_mgr/api.py 2009-03-15 07:27:13.305249903 +0000
@@ -77,6 +77,19 @@
"""User deleted
"""
+class IRegistrationConfirmation(Interface):
+ """An interface for receiving notification before and after the new user
+ registration form has been submitted.
+ """
+
+ def pre_registration(self, req):
+ """Returns the markup to be added to the registration form
+ """
+
+ def verify_registration(self, req):
+ """Returns an error message if confirmation fails, or None on success
+ """
+
class AccountManager(Component):
"""The AccountManager component handles all user account management methods
provided by the IPasswordStore interface.
diff -Naur trac-acct_mgr-0.2.1.orig/acct_mgr/templates/register.html trac-acct_mgr-0.2.1/acct_mgr/templates/register.html
--- trac-acct_mgr-0.2.1.orig/acct_mgr/templates/register.html 2009-03-15 07:26:49.368327943 +0000
+++ trac-acct_mgr-0.2.1/acct_mgr/templates/register.html 2009-03-15 07:27:13.305249903 +0000
@@ -43,6 +43,11 @@
class="textwidget" size="20" />
</label>
</div>
+ <py:if test="extra_required_content">
+ <div>
+ ${Markup(extra_required_content)}
+ </div>
+ </py:if>
</fieldset>
<fieldset>
<legend>Optional</legend>
diff -Naur trac-acct_mgr-0.2.1.orig/acct_mgr/web_ui.py trac-acct_mgr-0.2.1/acct_mgr/web_ui.py
--- trac-acct_mgr-0.2.1.orig/acct_mgr/web_ui.py 2009-03-15 07:26:49.412311159 +0000
+++ trac-acct_mgr-0.2.1/acct_mgr/web_ui.py 2009-03-15 07:27:13.307559560 +0000
@@ -27,6 +27,7 @@
from genshi.builder import tag
from api import AccountManager
+from api import IRegistrationConfirmation
from acct_mgr.util import urandom
def _create_user(req, env, check_permissions=True):
@@ -351,6 +352,8 @@
implements(INavigationContributor, IRequestHandler, ITemplateProvider)
+ listeners = ExtensionPoint(IRegistrationConfirmation)
+
def __init__(self):
self._enable_check(log=True)
@@ -394,19 +397,28 @@
'name' : None,
'email' : None,
},
+ 'extra_required_content' : self._get_extra_content(req),
}
+ error = None
if req.method == 'POST' and action == 'create':
- try:
- _create_user(req, self.env)
- except TracError, e:
- data['registration_error'] = e.message
- formdata = getattr(e, 'acctmgr', None)
- if formdata:
- data['acctmgr'] = formdata
+ for listener in self.listeners:
+ error = listener.verify_registration(req)
+ if error is not None:
+ break
+ data['registration_error'] = error
+ if error is None:
+ try:
+ _create_user(req, self.env)
+ except TracError, e:
+ data['registration_error'] = e.message
+ formdata = getattr(e, 'acctmgr', None)
+ if formdata:
+ data['acctmgr'] = formdata
+ else:
+ raise e
else:
- raise e
- else:
- req.redirect(req.href.login())
+ req.redirect(req.href.login())
+
data['reset_password_enabled'] = \
(self.env.is_component_enabled(AccountModule)
and NotificationSystem(self.env).smtp_enabled)
@@ -414,6 +426,14 @@
return 'register.html', data, None
+ def _get_extra_content(self, req):
+ ret = ""
+ for listener in self.listeners:
+ response = listener.pre_registration(req)
+ if response is not None:
+ ret += response
+ return ret
+
# ITemplateProvider
def get_htdocs_dirs(self):