Ejemplo n.º 1
0
def register_lead(first_name: str,
                  email: str,
                  source: str = 'unknown') -> _User:
    """
    Create a new user on the system generation a random password.
    An Welcome email is sent to the user informing his password with the link to change it.
    User is also registered on Mailchimp and subscribed to LeadWorkflow and is not registered on system in case api call
    fails

    :param first_name: User's first name
    :param email: User's email
    :param source: source of User traffic
    :return: User
    """
    if not source:
        source = 'unknown'
    form = _core_facade.validate_user(first_name, email, source)
    try:
        _email_marketing_facade.create_or_update_lead(first_name, email)
    except _ActiveCampaignError:
        form.add_error('email', 'Email Inválido')
        raise UserCreationException(form)
    lead = _core_facade.register_lead(first_name, email, source)
    _discourse_facade.sync_user(lead)
    _email_marketing_facade.create_or_update_lead(first_name,
                                                  email,
                                                  id=lead.id)

    return lead
Ejemplo n.º 2
0
def promote_member(user: _User, source: str) -> _User:
    """
    Promote a user to Member role and change it's role on Mailchimp. Will not fail in case API call fails.
    Email welcome email is sent to user
    :param source: source of traffic
    :param user:
    :return:
    """
    _core_facade.promote_to_member(user, source)
    _cohorts_facade.subscribe_to_last_cohort(user)
    cohort = _cohorts_facade.find_most_recent_cohort()
    _discourse_facade.sync_user(user)
    try:
        _email_marketing_facade.create_or_update_member(user.first_name,
                                                        user.email,
                                                        id=user.id)
        _email_marketing_facade.tag_as(user.email, user.id,
                                       f'turma-{cohort.slug}')
    except _ActiveCampaignError:
        pass
    email_msg = render_to_string(
        'payments/membership_email.txt', {
            'user': user,
            'cohort_detail_url': build_absolute_uri(cohort.get_absolute_url())
        })
    _send_mail(
        f'Inscrição na Turma {cohort.title} realizada! Confira o link com detalhes.',
        email_msg, _settings.DEFAULT_FROM_EMAIL, [user.email])
    return user
Ejemplo n.º 3
0
def force_register_client(first_name: str,
                          email: str,
                          source: str = 'unknown') -> _User:
    """
    Create a new user on the system generation a random password or update existing one based on email.
    An Welcome email is sent to the user informing his password with the link to change it.
    User is also registered on Mailchimp. But she will be registered even if api call fails
    :param first_name: User's first name
    :param email: User's email
    :param source: source of User traffic
    :return: User
    """
    user = _core_facade.register_client(first_name, email, source)
    _discourse_facade.sync_user(user)
    try:
        _email_marketing_facade.create_or_update_client(first_name,
                                                        email,
                                                        id=user.id)
    except _ActiveCampaignError:
        pass
    return user
Ejemplo n.º 4
0
def force_register_member(first_name, email, source='unknown'):
    """
    Create a new user on the system generation a random password or update existing one based on email.
    An Welcome email is sent to the user informing his password with the link to change it.
    User is also registered on Mailchimp. But she will be registered even if api call fails
    :param first_name: User's first name
    :param email: User's email
    :param source: source of User traffic
    :return: User
    """
    user = _core_facade.register_member(first_name, email, source)
    _cohorts_facade.subscribe_to_last_cohort(user)
    cohort = _cohorts_facade.find_most_recent_cohort()
    _discourse_facade.sync_user(user)
    try:
        _email_marketing_facade.create_or_update_member(first_name,
                                                        email,
                                                        id=user.id)
        _email_marketing_facade.tag_as(email, user.id, f'turma-{cohort.slug}')
    except _ActiveCampaignError:
        pass
    return user
Ejemplo n.º 5
0
def promote_client(user: _User, source: str) -> None:
    """
    Promote a user to Client role and change it's role on Mailchimp. Will not fail in case API call fails.
    Email welcome email is sent to user
    :param source: source of traffic
    :param user:
    :return:
    """
    _core_facade.promote_to_client(user, source)
    _discourse_facade.sync_user(user)
    try:
        _email_marketing_facade.create_or_update_client(user.first_name,
                                                        user.email,
                                                        id=user.id)
    except _ActiveCampaignError:
        pass
    email_msg = render_to_string(
        'payments/pytools_email.txt', {
            'user': user,
            'ty_url': build_absolute_uri(reverse('payments:pytools_thanks'))
        })
    _send_mail(
        'Inscrição no curso Pytools realizada! Confira o link com detalhes.',
        email_msg, _settings.DEFAULT_FROM_EMAIL, [user.email])
Ejemplo n.º 6
0
def test_user_sync(logged_user, resps):
    facade.sync_user(logged_user)
Ejemplo n.º 7
0
def test_no_integration_on_debug_and_missing_config(settings, no_responses):
    settings.DISCOURSE_API_USER = ''
    settings.DISCOURSE_API_KEY = ''
    settings.DEBUG = True
    assert facade.sync_user(None) is None
Ejemplo n.º 8
0
def test_missing_discourse_api_user(settings, no_responses):
    settings.DISCOURSE_API_USER = ''
    settings.DEBUG = False
    with pytest.raises(facade.MissingDiscourseAPICredentials):
        facade.sync_user(None)