コード例 #1
0
def compose_and_send_adg_password_reset_email(user, request):
    """
    Prepare and send email for password reset

    Arguments:
        user (User): Django user object
        request (Request): Request Object

    Returns:
        None
    """
    reset_link = '{protocol}://{site}{link}?track=pwreset'.format(
        protocol='https' if request.is_secure() else 'http',
        site=configuration_helpers.get_value('SITE_NAME', settings.SITE_NAME),
        link=reverse('password_reset_confirm',
                     kwargs={
                         'uidb36': int_to_base36(user.id),
                         'token': default_token_generator.make_token(user),
                     }),
    )

    context = {
        'first_name': get_user_first_name(user),
        'reset_link': reset_link
    }

    task_send_mandrill_email(MandrillClient.PASSWORD_RESET, [user.email],
                             context)
コード例 #2
0
def send_application_status_update_email(application, message_for_applicant):
    """
    Informs applicants about the decision taken against their application.

    Args:
        application (UserApplication): Application object
        message_for_applicant (str): Admin message for applicant

    Returns:
        None
    """
    UserApplication = apps.get_model('applications', 'UserApplication')

    status_email_template_map = {
        UserApplication.ACCEPTED: MandrillClient.APPLICATION_ACCEPTED,
        UserApplication.WAITLIST: MandrillClient.APPLICATION_WAITLISTED
    }
    applicant = application.user
    email_context = {
        'first_name': get_user_first_name(applicant),
        'message_for_applicant': message_for_applicant,
    }

    task_send_mandrill_email.delay(
        status_email_template_map[application.status], [applicant.email],
        email_context)
コード例 #3
0
def test_get_user_first_name(first_name, full_name, expected_first_name):
    """
    Tests `get_user_first_name` helper
    """
    user = UserFactory(first_name=first_name)
    UserProfileFactory(user=user, name=full_name)

    assert get_user_first_name(user) == expected_first_name
コード例 #4
0
def send_adg_password_reset_success_email(user, request):
    """
    Sends edx default email if the environment is testing. Otherwise, sends adg password reset
    success email
    """
    from openedx.core.djangoapps.user_authn.views.password_reset import send_password_reset_success_email

    if is_testing_environment():
        send_password_reset_success_email(user, request)
        return

    root_url = configuration_helpers.get_value('LMS_ROOT_URL',
                                               settings.LMS_ROOT_URL)
    context = {
        'first_name': get_user_first_name(user),
        'signin_link': '{}/login'.format(root_url),
    }

    task_send_mandrill_email(MandrillClient.PASSWORD_RESET_SUCCESS,
                             [user.email], context)
コード例 #5
0
def test_compose_and_send_password_reset_success_email(
        user_with_profile, request, mocker, mock_mandrill_client,
        mock_task_send_mandrill_email):
    mock_is_test_env = mocker.patch(
        'openedx.adg.lms.student.helpers.is_testing_environment')
    mock_is_test_env.return_value = False

    mock_get_configuration_value = mocker.patch.object(
        student_helpers.configuration_helpers, 'get_value')
    mock_get_configuration_value.return_value = settings.LMS_ROOT_URL

    root_url = mock_get_configuration_value.return_value

    expected_context = {
        'first_name': get_user_first_name(user_with_profile),
        'signin_link': '{}/login'.format(root_url),
    }

    student_helpers.send_adg_password_reset_success_email(
        user_with_profile, request)
    mock_task_send_mandrill_email.assert_called_once_with(
        mock_mandrill_client.PASSWORD_RESET_SUCCESS, [user_with_profile.email],
        expected_context)
コード例 #6
0
def compose_and_send_adg_activation_email(user, activation_key):
    """
    Prepare and send email for account activation

    Arguments:
        user (User): Django user object
        activation_key (str): Activation key that will be sent as email content

    Returns:
        None
    """
    root_url = configuration_helpers.get_value('LMS_ROOT_URL',
                                               settings.LMS_ROOT_URL)
    activation_url = '{root_url}/activate/{activation_key}'.format(
        root_url=root_url, activation_key=activation_key)

    context = {
        'first_name': get_user_first_name(user),
        'activation_link': activation_url
    }

    task_send_mandrill_email(MandrillClient.USER_ACCOUNT_ACTIVATION,
                             [user.email], context)