Пример #1
0
    def handle_apply(self, action):
        data, errors = self.extractData()

        if errors:
            return

        fridgemanager = IFridgeManager(self.context)
        user_data = fridgemanager.get_entry_payload(data["fridge_rand"])

        if user_data is not None:
            # Testing uniqueness of username
            portal = getSite()
            pas_tool = getToolByName(portal, "acl_users")
            members = pas_tool.getUserById(data["username"])
            if members is not None:
                raise forminterfaces.WidgetActionExecutionError(
                    "username", interface.Invalid(_(u"username_invalid_error"))
                )

            # Add member: We store username, password and email-address in the
            # default Plone member profile. All other member properties
            # (description, location, home_page, newsletter, etc.) are stored in
            # the Dexterity-based memberfolder.
            roles = []
            domains = []

            mtool = getToolByName(portal, "portal_membership")
            password = data["password"]
            if isinstance(password, unicode):
                password = password.encode("utf-8")
            mtool.addMember(data["username"], password, roles, domains)
            mtool.createMemberarea(data["username"])
            membersfolder = mtool.getMembersFolder()

            memberfolder = membersfolder[data["username"]]
            memberfolder.title = data["fullname"]
            memberfolder.description = data["description"]
            memberfolder.location = data["location"]
            memberfolder.home_page = data["home_page"]
            memberfolder.portrait = data["portrait"]
            memberfolder.newsletter = data["newsletter"]

            memberfolder.email = user_data["email"]

            notify(ObjectModifiedEvent(memberfolder))
            memberfolder.reindexObject()

            # Remove the fridge entry
            fridgemanager.delete_entry(data["fridge_rand"])

            # Log the new member in
            pas_tool.session._setupSession(data["username"].encode("utf-8"), self.request.RESPONSE)

            IStatusMessage(self.request).add(
                _(u"profile_registration_success_notification", default="Registration success"), type="info"
            )
        else:
            IStatusMessage(self.request).add(_(u"profile_registration_expired_or_invalid_notification"), type="error")

        return self._redirect()
Пример #2
0
    def login_next(self):
        plone_tools = getMultiAdapter((self.context, self.request),
                                      name=u'plone_tools')

        # check if user is authenticated
        mtool = plone_tools.membership()
        if mtool.isAnonymousUser():
            self.request.RESPONSE.expireCookie('__ac', path='/')
            # redirect to login_failed with error message
            IStatusMessage(self.request).add(
                    _(u'login_failed_notification'),
                    type='error')
            portal_state = getMultiAdapter((self.context, self.request),
                                           name=u'plone_portal_state')
            return self.request.RESPONSE.redirect(
                '%s/login_failed' % portal_state.portal_url())

        memberdata = mtool.getAuthenticatedMember()
        member_id = memberdata.getProperty('id')
        member = mtool.getMemberById(member_id).getHomeFolder()

        time = datetime.now()
        # Set last login time on member
        member.last_login = time

        # redirect with welcome message
        IStatusMessage(self.request).add(_(u'login_welcome_notification'),
                                         type='info')
        self.redirect(self.came_from)
Пример #3
0
    def handle_apply(self, action):
        data, errors = self.extractData()
        if errors:
            return

        portal = getSite()

        # create a new rand
        expires = datetime.now() + timedelta(days=2)
        data = {'email': data['email']}
        rand = IFridgeManager(self.context).add_entry(data, expires)

        # send mail to user
        mail_to = data['email']
        url = u"%s/%s/%s" % (self.context.absolute_url(), FORM_ID, rand)
        link = u'<a href="%s">%s</a>' % (url, url)
        message = translate(msgid=u'request_registration_mail_text',
                            domain=DOMAIN,
                            mapping={'link': link,
                                     'expires': expires.strftime('%d.%m.%Y %H:%M')},
                            context=self.request,
                            default=u'Finish your registration here ${link} by ${expires}.',
                            )
        mail_subject = translate(msgid="request_registration_mail_subject",
                                 domain=DOMAIN,
                                 context=self.request,
                                 default=u'Registration',
                                 )
        notify(MailEvent(message, mail_to, subject=mail_subject))

        IStatusMessage(self.request).add(_(u'request_registration_success_notification'),
                                        type='warn')
        return self._redirect()
Пример #4
0
    def __init__(self, context, request):
        super(ProfileRegistrationForm, self).__init__(context, request)

        portal_state = getMultiAdapter((context, request), name=u"plone_portal_state")
        self.schema["accept_terms"].description = _(
            u"accept_link_form_help", mapping={"link": "%s/agb" % portal_state.portal_url()}
        )
