Exemplo n.º 1
0
def notify_signup_accepted(event_name, signup):
    """Send an email to a user, that his signup was accepted"""
    id_field = current_app.config['ID_FIELD']

    if signup.get('user'):
        lookup = {id_field: signup['user']}
        user = current_app.data.find_one('users', None, **lookup)
        name = user['firstname']
        email = user['email']
    else:
        name = 'Guest of AMIV'
        email = signup['email']

    token = Signer(get_token_secret()).sign(
        str(signup[id_field]).encode('utf-8'))

    if current_app.config.get('SERVER_NAME') is None:
        current_app.logger.warning("SERVER_NAME is not set. E-Mail links "
                                   "will not work!")

    deletion_link = url_for('emails.on_delete_signup',
                            token=token,
                            _external=True)

    mail(
        current_app.config['API_MAIL'], email, '[AMIV] Eventsignup accepted',
        'Hello %s!\n'
        '\n'
        'We are happy to inform you that your signup for %s was accepted and '
        'you can come to the event! If you do not have time to attend the '
        'event please click this link to free your spot for someone else:\n'
        '\n%s\n\n'
        'Best Regards,\n'
        'The AMIV event bot' % (name, event_name, deletion_link))
Exemplo n.º 2
0
def send_confirmmail_to_unregistered_users(items):
    """Send a confirmation email for external signups(email only)

    Args:
        item: The item, which was just inserted into the database
    """
    for item in items:
        if 'user' not in item:
            event = current_app.data.find_one(
                'events', None,
                **{current_app.config['ID_FIELD']: item['event']})

            if 'title_en' in event:
                title = event['title_en']
            else:
                title = event['title_de']

            token = Signer(get_token_secret()).sign(
                str(item['_id']).encode('utf-8'))

            if current_app.config.get('SERVER_NAME') is None:
                current_app.logger.warning("SERVER_NAME is not set. E-Mail "
                                           "links will not work!")

            fields = {
                'link': url_for('emails.on_confirm_email', token=token,
                                _external=True),
                'title': title
            }
            email_content = current_app.config['CONFIRM_EMAIL_TEXT'] % fields

            mail(current_app.config['API_MAIL'],  # from
                 [item['email']],  # receivers list
                 'Registration for AMIV event %s' % title,
                 email_content)
Exemplo n.º 3
0
def notify_delete_blacklist(item):
    """Send an email to a user if one of his entries was deleted."""
    email = _get_email(item)
    fields = {'reason': item['reason']}

    mail(email, 'Your blacklist entry has been removed!',
         current_app.config['BLACKLIST_REMOVED'].format(**fields))
Exemplo n.º 4
0
def notify_signup_deleted(signup):
    """Send an email to a user that his signup was deleted"""
    id_field = current_app.config['ID_FIELD']

    if signup.get('user'):
        lookup = {id_field: signup['user']}
        user = current_app.data.find_one('users', None, **lookup)
        if user is None:  # User was deleted
            return
        name = user['firstname']
        email = user['email']
    else:
        name = 'Guest of AMIV'
        email = signup['email']

    event = current_app.data.find_one(
        'events', None, **{current_app.config['ID_FIELD']: signup['event']})

    if current_app.config.get('SERVER_NAME') is None:
        current_app.logger.warning("SERVER_NAME is not set. E-Mail links "
                                   "will not work!")

    mail([email], 'Successfully deregistered from %s' % event.get('title_en')
         or event.get('title_de'),
         current_app.config['DEREGISTER_EMAIL_TEXT'].format(
             name=name, title=event.get('title_en') or event.get('title_de')))
