def ajax_validate(self, targets=None, fields=None): """This is a validation method that is used by oc-js for presenting live validation to the user. It will return a python dictionary that will be eventually converted into a JSON response.""" # Working under the assumption that users don't need to be informed # when they haven't yet confirmed their password (because they're about # to), we set the correct confirmation password. ignore_password_confirmation = not self.request.form.get('confirm_password') validation_errors = ICreateMembers(self.portal).validate(self.request) if ignore_password_confirmation and 'confirm_password' in validation_errors: if validation_errors.get('password') == validation_errors['confirm_password']: del(validation_errors['password']) del(validation_errors['confirm_password']) ret = {} for error in validation_errors: # The AJAX submit only includes the field(s) that we are # validating, and so we have to remove errors that we don't want # displayed to the user. if error not in self.request.form: continue ret['oc-%s-error' % error] = { 'html': validation_errors[error].encode('utf-8','ignore'), 'action': 'copy', 'effects': 'highlight'} return ret
def _create_member(self, targets=None, fields=None, confirmed=False): """ tries to create a member object based on the request. returns the newly created member, or an error dictionary on failure. """ factory = ICreateMembers(self.portal) self.errors = factory.validate(self.request) viewlet_mgr = getMultiAdapter((self.context, self.request, self), name='opencore.create_account') if not hasattr(viewlet_mgr, 'viewlets'): # This means it hasn't had update() called yet. only do that once. viewlet_mgr.update() for viewlet in viewlet_mgr.viewlets: if hasattr(viewlet, 'validate'): self.errors.update(viewlet.validate()) if self.errors: # XXX let's raise something instead of returning. # it's ugly to overload function return values to signal errors. return self.errors for viewlet in viewlet_mgr.viewlets: if hasattr(viewlet, 'save'): viewlet.save() mem = factory.create(self.request.form) mem_name = mem.getFullname() or mem.getId() url = self._confirmation_url(mem) if utils.email_confirmation(): if not confirmed: self._send_mail_to_pending_user(user_name=mem_name, email=self.request.get('email'), url=url) self.addPortalStatusMessage(_(u'psm_thankyou_for_joining', u'Thanks for joining ${portal_title}, ${mem_id}!<br/>\nA confirmation email has been sent to you with instructions on activating your account.', mapping={u'mem_id':mem.getId(), u'portal_title':self.portal_title()})) portal_url = getToolByName(self.context, 'portal_url')() self.redirect(portal_url + '/message') return mem self.redirect(url) return mem
def _create(self): factory = ICreateMembers(self.portal) self.errors = factory.validate(self.request) viewlet_mgr = getMultiAdapter((self.context, self.request, self), name='opencore.create_account') if not hasattr(viewlet_mgr, 'viewlets'): # This means it hasn't had update() called yet. only do that once. viewlet_mgr.update() for viewlet in viewlet_mgr.viewlets: if hasattr(viewlet, 'validate'): self.errors.update(viewlet.validate()) if self.errors: return self.errors for viewlet in viewlet_mgr.viewlets: if hasattr(viewlet, 'save'): viewlet.save() mem = factory.create(self.request.form) mdc = getToolByName(self.context, 'portal_memberdata') mem_id = mem.getId() code = mem.getUserConfirmationCode() site_url = getToolByName(self.context, 'portal_url')() url = "%s/confirm-account?key=%s" % (site_url, code) self._send_mail_to_pending_user(id=mem_id, email=self.request.get('email'), url=url) self.addPortalStatusMessage(_('psm_thankyou_for_joining_to_team', u'Thanks for joining ${portal_title}, ${mem_id}!\nA confirmation email has been sent to you with instructions on activating your account. After you have activated your account, your request to join the ${project_noun} will be sent to the ${project_noun} administrators.', mapping={u'mem_id':mem_id, u'portal_title':self.portal_title(), u'project_noun': self.project_noun, })) return mdc._getOb(mem_id)