Пример #5
0
    def __init__(self, context, request):
        super(ProfileRegistrationForm, self).__init__(context, request)

        portal_state = getMultiAdapter((context, request),
                                       name=u'plone_portal_state')
        self.schema['accept_terms'].description = \
            _(u"accept_link_form_help",
            mapping={'link': '%s/agb' % portal_state.portal_url()})
Пример #6
0
class LoginForm(AutoExtensibleForm, form.EditForm, LoginBase):
    schema = ILoginForm
    id = "login_form"
    ignoreContext = True
    label = _(u"login_form_title", default="Login")
    description = _(u"login_form_description")

    def _redirect(self, target=''):
        if not target:
            portal_state = getMultiAdapter((self.context, self.request),
                                           name=u'plone_portal_state')
            target = portal_state.portal_url()
        self.request.response.redirect(target)

    def updateWidgets(self):
        super(LoginForm, self).updateWidgets()
        self.widgets['came_from'].mode = HIDDEN_MODE
        self.widgets['came_from'].value = self.came_from

    @button.buttonAndHandler(_(u'login_form_button'), name='submit')
    def handle_apply(self, action):
        data, errors = self.extractData()
        if not errors:
            plone_tools = getMultiAdapter((self.context, self.request),
                                          name=u'plone_tools')

            if 'came_from' in data.keys() and data['came_from']:
                self.request['came_from'] = data['came_from']

            plone_tools.membership().loginUser(self.request)
            portal_state = getMultiAdapter((self.context, self.request),
                                           name=u'plone_portal_state')
            return self._redirect(target='%s/login_next?came_from=%s' %
                                  (portal_state.portal_url(), self.came_from))

    @button.buttonAndHandler(_(u'cancel_form_button'), name='cancel')
    def handle_cancel(self, action):
        data, errors = self.extractData()

        IStatusMessage(self.request).add(_(u'login_cancel_notification'),
                                         type='info')

        if 'came_from' in data.keys() and data['came_from']:
            self.redirect(data['came_from'])

        return self._redirect()
Пример #7
0
    def handle_cancel(self, action):
        data, errors = self.extractData()

        IStatusMessage(self.request).add(_(u'login_cancel_notification'),
                                         type='info')

        if 'came_from' in data.keys() and data['came_from']:
            self.redirect(data['came_from'])

        return self._redirect()
Пример #8
0
    def handle_cancel(self, action):
        data, errors = self.extractData()

        IStatusMessage(self.request).add(_(u'login_cancel_notification'),
                                        type='info')

        if 'came_from' in data.keys() and data['came_from']:
            self.redirect(data['came_from'])

        return self._redirect()
Пример #9
0
    def __call__(self):
        context = aq_inner(self.context)
        membership_tool = getToolByName(context, 'portal_membership')
        portal_url_tool = getToolByName(self.context, 'portal_url')

        portal_url = portal_url_tool.portal_url()
        membership_tool.logoutUser(self.request)
        IStatusMessage(self.request).add(_(u'logout_notification'),
                                         type='info')
        self.request.response.expireCookie('__ac', path='/')
        return self.request.RESPONSE.redirect('%s/login' % portal_url)
Пример #10
0
    def __call__(self):
        context = aq_inner(self.context)
        membership_tool = getToolByName(context, 'portal_membership')
        portal_url_tool = getToolByName(self.context, 'portal_url')

        portal_url = portal_url_tool.portal_url()
        membership_tool.logoutUser(self.request)
        IStatusMessage(self.request).add(_(u'logout_notification'),
                                         type='info')
        self.request.response.expireCookie('__ac', path='/')
        return self.request.RESPONSE.redirect('%s/login' % portal_url)
Пример #11
0
    def handle_apply(self, action):
        data, errors = self.extractData()
        if errors:
            return

        portal = getSite()

        # create a new rand
        expires = datetime.now() + timedelta(days=2)
        data = {'email': data['email']}
        rand = IFridgeManager(self.context).add_entry(data, expires)

        # send mail to user
        mail_to = data['email']
        url = u"%s/%s/%s" % (self.context.absolute_url(), FORM_ID, rand)
        link = u'<a href="%s">%s</a>' % (url, url)
        message = translate(
            msgid=u'request_registration_mail_text',
            domain=DOMAIN,
            mapping={
                'link': link,
                'expires': expires.strftime('%d.%m.%Y %H:%M')
            },
            context=self.request,
            default=u'Finish your registration here ${link} by ${expires}.',
        )
        mail_subject = translate(
            msgid="request_registration_mail_subject",
            domain=DOMAIN,
            context=self.request,
            default=u'Registration',
        )
        notify(MailEvent(message, mail_to, subject=mail_subject))

        IStatusMessage(self.request).add(
            _(u'request_registration_success_notification'), type='warn')
        return self._redirect()
