Example #1
0
 def register_success(self, appstruct):
     #FIXME: Protect against spamming?
     email = appstruct['email']
     factory = self.get_content_factory(u'Token')
     token = factory()
     rtokens = IRegistrationTokens(self.context)
     rtokens[email] = token
     html = self.render_template("arche:templates/emails/register.pt", token = token, email = email)
     send_email(_(u"Registration link"),
                [email],
                html,
                request = self.request,
                send_immediately = True)
     self.flash_messages.add(_(u"A mail with registration instructions have been sent!" + html), type="success")
     return HTTPFound(location = self.request.resource_url(self.root))
Example #2
0
def send_invite_ticket(ticket, request, message = ""):
    if ticket.closed: #Just as a precaution
        return
    meeting = find_interface(ticket, IMeeting)
    html = render_invite_ticket(ticket, request, message = message)
    subject = _(u"Invitation to ${meeting_title}", mapping = {'meeting_title': meeting.title})
    if send_email(request, subject = subject, recipients = ticket.email, html = html, send_immediately = True):
        ticket.sent_dates.append(utcnow())
Example #3
0
 def send_success(self, appstruct):
     self.flash_messages.add(_(u"Message sent"), type="success")
     factory = self.get_content_factory(u'Token')
     email_or_userid = appstruct['email_or_userid']
     if '@' in email_or_userid:
         user = self.context['users'].get_user_by_email(email_or_userid)
     else:
         user = self.context['users'].get(email_or_userid, None)
     if user is None:
         raise HTTPForbidden("Something went wrong during login. No user profile found.")
     user.pw_token = factory()
     html = self.render_template("arche:templates/emails/recover_password.pt", user = user)
     send_email(_(u"Password recovery request"),
                [user.email],
                html,
                request = self.request)
     return HTTPFound(location = self.request.resource_url(self.root))
Example #4
0
 def save_success(self, appstruct):
     nr_of_users = 0
     if not appstruct['users']:
         return HTTPFound(location = self.request.resource_url(self.context))
     for uid in appstruct['users']:
             user = self.resolve_uid(uid)
             fikauser = IFikaUser(self.resolve_uid(uid), None)
             if fikauser is not None:
                 fikauser.join_course(self.context)
                 email_html = '<h4>Hello '+user.first_name+' '+user.last_name+ \
                             ',</h4><p>You have been assigned to the course \"'+self.context.title+ \
                             '\" by '+self.profile.first_name + ' ' + self.profile.last_name+'. You will now see it in the \'My Courses\' list when you log in to '+self.root.title+'.'
                 send_email(self.request, 'You have been assigned a course', user.email, email_html, send_immediately=True)
                 nr_of_users += 1
     plural = "s" if nr_of_users != 1 else ""
     self.flash_messages.add(_(u"Assigned course to "+str(nr_of_users)+" user"+plural+"."), type="success")
     return HTTPFound(location = self.request.resource_url(self.context))
Example #5
0
 def register_success(self, appstruct):
     #FIXME: Protect against spamming?
     email = appstruct['email']
     factory = self.get_content_factory(u'Token')
     token = factory()
     rtokens = IRegistrationTokens(self.context)
     rtokens[email] = token
     html = self.render_template("arche:templates/emails/register.pt",
                                 token=token,
                                 email=email)
     send_email(_(u"Registration link"), [email],
                html,
                request=self.request,
                send_immediately=True)
     self.flash_messages.add(
         _(u"A mail with registration instructions have been sent!" + html),
         type="success")
     return HTTPFound(location=self.request.resource_url(self.root))
Example #6
0
 def send_success(self, appstruct):
     self.flash_messages.add(_(u"Message sent"), type="success")
     factory = self.get_content_factory(u'Token')
     email_or_userid = appstruct['email_or_userid']
     if '@' in email_or_userid:
         user = self.context['users'].get_user_by_email(email_or_userid)
     else:
         user = self.context['users'].get(email_or_userid, None)
     if user is None:
         raise HTTPForbidden(
             "Something went wrong during login. No user profile found.")
     user.pw_token = factory()
     html = self.render_template(
         "arche:templates/emails/recover_password.pt", user=user)
     send_email(_(u"Password recovery request"), [user.email],
                html,
                request=self.request)
     return HTTPFound(location=self.request.resource_url(self.root))
Example #7
0
 def email_feedback(self):
     user_uid = self.request.POST.get('user_uid')
     feedback = self.request.POST.get('feedback')
     from_email = self.request.POST.get('from')
     user = self.resolve_uid(user_uid)
     success = send_email(self.request, 'Feedback on your answers in course '+self.context.title, user.email, feedback, sender=from_email, plaintext=feedback, send_immediately=True)
     if success != None:
         self.flash_messages.add(_(u"Email with feedback send to "+user.title+"."), type="success")
     else:
         self.flash_messages.add(_(u"Could not send email feedback to "+user.title+"."), type="danger")
     return HTTPFound(location = self.request.resource_url(self.context, 'responses_overview'))
