def send_invitation_email(obj, event): if not getattr(obj, 'sendInvitation', True): return mailhost = getToolByName(obj, 'MailHost') urltool = getToolByName(obj, 'portal_url') portal = urltool.getPortalObject() activation_code = ''.join( random.sample(string.ascii_lowercase + string.digits, 8)) obj.activation_code = activation_code subject = _( u"You've been invited to ${site_title}", mapping=dict( site_title=portal.getProperty('title'), )) body = _(INVITATION_TEMPLATE, mapping=dict( name=obj.title, site_title=portal.getProperty('title'), url=obj.absolute_url(), activation_code=activation_code, )) # Construct and send a message message = message_from_string(obj.translate(body).encode('utf-8')) message.set_charset('utf-8') message['From'] = u"%s <%s>" % (portal.getProperty('title'), portal.getProperty('email_from_address'), ) message['To'] = u"%s <%s>" % (obj.title.replace('@', '[at]'), obj.emailAddress) message['Subject'] = Header(obj.translate(subject), 'utf-8') mailhost.send(message)
def id(value): reg_tool = getToolByName(get_site(), "portal_registration") if not reg_tool.isMemberIdAllowed(value): raise Invalid( _(u"A user with the id '${id}' already exists or " u"the id is not allowed.", mapping={"id": value}) ) catalog = getToolByName(getSite(), "portal_catalog") results = catalog.unrestrictedSearchResults( object_provides="ixds.covalent.behaviors.covalent_member.ICovalentMember", id=value ) if results: raise Invalid(_(u"A user with the id '${id}' is already invited", mapping={"id": value})) return True
def extract_memberdata(filedata): user_infos = [] book = open_workbook(file_contents=filedata) sheet = book.sheets()[0] if [h.value for h in sheet.row(0)[:3]] != [u"Fullname", u"Id", u"Email address"]: raise Invalid(_(u"Your Excel sheet is not properly formatted")) curr_row = 0 while True: curr_row += 1 try: row = sheet.row(curr_row) except IndexError: break if not row[0].value.strip(): continue id = row[1].value title = row[0].value emailAddress = row[2].value validators.id(id) validators.email(emailAddress) user_infos.append(dict(id=id, title=title, emailAddress=emailAddress)) return user_infos
def activation_code_valid(self): if self.activation_code == self.context.activation_code: return True IStatusMessage(self.request).addStatusMessage( _(u"Invalid activation code."), "error") return False
def id(value): reg_tool = getToolByName(get_site(), 'portal_registration') if not reg_tool.isMemberIdAllowed(value): raise Invalid(_(u"A user with the id '${id}' already exists or " u"the id is not allowed.", mapping={'id': value})) catalog = getToolByName(getSite(), 'portal_catalog') results = catalog.unrestrictedSearchResults( object_provides='ixds.covalent.interfaces.ICovalentMember', id=value, ) if results: raise Invalid(_(u"A user with the id '${id}' already exists ", mapping={'id': value})) return True
def updateActions(self): if not self.terms_accepted: name = 'proceed' caption = _("Proceed") handler = self.__class__.proceedHandler else: name = 'complete' caption = _("Complete activation") handler = self.__class__.completeHandler but = button.Button(name, title=caption) self.buttons = button.Buttons(but) handler = button.Handler(but, handler) self.handlers = getattr(self, 'handlers', button.Handlers()) self.handlers.addHandler(but, handler) return super(ActivateForm, self).updateActions()
def send_approve_email(obj, event): mtool = getToolByName(obj, 'portal_membership') currentUser = mtool.getAuthenticatedMember() userRoles = currentUser.getRoles() isAdmin = 'Manager' in userRoles or 'Site Administrator' in userRoles if isAdmin: # 1. admin or manager created the new member: approve automatically obj.registeredSelf = False utilities.auto_approve_member_object(obj) else: # 2. member registered himself: request approval from admin obj.registeredSelf = True mailhost = getToolByName(obj, 'MailHost') urltool = getToolByName(obj, 'portal_url') portal = urltool.getPortalObject() subject = _(u"Please approve or reject new member ${name}", mapping=dict(name=obj.title)) body = _(MEMBER_REQUEST_TEMPLATE, mapping=dict( member_url=obj.absolute_url(), userId=obj.id, site_title=portal.getProperty('title'), name=obj.title )) group = portal.acl_users.getGroupById('Site Administrators') for m in group.getGroupMembers(): email = m.getProperty('email') if email is not None: # Construct and send a message message = message_from_string(obj.translate(body).encode('utf-8')) message.set_charset('utf-8') message['From'] = u"%s <%s>" % (portal.getProperty('title'), portal.getProperty('email_from_address'), ) name = m.getProperty('fullname') if name is not None: name = name.decode("utf-8") message['To'] = u"%s <%s>" % (name.replace('@', '[at]'), email) else: message['To'] = u"<%s>" % email message['Subject'] = Header(obj.translate(subject), 'utf-8') mailhost.send(message)
def activation_code_valid(self): if self.activation_code == self.context.activation_code: return True from Products.statusmessages.interfaces import IStatusMessage IStatusMessage(self.request).addStatusMessage( _(u"Invalid activation code."), "error") return False
def is_member_pending(self): wf = getToolByName(self.context, 'portal_workflow') review_state = wf.getInfoFor(self.context, 'review_state') if review_state == 'pending': return True elif review_state == 'expired': IStatusMessage(self.request).addStatusMessage( _(u"Your activation code expired. Please use the feedback form to contact the site administrator."), "error") return False
def terms_accepted(value): if not value: raise Invalid( _(u"You have to read the terms of use and agree to them first.")) return True
def email(value): regtool = getToolByName(get_site(), 'portal_registration') if not regtool.isValidEmail(value): raise Invalid(_(u"Invalid email address '${addr}'", mapping={'addr': value})) return True
def send_invitation_email(obj, event): if not getattr(obj, 'sendInvitation', True): return if event.action != 'approve' and event.action != 'approve_again' and event.action != 'reject': return mailhost = getToolByName(obj, 'MailHost') urltool = getToolByName(obj, 'portal_url') portal = urltool.getPortalObject() activation_code = ''.join( random.sample(string.ascii_lowercase + string.digits, 8)) obj.activation_code = activation_code if event.action == 'approve' or event.action == 'approve_again': registered_self = obj.registeredSelf if hasattr(obj, 'registeredSelf') else False if registered_self: subject_tpl = u"Your membership request for the ${site_title} site has been approved" body_tpl = APPROVAL_TEMPLATE else: subject_tpl = u"You've been invited to ${site_title}" body_tpl = INVITATION_TEMPLATE registry = getUtility(IRegistry) activation_period = registry['cnrd.vctypes.memberActivationTimeout'] subject = _( subject_tpl, mapping=dict( site_title=portal.getProperty('title'), )) body = _(body_tpl, mapping=dict( name=obj.title, userId=obj.id, site_title=portal.getProperty('title'), url=obj.absolute_url(), activation_code=activation_code, activation_period=activation_period )) if event.action == 'reject': subject = _( u"Your member request for the ${site_title} site has been rejected", mapping=dict( site_title=portal.getProperty('title'), )) body = _(REJECT_TEMPLATE, mapping=dict( name=obj.title, site_title=portal.getProperty('title'), )) # Construct and send a message message = message_from_string(obj.translate(body).encode('utf-8')) message.set_charset('utf-8') message['From'] = u"%s <%s>" % (portal.getProperty('title'), portal.getProperty('email_from_address'), ) message['To'] = u"%s <%s>" % (obj.title.replace('@', '[at]'), obj.emailAddress) message['Subject'] = Header(obj.translate(subject), 'utf-8') mailhost.send(message)