Пример #12
0
 def handle_cancel(self, action):
     IStatusMessage(self.request).add(_(u'request_registration_cancel_notification'),
                                     type='info')
     return self._redirect()
Пример #13
0
class ProfileRegistrationForm(form.SchemaForm, FridgeForm):
    grok.name('registration')
    grok.require('zope2.View')
    grok.context(IRegistrator)

    schema = IRegistration

    ignoreContext = True
    id = "ProfileRegistrationForm"
    label = _(u"profile_registration_form_title")
    description = _(u"profile_registration_form_description")

    def __init__(self, context, request):
        super(ProfileRegistrationForm, self).__init__(context, request)

        portal_state = getMultiAdapter((context, request),
                                       name=u'plone_portal_state')
        self.schema['accept_terms'].description = \
            _(u"accept_link_form_help",
            mapping={'link': '%s/agb' % portal_state.portal_url()})

    def _redirect(self, target=''):
        if not target:
            portal_state = getMultiAdapter((self.context, self.request),
                                           name=u'plone_portal_state')
            target = portal_state.portal_url()
        self.request.response.redirect(target)

    @button.buttonAndHandler(_(u"save_profile_form_button"), name='submit')
    def handle_apply(self, action):
        data, errors = self.extractData()

        if errors:
            return

        fridgemanager = IFridgeManager(self.context)
        user_data = fridgemanager.get_entry_payload(data['fridge_rand'])

        if user_data is not None:
            # Testing uniqueness of username
            portal = getSite()
            pas_tool = getToolByName(portal, 'acl_users')
            members = pas_tool.getUserById(data['username'])
            if members is not None:
                raise forminterfaces.WidgetActionExecutionError(
                    'username',
                    interface.Invalid(_(u"username_invalid_error")))

            # Add member: We store username, password and email-address in the
            # default Plone member profile. All other member properties
            # (description, location, home_page, newsletter, etc.) are stored in
            # the Dexterity-based memberfolder.
            roles = []
            domains = []

            mtool = getToolByName(portal, 'portal_membership')
            password = data['password']
            if isinstance(password, unicode):
                password = password.encode('utf-8')
            mtool.addMember(data['username'], password, roles, domains)
            mtool.createMemberarea(data['username'])
            membersfolder = mtool.getMembersFolder()

            memberfolder = membersfolder[data['username']]
            memberfolder.title = data['fullname']
            memberfolder.description = data['description']
            memberfolder.location = data['location']
            memberfolder.home_page = data['home_page']
            memberfolder.portrait = data['portrait']
            memberfolder.newsletter = data['newsletter']

            memberfolder.email = user_data['email']

            notify(ObjectModifiedEvent(memberfolder))
            memberfolder.reindexObject()

            # Remove the fridge entry
            fridgemanager.delete_entry(data['fridge_rand'])

            # Log the new member in
            pas_tool.session._setupSession(data['username'].encode("utf-8"),
                                           self.request.RESPONSE)

            IStatusMessage(self.request).add(_(
                u'profile_registration_success_notification',
                default="Registration success"),
                                             type='info')
        else:
            IStatusMessage(self.request).add(
                _(u'profile_registration_expired_or_invalid_notification'),
                type='error')

        return self._redirect()

    @button.buttonAndHandler(_(u'cancel_form_button'), name='cancel')
    def handle_cancel(self, action):
        IStatusMessage(self.request).add(
            _(u'profile_registration_cancel_notification'), type='info')
        return self._redirect()

    def updateFields(self):
        super(ProfileRegistrationForm, self).updateFields()
        self.fields['newsletter'].widgetFactory = \
            SingleCheckBoxFieldWidget
        self.fields['accept_terms'].widgetFactory = \
            SingleCheckBoxFieldWidget

    def updateWidgets(self):
        super(ProfileRegistrationForm, self).updateWidgets()
        self.widgets['home_page'].addClass("url")
Пример #14
0
 def handle_cancel(self, action):
     IStatusMessage(self.request).add(
         _(u'request_registration_cancel_notification'), type='info')
     return self._redirect()
