Exemple #1
0
def convert_to_stub_account(user):
    """Set all fields to as blank as possible.

    :param user: The user to operate on.
    :return: The new user object.
    """
    user.first_name = "Deleted"
    user.last_name = ""
    user.username = md5(user.email)
    user.set_unusable_password()
    user.save()

    profile = user.profile
    profile.address1 = None
    profile.address2 = None
    profile.barmembership = []
    profile.city = None
    profile.employer = None
    profile.state = None
    profile.stub_account = True
    profile.wants_newsletter = False
    profile.zip_code = None
    profile.save()

    return user
Exemple #2
0
def update_mailchimp(self, email, status):
    allowed_statuses = ["unsubscribed", "subscribed"]
    assert status in allowed_statuses, (
        "'%s' is not an allowed status." % status
    )
    md5_hash = md5(email)
    path = "/3.0/lists/%s/members/%s" % (MC_LIST_ID, md5_hash)
    try:
        r = requests.patch(
            urljoin(MC_BASE_URL, path),
            json={"status": status},
            headers={
                "Authorization": "apikey %s" % settings.MAILCHIMP_API_KEY
            },
        )
    except requests.RequestException as exc:
        abort_or_retry(self, exc)
        return
    if r.status_code == HTTP_200_OK:
        logger.info(
            "Successfully completed '%s' command on '%s' in mailchimp.",
            (status, email),
        )
    elif r.status_code == HTTP_404_NOT_FOUND:
        logger.info(
            "Did not complete '%s' command on '%s' in mailchimp. "
            "Address not found.",
            (status, email),
        )
    else:
        logger.warn(
            "Did not complete '%s' command on '%s' in mailchimp: '%s: %s'",
            (status, email, r.status_code),
        )
Exemple #3
0
def create_stub_account(
    user_data: Dict[str, str],
    profile_data: Dict[str, str],
) -> Tuple[User, UserProfile]:
    """Create a minimal user account in CL

    This can be helpful when receiving anonymous donations, payments from
    external applications like XERO, etc.

    :param user_data: Generally cleaned data from a cl.donate.forms.UserForm
    :type user_data: dict
    :param profile_data: Generally cleaned data from a
    cl.donate.forms.ProfileForm
    :type profile_data: dict
    :return: A tuple of a User and UserProfile objects
    """
    with transaction.atomic():
        email = user_data["email"]
        new_user = User.objects.create_user(
            # Use a hash of the email address to reduce the odds of somebody
            # wanting to create an account that already exists. We'll change
            # this to good values later, when/if the stub account is upgraded
            # to a real account with a real username.
            md5(email),
            email,
        )
        new_user.first_name = user_data["first_name"]
        new_user.last_name = user_data["last_name"]

        # Associate a profile
        profile = UserProfile.objects.create(
            user=new_user,
            stub_account=True,
            address1=profile_data["address1"],
            address2=profile_data.get("address2"),
            city=profile_data["city"],
            state=profile_data["state"],
            zip_code=profile_data["zip_code"],
            wants_newsletter=profile_data["wants_newsletter"],
        )
    return new_user, profile