Skip to main content

A package for all things users and groups related (specific to plone)

Project description

Introduction

This package provide the registration form for new users using a Zope formlib form. It allows the site administrator to select fields from a schema to appear on the registration form.

Example below is extracted from the addon collective.examples.userdata

How to Override the default schema

The default schema is provided by a utility.

You can override this utility by using GenericSetup in your addon: add a componentregistry.xml file:

<?xml version="1.0"?>
<componentregistry>
  <utilities>
    <utility
      interface="plone.app.users.userdataschema.IUserDataSchemaProvider"
      factory="collective.examples.userdata.userdataschema.UserDataSchemaProvider"
    />
  </utilities>
</componentregistry>

and declare your utility in a configure.zcml file:

<utility
  interface="plone.app.users.userdataschema.IUserDataSchemaProvider"
  factory="collective.examples.userdata.userdataschema.UserDataSchemaProvider"

A userdataschema.py file should contains:

from plone.app.users.userdataschema import IUserDataSchemaProvider
from plone.app.users.userdataschema import IUserDataSchema


class UserDataSchemaProvider(object):
    implements(IUserDataSchemaProvider)

    def getSchema(self):
        """
        """
        return IEnhancedUserDataSchema


class IEnhancedUserDataSchema(IUserDataSchema):
    """ Use all the fields from the default user data schema, and add various
    extra fields.
    """

For example you can add a country field to the schema:

class IEnhancedUserDataSchema(IUserDataSchema):
    # ...
    country = schema.TextLine(
        title=_(u'label_country', default=u'Country'),
        description=_(u'help_country',
                      default=u"Fill in which country you live in."),
        required=False,
        )

An other use case could be a not stored field. For example an “Accept Terms” field can be implemented by adding a constraint to the schema:

def validateAccept(value):
    if not value == True:
        return False
    return True

class IEnhancedUserDataSchema(IUserDataSchema):
    # ...
    accept = schema.Bool(
        title=_(u'label_accept', default=u'Accept terms of use'),
        description=_(u'help_accept',
                      default=u"Tick this box to indicate that you have found,"
                      " read and accepted the terms of use for this site. "),
        required=True,
        constraint=validateAccept,
        )

Because this field can be ignored once registration is complete, you don’t add it to the memberdata properties and voila.

Next you have to add theses fields to the memberdata properties using a memberdata_properties.xml:

<?xml version="1.0"?>
<object name="portal_memberdata" meta_type="Plone Memberdata Tool">
 <property name="country" type="string"></property>
</object>

How to define which fields should appear on the registration form

Fields which appear on the registration form are defined in the site_properties property sheet:

<?xml version="1.0"?>
<object name="portal_properties" meta_type="Plone Properties Tool">
 <object name="site_properties" meta_type="Plone Property Sheet">
  <!-- Fields that will be on the form after installation of the product -->
  <property name="user_registration_fields" type="lines">
   <element value="country" />
   <element value="accept" />
  </property>
 </object>
</object>

The site manager can modify this configuration using the control panel @@member-registration.

How to update the personal information form

In order to see these properties in the Personal Information form (@@personal-information), you need to take a few extra steps. You have to override the default adapter which adapts a user object to a form. See the plone.app.controlpanel documentation for a detailed explanation.

To override plone.app.users’ default adapter, you have to put this in overrides.zcml:

<adapter
  provides=".userdataschema.IEnhancedUserDataSchema"
  for="Products.CMFCore.interfaces.ISiteRoot"
  factory=".adapter.EnhancedUserDataPanelAdapter"
  />

In adapter.py, repeat (yes, this is unfortunate) the fields we defined in the schema. For example, for the firstname field, we do this:

class EnhancedUserDataPanelAdapter(UserDataPanelAdapter):
    """
    """
    def get_firstname(self):
        return self.context.getProperty('firstname', '')
    def set_firstname(self, value):
        return self.context.setMemberProperties({'firstname': value})
    firstname = property(get_firstname, set_firstname)

