def promote_member(user: _User, source: str) -> _User: """ Promote a user to Member role and change it's role on Email Marketing. 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() sync_user_on_discourse(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
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) try: _mailchimp_facade.create_or_update_client(user.first_name, user.email) except _MailChimpError: 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] )
def save_and_sent_password_email(first_name, email, source): form = validate_user(first_name, email, source) user = form.save() subject = 'Confira sua senha do Python Pro' change_password_uri = build_absolute_uri(reverse('core:profile_password')) ctx = { 'first_name': first_name, 'password': form.plain_password, 'change_password_uri': change_password_uri } msg = render_to_string('core/password_email.txt', context=ctx) send_mail(subject, msg, settings.DEFAULT_FROM_EMAIL, [user.email]) return user
def test_password_email_sent(resp_lead_creation_without_source, django_user_model, mailoutbox): assert len(mailoutbox) == 1 body = mailoutbox[0].body assert build_absolute_uri(reverse('core:profile_password')) in body