Esempio n. 1
0
class RegistrationView(form.SchemaForm):
    grok.name('slc.accountrequest.register')
    grok.require('zope2.AccessContentsInformation')
    grok.context(IRequestFolderSchema)

    portal_type = u"slc.accountrequest.request"
    schema = IRequestSchema
    ignoreContext = True

    label = _(u"Enter your account details")
    description = _(u"We will contact you once your account has been created.")

    def update(self):
        # disable Plone's editable border
        self.request.set('disable_border', True)

        # call the base class version - this is very important!
        super(RegistrationView, self).update()

    @button.buttonAndHandler(_(u'Send request'))
    def handleApply(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        createContentInContainer(self.context, 'slc.accountrequest.request',
                                 **data)

        # Redirect back to the front page with a status message
        IStatusMessage(self.request).addStatusMessage(
            _(u"Thank you for your request. We will contact you shortly"),
            "info")
        portal_url = self.context.restrictedTraverse(
            '@@plone_portal_state').portal_url()
        self.request.response.redirect(portal_url)

    @button.buttonAndHandler(_(u"Cancel"))
    def handleCancel(self, action):
        """User cancelled. Redirect back to the front page.
        """
        portal_url = self.context.restrictedTraverse(
            '@@plone_portal_state').portal_url()
        self.request.response.redirect(portal_url)
Esempio n. 2
0
    def handleApply(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        createContentInContainer(self.context, 'slc.accountrequest.request',
                                 **data)

        # Redirect back to the front page with a status message
        IStatusMessage(self.request).addStatusMessage(
            _(u"Thank you for your request. We will contact you shortly"),
            "info")
        portal_url = self.context.restrictedTraverse(
            '@@plone_portal_state').portal_url()
        self.request.response.redirect(portal_url)
Esempio n. 3
0
    def handleApply(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        createContentInContainer(self.context,
            'slc.accountrequest.request', **data)

        # Redirect back to the front page with a status message
        IStatusMessage(self.request).addStatusMessage(
                _(u"Thank you for your request. We will contact you shortly"),
                "info"
            )
        portal_url = self.context.restrictedTraverse(
            '@@plone_portal_state').portal_url()
        self.request.response.redirect(portal_url)
Esempio n. 4
0
 def validatePassword(data):
     if data.password != data.password_ctl:
             raise PasswordsDoNotMatch(_(u"Password confirmation should match password."))
import logging
from zope.i18n import translate
from zope.i18nmessageid import Message
from zope.component import getAllUtilitiesRegisteredFor
from Products.CMFCore.utils import getToolByName
from slc.accountrequest.interfaces import IRegistrationHandler
from slc.accountrequest import MessageFactory as _

logger = logging.getLogger("slc.accountrequest.eventhandlers")

MAIL_NOTIFICATION_MESSAGE = _(
    u"mail_notification_message",
    default=u"Your account was created with the following details:\n\n"
             "User Name: ${username}\n"
             "Password: ${password}\n")

def createAccount(obj, event):
    # Transitioning from pending to created
    if event.new_state.id == 'created':
        # Look up utilities, call them to do actual registration
        handlers = getAllUtilitiesRegisteredFor(IRegistrationHandler)
        for handler in handlers:
            handler.register(obj)

def notifyAccountCreated(obj, event):
    if event.new_state.id == 'created':
        # Send an email to let the user know his account was approved
        mail_host = getToolByName(obj, 'MailHost')
        portal_url = getToolByName(obj, 'portal_url')
        portal = portal_url.getPortalObject()
        sender = portal.getProperty('email_from_address')
Esempio n. 6
0
 def validatePassword(data):
     if data.password != data.password_ctl:
         raise PasswordsDoNotMatch(
             _(u"Password confirmation should match password."))
Esempio n. 7
0
class IRequestSchema(form.Schema):
    """ This extends plone.app.users.userdataschema.IRegisterSchema and makes
        it available to dexterity, so we can create objects with this schema.
    """
    fullname = schema.TextLine(
        title=_(u'label_full_name', default=u'Full Name'),
        description=_(u'help_full_name_creation',
                      default=u"Enter full name, e.g. John Smith."),
        required=True)

    email = schema.ASCIILine(title=_(u'label_email', default=u'E-mail'),
                             description=u'',
                             required=True)

    organisation = schema.TextLine(
        title=_(u'label_organisation', default=u'Organisation'),
        description=_(u'help_organisation_creation',
                      default=u"Enter the name of your organisation."),
        required=True)

    sector = schema.Choice(vocabulary=u'slc.accountrequest.sector',
                           title=_(u'label_sector', default=u'Sector'),
                           description=_(
                               u'help_sector_creation',
                               default=u"Select the relevant NACE code."),
                           required=True)

    country_manager = schema.Bool(
        title=_(u'label_country_manager',
                default=u'Country Manager account required'),
        description=_(
            u'help_country_manager_creation',
            default=u"Tick if you require a country manager account."),
        required=False)

    receive_statistics = schema.Bool(
        title=_(u'label_receive_statistics', default=u'Receive statistics'),
        description=_(u'help_receive_statistics_creation',
                      default=u"Tick if you want to receive statistics."),
        required=False)

    username = schema.ASCIILine(
        title=_(u'label_user_name', default=u'User Name'),
        description=_(u'help_user_name_creation_casesensitive',
                      default=u"Enter a user name, usually something "
                      "like 'jsmith'. "
                      "No spaces or special characters. "
                      "Usernames and passwords are case sensitive, "
                      "make sure the caps lock key is not enabled. "
                      "This is the name used to log in."))

    password = schema.Password(title=_(u'label_password', default=u'Password'),
                               description=_(u'help_password_creation',
                                             default=u'Minimum 5 characters.'))

    password_ctl = schema.Password(
        title=_(u'label_confirm_password', default=u'Confirm password'),
        description=_(u'help_confirm_password',
                      default=u"Re-enter the password. "
                      "Make sure the passwords are identical."))

    form.widget(sector=TreeFieldWidget)

    @invariant
    def validatePassword(data):
        if data.password != data.password_ctl:
            raise PasswordsDoNotMatch(
                _(u"Password confirmation should match password."))
Esempio n. 8
0
class PasswordsDoNotMatch(Invalid):
    __doc__ = _(u"Passwords do not match")