Changelog

1.1.5 (2013-01-13)

  • Fix email as login validation in the personalize form (UserDataPanel). This is for the case when email is used as login. It checked that a changed email address was valid as user id. But the user id is never changed here, only the login name. We only need to check if this address is not used by another user. [maurits]

1.1.4 (2012-10-03)

  • Fix to not break if passwords contain non-ASCII characters. This closes https://dev.plone.org/ticket/13114 [davisagli]

  • Ensure links on user preference panes adhere to navigation root. Fixes https://dev.plone.org/ticket/11909. [davidjb]

  • Avoid direct zope.app.form dependency. [hannosch]

  • Support redirecting to a URL specified in the ‘came_from’ query string parameter following registration. [davisagli]

  • Be consistent in using INavigationRoot. [do3cc]

1.1.3 (2012-01-04)

1.1.2 (2011-08-23)

1.1.1 - 2011-06-02

1.1 - 2011-04-03

  • Include plone.app.controlpanel configure.zcml because we use permissions defined in this package. [vincentfretin]

  • Use portal object instead of self.context in AddUserForm so we can easily subclass the class for another context. [vincentfretin]

1.1b2 - 2011-03-02

  • Fixed test of the default user portrait, which changed from defaultUser.gif to defaultUser.png in Products.PlonePAS 4.0.5. [maurits]

1.1b1 - 2011-01-03

  • Depend on Products.CMFPlone instead of Plone. [elro]

  • Don’t allow non-Managers to add new users to groups that grant the Manager role. [davisagli]

  • Protect the user management forms with the “Plone Site Setup: Users and Groups” permission instead of the generic “Manage portal” and “Manage users”. This requires plone.app.controlpanel >= 2.1b1. [davisagli]

1.0.5 - 2011-06-02

1.0.4 - 2011-02-25

  • Fixed test of the default user portrait, which changed from defaultUser.gif to defaultUser.png in Products.PlonePAS 4.0.5. [maurits]

1.0.3 - 2011-01-03

  • Don’t assume that fields in the user schema will be saved in property sheets when a new user registers. Instead, adapt the navigation root to the user schema to get the same adapter as is used on the Personal Information form, and use it to save the values from the registration form. [davisagli]

  • Fixed critical error on add user page when some groups have a non-ascii character in their title. Sort groups on their title normalized. Token and value in terms in the groups vocabulary were switched. This closes http://dev.plone.org/plone/ticket/11316 [thomasdesvenain, vincentfretin, davisagli]

1.0.2 - 2010-11-24

  • Don’t use a custom widget just to set the description of the fullname field, which should be set on the field itself. [davisagli]

1.0.1 - 2010-07-18

  • Added missing i18n:domain plone in user information template which prevented some translations from showing up. Fixes http://dev.plone.org/plone/ticket/10744 [maurits]

  • Update license to GPL version 2 only. [hannosch]

  • Fix @@user-information to correctly get/set and delete the portrait for the given userid. Fixes http://dev.plone.org/plone/ticket/10731. [mr_savage]

1.0 - 2010-07-01

1.0b9 - 2010-06-13

  • Avoid deprecation warnings under Zope 2.13. [hannosch]

  • Use the standard libraries doctest module. [hannosch]

  • Use five.formlib. [hannosch]

  • Retrieve properties as unicode even if they are already stored that way. Fixes http://dev.plone.org/plone/ticket/10509 [davisagli]

  • When the user_registration_fields property is not there, fall back to an empty list; this avoids a TypeError on the registration form. [maurits]

1.0b8 - 2010-06-03

1.0b7 - 2010-05-01

  • Handle encoded strings returned by PlonePAS. Fixes http://dev.plone.org/plone/ticket/10447 [esteele]

  • Remove unused memberdetails.py [esteele]

  • Pin user preferences forms to INavigationRoot instead of ISiteRoot. Fixes http://dev.plone.org/plone/ticket/10439 [esteele]

  • Added configlet forms that inherit from personal preferences and personal information. These forms are used when editing user prefs from ‘User and groups’ in site setup. [kcleong]

  • Use utility-provided UserDataSchema on @@personal-information form. Fixes http://dev.plone.org/plone/ticket/10258 [khink, huub_bouma]