Exemplo n.º 5
0
def send_confirmmail_to_unregistered_users(items):
    """Send a confirmation email for external signups(email only)

    Args:
        item: The item, which was just inserted into the database
    """
    for item in items:
        if item.get('user') is None:
            event = current_app.data.find_one(
                'events', None,
                **{current_app.config['ID_FIELD']: item['event']})

            title = event.get('title_en') or event.get('title_de')

            s = URLSafeSerializer(get_token_secret())
            token = s.dumps(str(item['_id']))

            if current_app.config.get('SERVER_NAME') is None:
                current_app.logger.warning("SERVER_NAME is not set. E-Mail "
                                           "links will not work!")

            confirm_link = url_for('emails.on_confirm_email',
                                   token=token,
                                   _external=True)

            mail([item['email']], 'Registration for %s' % title,
                 current_app.config['CONFIRM_EMAIL_TEXT'].format(
                     title=title, link=confirm_link))
Exemplo n.º 6
0
def send_confirmmail_to_unregistered_users(items):
    """Send a confirmation email for external signups(email only)

    Args:
        item: The item, which was just inserted into the database
    """
    for item in items:
        if 'user' not in item:
            event = current_app.data.find_one(
                'events', None,
                **{current_app.config['ID_FIELD']: item['event']})

            title = event.get('title_en') or event.get('title_de')

            s = URLSafeSerializer(get_token_secret())
            token = s.dumps(str(item['_id']))

            if current_app.config.get('SERVER_NAME') is None:
                current_app.logger.warning("SERVER_NAME is not set. E-Mail "
                                           "links will not work!")

            confirm_link = url_for('emails.on_confirm_email', token=token,
                                   _external=True)

            mail([item['email']],
                 'Registration for %s' % title,
                 current_app.config['CONFIRM_EMAIL_TEXT'].format(
                     title=title,
                     link=confirm_link))
Exemplo n.º 7
0
def notify_delete_blacklist(item):
    """Send an email to a user if one of his entries was deleted."""
    email = _get_email(item)
    fields = {'reason': item['reason']}

    mail(email, 'Your blacklist entry has been removed!',
         current_app.config['BLACKLIST_REMOVED'].format(**fields))
Exemplo n.º 8
0
def notify_signup_accepted(event, signup):
    """Send an email to a user that his signup was accepted"""
    id_field = current_app.config['ID_FIELD']

    if signup.get('user'):
        lookup = {id_field: signup['user']}
        user = current_app.data.find_one('users', None, **lookup)
        name = user['firstname']
        email = user['email']
    else:
        name = 'Guest of AMIV'
        email = signup['email']

    s = URLSafeSerializer(get_token_secret())
    token = s.dumps(str(signup[id_field]))

    if current_app.config.get('SERVER_NAME') is None:
        current_app.logger.warning("SERVER_NAME is not set. E-Mail links "
                                   "will not work!")

    deletion_link = url_for('emails.on_delete_signup', token=token,
                            _external=True)

    mail([email],
         'Eventsignup accepted',
         current_app.config['ACCEPT_EMAIL_TEXT'].format(
             name=name,
             title=event.get('title_en') or event.get('title_de'),
             link=deletion_link,
             deadline=event['time_register_end'].strftime('%H.%M %d.%m.%Y')))
Exemplo n.º 9
0
def notify_signup_accepted(event, signup):
    """Send an email to a user that his signup was accepted"""
    id_field = current_app.config['ID_FIELD']

    if signup.get('user'):
        lookup = {id_field: signup['user']}
        user = current_app.data.find_one('users', None, **lookup)
        name = user['firstname']
        email = user['email']
    else:
        name = 'Guest of AMIV'
        email = signup['email']

    s = URLSafeSerializer(get_token_secret())
    token = s.dumps(str(signup[id_field]))

    if current_app.config.get('SERVER_NAME') is None:
        current_app.logger.warning("SERVER_NAME is not set. E-Mail links "
                                   "will not work!")

    deletion_link = url_for('emails.on_delete_signup',
                            token=token,
                            _external=True)

    mail([email], 'Eventsignup accepted',
         current_app.config['ACCEPT_EMAIL_TEXT'].format(
             name=name,
             title=event.get('title_en') or event.get('title_de'),
             link=deletion_link,
             deadline=event['time_register_end'].strftime('%H.%M %d.%m.%Y')))