Example #8
0
def email_voters_about_ongoing_poll(poll, request=None):
    """ Email voters about that a poll they have voting permission in is open.
        I.e. in state ongoing.
        This function is triggered by a workflow subscriber, so not all functionality
        is nested in the workflow callback. (It would make permission tests very
        annoying and hard to write otherwise)

        Note that there's a setting on the meeting called poll_notification_setting
        that controls wether this should be executed or not.
    """
    meeting = find_interface(poll, IMeeting)
    assert meeting
    if not meeting.get_field_value('poll_notification_setting', False):
        return
    if request is None:
        request = get_current_request()
    userids = security.find_authorized_userids(poll, (security.ADD_VOTE, ))
    root = find_root(meeting)
    users = root['users']
    email_addresses = set()
    for userid in userids:
        #In case user is deleted, they won't have the required permission either
        #find_authorized_userids loops through the users folder
        email = users[userid].email
        if email:
            email_addresses.add(email)
    response = {}
    response['meeting'] = meeting
    response['meeting_url'] = request.resource_url(meeting)
    response['poll_url'] = request.resource_url(poll)
    sender = "%s <%s>" % (meeting.get_field_value('meeting_mail_name'),
                          meeting.get_field_value('meeting_mail_address'))
    body_html = render(
        'voteit.core:templates/email/ongoing_poll_notification.pt',
        response,
        request=request)
    #Since subject won't be part of a renderer, we need to translate it manually
    #Keep the _ -syntax otherwise Babel/lingua won't pick up the string
    subject = _(u"VoteIT: Open poll")
    for email in email_addresses:
        send_email(request, subject, [email], body_html)
def send_invite_ticket(ticket, request, message=""):
    if ticket.closed:  #Just as a precaution
        return
    meeting = find_interface(ticket, IMeeting)
    html = render_invite_ticket(ticket, request, message=message)
    subject = _(u"Invitation to ${meeting_title}",
                mapping={'meeting_title': meeting.title})
    if send_email(request,
                  subject=subject,
                  recipients=ticket.email,
                  html=html,
                  send_immediately=True):
        ticket.sent_dates.append(utcnow())
Example #10
0
def claim_and_send_notification(ticket, request, message = ""):
    """ When a ticket was added for a user that already
        has a validated email address, that ticket should be
        used right away, and the user notified.
    """
    if ticket.closed: #Just as a precaution
        return
    user = claim_ticket(ticket, request, ticket.email)
    meeting = find_interface(ticket, IMeeting)
    html = render_claimed_ticket_notification(ticket, request, message = message, user = user)
    subject = _(u"${meeting_title} is now accessible", mapping = {'meeting_title': meeting.title})
    if send_email(request, subject = subject, recipients = ticket.email, html = html, send_immediately = True):
        ticket.sent_dates.append(utcnow())
Example #11
0
 def send_success(self, appstruct):
     sender = appstruct['email'] and appstruct['email'] or None
     response = {
         'meeting': self.request.meeting,
         'name': appstruct['name'],
         'email': appstruct['email'],
         'subject': appstruct['subject'],
         'message': appstruct['message'],
         'meeting_title': appstruct.get('meeting_title', ''),
     }
     body_html = render('voteit.core:templates/email/support.pt',
                        response,
                        request=self.request)
     title = "%s %s" % (self.root.head_title,
                        self.request.localizer.translate(_("Support")))
     subject = "[%s] | %s" % (title, appstruct['subject'])
     send_email(self.request,
                subject, [self.root.support_email],
                body_html,
                sender=sender,
                send_immediately=True)
     self.flash_messages.add(_("Message sent"))
     return HTTPFound(location=self.request.resource_url(self.context))
def claim_and_send_notification(ticket, request, message=""):
    """ When a ticket was added for a user that already
        has a validated email address, that ticket should be
        used right away, and the user notified.
    """
    if ticket.closed:  #Just as a precaution
        return
    user = claim_ticket(ticket, request, ticket.email)
    meeting = find_interface(ticket, IMeeting)
    html = render_claimed_ticket_notification(ticket,
                                              request,
                                              message=message,
                                              user=user)
    subject = _(u"${meeting_title} is now accessible",
                mapping={'meeting_title': meeting.title})
    if send_email(request,
                  subject=subject,
                  recipients=ticket.email,
                  html=html,
                  send_immediately=True):
        ticket.sent_dates.append(utcnow())