1.0b6 - 2010-04-07

  • Update permission for the @@register view so only users with the Add Portal Member permission can use it to add new members. Update tests accordingly. Fixes http://dev.plone.org/plone/ticket/3739 [dukebody]

  • Fixed help_biography message. [vincentfretin]

1.0b5 - 2010-03-05

  • Remove some unused variable definitions from browser/register.py. [esteele]

  • Updated account-panel-bare.pt to recent markup conventions. References http://dev.plone.org/plone/ticket/9981 [spliter]

  • Sort groups listing alphabetically by title. [esteele]

  • Display groups by title (id) in @@new-user. [esteele]

  • Fix some more duplicate id’s, including some done through TAL that had nothing dynamic and so nee not be tal:attributes. [rossp]

1.0b4 - 2010-02-18

  • Updated memberregistration.pt to recent markup conventions. References http://dev.plone.org/old/plone/ticket/9981 [spliter]

  • Fixed @@register by removing unnecessary fill-slot outside of a fill-macro. [spliter]

  • Removing redundant .documentContent markup. This refs http://dev.plone.org/plone/ticket/10231. [limi]

  • Updated register_form.pt to not use fill-slot=”viewlet”. [spliter]

  • Updated user registration templates to disable the columns with ‘disable_MANAGER_NAME’ pattern [spliter]

  • add views to replace personalize_form, split up into @@personal-preferences, @@personal-information and @@change-password. [khink, kcleong]

1.0b3 - 2010-02-01

  • Retarget the registration and new-user forms at the navigation root. [mj]

1.0b2 - 2010-01-28

  • Fixed tests to account for new layout of users overview pages. [esteele]

1.0b1 - 2009-12-27

  • Fixed package dependency declarations and use getSite from zope.site. [hannosch]

1.0a3 - 2009-12-16

  • Make the password field optional for the admin when instead an email can be sent. [maurits]

  • On the anonymous registration form, do not offer to send an email with a link to reset your password if the password fields are right there on the form already; we were never actually sending emails with the plain password itself anyway. [maurits]

  • Allow admins to register a user at all times, also without valid mailhost settings. This means that in a fresh Plone site you can create user accounts immediately without having to edit any settings. [maurits]

  • Use the proper SimpleVocabulary/SimpleTerm API instead of encouraging bad practice. This refs http://dev.plone.org/plone/ticket/6480. [hannosch]

1.0a2 - 2009-12-01

  • Display a message and prevent the user from registering if there is no defined mailhost and users are not allowed to select their own passwords. [esteele]

  • “User/Groups Settings” configlet view is polished visually to follow rest of configlets in “Users and Groups” control panel. Ref. #9825 [spliter]

  • For “User/Groups Settings” configlet highlighted “Member registration” tab instead of the wrong “Settings” [spliter]

  • @@new-user form will now always show the password fields, regardless of the site settings. [esteele]

  • Change registration form name @@join_form to @@register. Change class names accordingly. Added an “@@new-user” form to be used from the control panel. “Add to group” functionality now lives there. We can now get rid of the horrid came_from flags that we’ve been passing around. [esteele]

  • Internationalized title_join_form_fields and description_join_form_fields. This closes http://dev.plone.org/plone/attachment/ticket/9810 [vincentfretin]

1.0a1 - 2009-11-18

  • Fixed bad use of i18n markup in joinform.py. This closes http://dev.plone.org/plone/ticket/9773 [vincentfretin]

  • Renamed label_groups to label_add_to_groups in joinform.py [vincentfretin]

  • Restore the came_from_prefs check to make the join form redirect to the Users and Groups configlet if that’s where the user started from. [davisagli]

  • Initial release

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plone.app.users-1.1.5.zip (69.1 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page