Example #1
0
def applyPasswdChanges(form, content, data):
    # copied from z3c.form.form
    changes = {}
    if data['password1'] != data['password2']:
        raise interfaces.WidgetActionExecutionError(\
            'password1',
            zope.interface.Invalid("passwords aren't equal"))
    reqPrincipal = form.request.principal
    (prefix, id) = reqPrincipal.id.split('.')
    utilUserMagagement = getUtility(IAdmUtilUserManagement)
    principalFolder = utilUserMagagement[u'principals']
    if principalFolder.prefix == prefix + '.':
        intPrincipal = principalFolder.get(id)
        if intPrincipal is None:
            raise interfaces.WidgetActionExecutionError(\
                'password_old',
                zope.interface.Invalid("error in old password"))
        if intPrincipal.checkPassword(data['password_old']) is False:
            raise interfaces.WidgetActionExecutionError(\
                'password_old',
                zope.interface.Invalid("error in old password"))
        intPrincipal.setPassword(data['password1'])
        changes.setdefault(IEditPassword, {}).setdefault('password',
                                                         {})['newval'] = "****"
        changes.setdefault(IEditPassword, {}).setdefault('password',
                                                         {})['oldval'] = "####"
    return changes
Example #2
0
 def _checkForm(self, data):
     if data['company'] is None and data['new_company'] is None:
         raise interfaces.WidgetActionExecutionError(
             'new_company',
             interface.Invalid(
                 _(u"You need to specify your company name.")
             )
         )
Example #3
0
 def handleRegister(self, action):
     data, errors = self.extractData()
     self._checkForm(data)
     if errors:
         return
     if data['password'] != data['password_confirm']:
         raise interfaces.WidgetActionExecutionError(
             'password', interface.Invalid(_(u'Passwords do not match.'))
         )
     self._registerUser(data)
     self._updateDataCompany(data, data['login'])
     self._updateUser(data['login'], data)
     self._renameUserContent()
     self._sendMailToUser()
     self._sendNotificationToAdmin()
     portal_url = getToolByName(self.context, "portal_url")
     self.request.response.redirect('%s/login' % portal_url())
Example #4
0
 def handleApply(self, action):
     sm = getSecurityManager()
     if not sm.checkPermission(ModifyPortalContent, self.context):
         raise Unauthorized
     data, errors = self.extractData()
     if data['company'] is None and data['new_company'] is None:
         raise interfaces.WidgetActionExecutionError(
             'new_company',
             interface.Invalid(
                 _(u"You need to specify your company name.")))
     if errors:
         self.status = _(u"There were errors.")
         return
     if data['new_company'] is not None:
         self.context.company = data['new_company']
         self.context.company_id = createCompany(self.context, self.request,
                                                 self.context.username,
                                                 self.context.company)
     else:
         self.context.company_id = data['company']
         companies = vocabularies.companies(self.context)
         self.context.company = companies.getTerm(data['company']).title
     self.request.response.redirect(self.context.absolute_url())
Example #5
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()