示例#1
0
def ensure_user_blacklist_converts_to_setting(sender, user, request, **kwargs):
    """ Make sure on user login, that the user becomes a member of this portal """
    try:
        email = user.email
        if GlobalBlacklistedEmail.is_email_blacklisted(email):
            with transaction.atomic():
                GlobalBlacklistedEmail.remove_for_email(email)
                settings_obj = GlobalUserNotificationSetting.objects.get_object_for_user(user)
                settings_obj.setting = GlobalUserNotificationSetting.SETTING_NEVER
                settings_obj.save()
    except:
        # We fail silently, because we never want to 500 here unexpectedly
        logger.error("Error while trying to add User Portal Membership for user that has just logged in.")
        if settings.DEBUG:
            raise
示例#2
0
def add_email_to_blacklist(request, email, token):
    """ Adds an email to the email blacklist. Used for generating list-unsubscribe links in our emails.
        Use `email_blacklist_token_generator.make_token(email)` to generate a token. """
    
    if not is_email_valid(email):
        messages.error(request, _('The unsubscribe link you have clicked does not seem to be valid!') + ' (1)')
        return render(request, 'cosinnus/common/200.html')
    
    if not email_blacklist_token_generator.check_token(email, token):
        messages.error(request, _('The unsubscribe link you have clicked does not seem to be valid!') + ' (2)')
        return render(request, 'cosinnus/common/200.html')
    
    GlobalBlacklistedEmail.add_for_email(email)
    messages.success(request, _('We have unsubscribed your email "%(email)s" from our mailing list. You will not receive any more emails from us!') 
        % {'email': email})
    
    return render(request, 'cosinnus/common/200.html')
示例#3
0
def check_user_can_receive_emails(user):
    """ Checks if a user can receive emails *at all*, ignoring any frequency settings.
        This checks the global notification setting for authenticated users,
        and the email blacklist for anonymous users. """
    if not user.is_authenticated():
        return not GlobalBlacklistedEmail.is_email_blacklisted(user.email)
    else:
        return GlobalUserNotificationSetting.objects.get_for_user(user) > GlobalUserNotificationSetting.SETTING_NEVER
示例#4
0
def remove_user_from_blacklist(sender, profile, **kwargs):
    user = profile.user
    email = get_newly_registered_user_email(user)
    GlobalBlacklistedEmail.remove_for_email(email)