Пример #15
0
class RequestRegistrationForm(form.SchemaForm):
    grok.name('request_registration')
    grok.require('zope2.View')
    grok.context(IRegistrator)

    schema = IRegistrationRequest
    ignoreContext = True
    id = "request_registration_form"
    label = _(u"request_registration_form_title")
    description = _(u"request_registration_form_description")

    def _redirect(self, target=''):
        if not target:
            portal_state = getMultiAdapter((self.context, self.request),
                                           name=u'plone_portal_state')
            target = portal_state.portal_url()
        self.request.response.redirect(target)

    def updateWidgets(self):
        super(RequestRegistrationForm, self).updateWidgets()
        self.widgets['email'].addClass("email")
        self.widgets['email_repeat'].addClass("email")

    @button.buttonAndHandler(_(u"register_form_button"), name='submit')
    def handle_apply(self, action):
        data, errors = self.extractData()
        if errors:
            return

        portal = getSite()

        # create a new rand
        expires = datetime.now() + timedelta(days=2)
        data = {'email': data['email']}
        rand = IFridgeManager(self.context).add_entry(data, expires)

        # send mail to user
        mail_to = data['email']
        url = u"%s/%s/%s" % (self.context.absolute_url(), FORM_ID, rand)
        link = u'<a href="%s">%s</a>' % (url, url)
        message = translate(
            msgid=u'request_registration_mail_text',
            domain=DOMAIN,
            mapping={
                'link': link,
                'expires': expires.strftime('%d.%m.%Y %H:%M')
            },
            context=self.request,
            default=u'Finish your registration here ${link} by ${expires}.',
        )
        mail_subject = translate(
            msgid="request_registration_mail_subject",
            domain=DOMAIN,
            context=self.request,
            default=u'Registration',
        )
        notify(MailEvent(message, mail_to, subject=mail_subject))

        IStatusMessage(self.request).add(
            _(u'request_registration_success_notification'), type='warn')
        return self._redirect()

    @button.buttonAndHandler(_(u'cancel_form_button'), name='cancel')
    def handle_cancel(self, action):
        IStatusMessage(self.request).add(
            _(u'request_registration_cancel_notification'), type='info')
        return self._redirect()
Пример #16
0
    def handle_apply(self, action):
        data, errors = self.extractData()

        if errors:
            return

        fridgemanager = IFridgeManager(self.context)
        user_data = fridgemanager.get_entry_payload(data['fridge_rand'])

        if user_data is not None:
            # Testing uniqueness of username
            portal = getSite()
            pas_tool = getToolByName(portal, 'acl_users')
            members = pas_tool.getUserById(data['username'])
            if members is not None:
                raise forminterfaces.WidgetActionExecutionError(
                    'username',
                    interface.Invalid(_(u"username_invalid_error")))

            # Add member: We store username, password and email-address in the
            # default Plone member profile. All other member properties
            # (description, location, home_page, newsletter, etc.) are stored in
            # the Dexterity-based memberfolder.
            roles = []
            domains = []

            mtool = getToolByName(portal, 'portal_membership')
            password = data['password']
            if isinstance(password, unicode):
                password = password.encode('utf-8')
            mtool.addMember(data['username'], password, roles, domains)
            mtool.createMemberarea(data['username'])
            membersfolder = mtool.getMembersFolder()

            memberfolder = membersfolder[data['username']]
            memberfolder.title = data['fullname']
            memberfolder.description = data['description']
            memberfolder.location = data['location']
            memberfolder.home_page = data['home_page']
            memberfolder.portrait = data['portrait']
            memberfolder.newsletter = data['newsletter']

            memberfolder.email = user_data['email']

            notify(ObjectModifiedEvent(memberfolder))
            memberfolder.reindexObject()

            # Remove the fridge entry
            fridgemanager.delete_entry(data['fridge_rand'])

            # Log the new member in
            pas_tool.session._setupSession(data['username'].encode("utf-8"),
                                           self.request.RESPONSE)

            IStatusMessage(self.request).add(_(
                u'profile_registration_success_notification',
                default="Registration success"),
                                             type='info')
        else:
            IStatusMessage(self.request).add(
                _(u'profile_registration_expired_or_invalid_notification'),
                type='error')

        return self._redirect()
Пример #17
0
 def handle_cancel(self, action):
     IStatusMessage(self.request).add(_(u"profile_registration_cancel_notification"), type="info")
     return self._redirect()