Exemplo n.º 10
0
def send_removed_mail(item):
    """Schedules an email when end_time is reached and the entry is removed."""
    # Check that the end date is still correct and has not changed again
    _item = current_app.data.find_one('blacklist', None, {"_id": item['_id']})
    if _item is None:
        return  # Entry was deleted, no mail to send anymore

    # Note: We have to remove the (empty) tzinfo from dates coming from the db
    if _item['end_time'].replace(tzinfo=None) == item['end_time']:
        email = _get_email(_item)
        fields = {'reason': _item['reason']}
        mail(email, 'Your blacklist entry has been removed!',
             current_app.config['BLACKLIST_REMOVED'].format(**fields))
Exemplo n.º 11
0
def send_removed_mail(item):
    """Schedules an email when end_time is reached and the entry is removed."""
    # Check that the end date is still correct and has not changed again
    _item = current_app.data.find_one('blacklist', None, {"_id": item['_id']})
    if _item is None:
        return  # Entry was deleted, no mail to send anymore

    # Note: We have to remove the (empty) tzinfo from dates coming from the db
    if _item['end_time'].replace(tzinfo=None) == item['end_time']:
        email = _get_email(_item)
        fields = {'reason': _item['reason']}
        mail(email,
             'Your blacklist entry has been removed!',
             current_app.config['BLACKLIST_REMOVED'].format(**fields))
Exemplo n.º 12
0
def send_removed_mail(item):
    """Send scheduled email when a blacklist entry times out."""
    _item = current_app.data.find_one('blacklist', None, {"_id": item['_id']})
    # Check that the end date is still correct and has not changed again
    if _item is None:
        return  # Entry was deleted, no mail to send anymore
    if _item.get('end_time') is None:
        return  # Entry was patched to last indefinitely, so no mail to send.
    if _item['end_time'].replace(tzinfo=None) != item['end_time']:
        return  # Entry was edited, so this is outdated.

    email = _get_email(_item)
    fields = {'reason': _item['reason']}
    mail(email,
         'Your blacklist entry has been removed!',
         current_app.config['BLACKLIST_REMOVED'].format(**fields))
Exemplo n.º 13
0
def notify_new_blacklist(items):
    """Send an email to a user who has a new blacklist entry."""
    for item in items:
        email = _get_email(item)
        fields = {
            'reason': item['reason'],
            'reply_to': current_app.config['BLACKLIST_REPLY_TO']
        }

        if item['price']:
            fields['price'] = item['price'] / 100  # convert Rappen to CHF
            template = current_app.config['BLACKLIST_ADDED_EMAIL_W_PRICE']
        else:
            template = current_app.config['BLACKLIST_ADDED_EMAIL_WO_PRICE']

        mail(email, 'You have been blacklisted!', template.format(**fields))

        # If the end time is already known, schedule removal mail
        if item['end_time'] and item['end_time'] > datetime.utcnow():
            schedule_task(item['end_time'], send_removed_mail, item)
Exemplo n.º 14
0
def notify_new_blacklist(items):
    """Send an email to a user who has a new blacklist entry."""
    for item in items:
        email = _get_email(item)
        fields = {
            'reason': item['reason'],
            'reply_to': current_app.config['BLACKLIST_REPLY_TO']
        }

        if item['price']:
            fields['price'] = item['price']/100  # convert Rappen to CHF
            template = current_app.config['BLACKLIST_ADDED_EMAIL_W_PRICE']
        else:
            template = current_app.config['BLACKLIST_ADDED_EMAIL_WO_PRICE']

        mail(email, 'You have been blacklisted!', template.format(**fields))

        # If the end time is already known, schedule removal mail
        if item['end_time'] and item['end_time'] > datetime.utcnow():
            schedule_task(item['end_time'], send_removed_mail, item)