[Checkins] SVN: grokapps/PlainLoginDemo/src/plainlogindemo/app.py
validation of duplicate login
Luciano Ramalho
luciano at ramalho.org
Mon Jan 14 21:53:55 EST 2008
Log message for revision 82882:
validation of duplicate login
Changed:
U grokapps/PlainLoginDemo/src/plainlogindemo/app.py
-=-
Modified: grokapps/PlainLoginDemo/src/plainlogindemo/app.py
===================================================================
--- grokapps/PlainLoginDemo/src/plainlogindemo/app.py 2008-01-15 02:50:41 UTC (rev 82881)
+++ grokapps/PlainLoginDemo/src/plainlogindemo/app.py 2008-01-15 02:53:54 UTC (rev 82882)
@@ -12,7 +12,9 @@
from zope.app.authentication.session import SessionCredentialsPlugin
from zope.app.security.interfaces import IAuthentication
from zope.app.security.interfaces import IUnauthenticatedPrincipal
+from zope.security.management import checkPermission
from zope.app.securitypolicy.interfaces import IPrincipalPermissionManager
+from zope.schema import getFieldNamesInOrder, ValidationError
from zope.schema.interfaces import IField, IIterableSource
from zope.i18n import MessageFactory
@@ -105,8 +107,8 @@
"""
User registration form.
"""
- form_fields = grok.AutoFields(IInternalPrincipal)
- label = u'User registration'
+ form_fields = grok.AutoFields(IInternalPrincipal).omit('passwordManagerName')
+ label = _(u'User registration')
template = grok.PageTemplateFile('form.pt')
@grok.action('Save')
@@ -119,17 +121,21 @@
login = data['login']
pau = getUtility(IAuthentication)
principals = pau['principals']
- # create an instance of InternalPrincipal
- principal = InternalPrincipal(**data)
# XXX: the login name must be unique; need better handling of this
- assert(login not in principals)
- principals[login] = principal
- # grant the user permission to view the member listing
- permission_mngr = IPrincipalPermissionManager(grok.getSite())
- permission_mngr.grantPermissionToPrincipal(
- 'plainlogindemo.ViewMemberListing', principals.prefix + login)
+ if login in principals:
+ msg = _(u'Login name taken. Please choose a different one.')
+ self.widgets['login']._error = ValidationError(msg)
+ self.form_reset = False
+ else:
+ # create an instance of InternalPrincipal
+ principal = InternalPrincipal(passwordManagerName='SHA1', **data)
+ principals[login] = principal
+ # grant the user permission to view the member listing
+ permission_mngr = IPrincipalPermissionManager(grok.getSite())
+ permission_mngr.grantPermissionToPrincipal(
+ 'plainlogindemo.ViewMemberListing', principals.prefix + login)
- self.redirect(self.url('login')+'?'+urlencode({'login':login}))
+ self.redirect(self.url('login')+'?'+urlencode({'login':login}))
class Account(grok.View):
@@ -146,15 +152,8 @@
grok.require('plainlogindemo.ViewMemberListing')
- def field_names(self):
- # failed attempt to list fields but not methods; this returns empty
- # return (f for f in IInternalPrincipal if IField.providedBy(f))
-
- # another failed attempt to list fields but not methods; this returns
- # all attributes
- # return (f for f in IInternalPrincipal if not callable(f))
-
- return ['login', 'title', 'description']
+ def field_names(self):
+ return getFieldNamesInOrder(IInternalPrincipal)
def members(self):
pau = getUtility(IAuthentication)
More information about the Checkins
mailing list