diff --git a/lms/djangoapps/verify_student/tests/test_views.py b/lms/djangoapps/verify_student/tests/test_views.py index c7cf5b13dc..5dfb00c0fe 100644 --- a/lms/djangoapps/verify_student/tests/test_views.py +++ b/lms/djangoapps/verify_student/tests/test_views.py @@ -25,6 +25,7 @@ from django.test.utils import override_settings from django.conf import settings from django.core.urlresolvers import reverse from django.core.exceptions import ObjectDoesNotExist +from django.core import mail from bs4 import BeautifulSoup from util.testing import UrlResetMixin @@ -923,6 +924,15 @@ class TestSubmitPhotosForVerification(UrlResetMixin, TestCase): response = self.client.post(url, params) self.assertEqual(response.status_code, expected_status_code) + + if expected_status_code == 200: + # Verify that photo submission confirmation email was sent + self.assertEqual(len(mail.outbox), 1) + self.assertEqual("Verification photos received", mail.outbox[0].subject) + else: + # Verify that photo submission confirmation email was not sent + self.assertEqual(len(mail.outbox), 0) + return response def _assert_full_name(self, full_name): diff --git a/lms/djangoapps/verify_student/views.py b/lms/djangoapps/verify_student/views.py index 74f86f0635..4e5f77505b 100644 --- a/lms/djangoapps/verify_student/views.py +++ b/lms/djangoapps/verify_student/views.py @@ -9,7 +9,7 @@ import datetime from collections import namedtuple from pytz import UTC -from edxmako.shortcuts import render_to_response +from edxmako.shortcuts import render_to_response, render_to_string from django.conf import settings from django.core.urlresolvers import reverse @@ -24,6 +24,7 @@ from django.views.generic.base import View from django.utils.decorators import method_decorator from django.utils.translation import ugettext as _, ugettext_lazy from django.contrib.auth.decorators import login_required +from django.core.mail import send_mail from openedx.core.djangoapps.user_api.api import profile as profile_api @@ -43,6 +44,7 @@ from xmodule.modulestore.exceptions import ItemNotFoundError from opaque_keys.edx.keys import CourseKey from .exceptions import WindowExpiredException from xmodule.modulestore.django import modulestore +from microsite_configuration import microsite from util.json_request import JsonResponse @@ -850,12 +852,14 @@ def submit_photos_for_verification(request): if SoftwareSecurePhotoVerification.user_has_valid_or_pending(request.user): return HttpResponseBadRequest(_("You already have a valid or pending verification.")) + username = request.user.username + # If the user wants to change his/her full name, # then try to do that before creating the attempt. if request.POST.get('full_name'): try: profile_api.update_profile( - request.user.username, + username, full_name=request.POST.get('full_name') ) except profile_api.ProfileUserNotFound: @@ -880,6 +884,21 @@ def submit_photos_for_verification(request): attempt.mark_ready() attempt.submit() + profile_dict = profile_api.profile_info(username) + if profile_dict: + # Send a confirmation email to the user + context = { + 'full_name': profile_dict.get('full_name'), + 'platform_name': settings.PLATFORM_NAME + } + + subject = _("Verification photos received") + message = render_to_string('emails/photo_submission_confirmation.txt', context) + from_address = microsite.get_value('default_from_email', settings.DEFAULT_FROM_EMAIL) + to_address = profile_dict.get('email') + + send_mail(subject, message, from_address, [to_address], fail_silently=False) + return HttpResponse(200) diff --git a/lms/templates/emails/photo_submission_confirmation.txt b/lms/templates/emails/photo_submission_confirmation.txt new file mode 100644 index 0000000000..028af4f22a --- /dev/null +++ b/lms/templates/emails/photo_submission_confirmation.txt @@ -0,0 +1,11 @@ +<%! from django.utils.translation import ugettext as _ %> + +${_("Hi {full_name},").format(full_name=full_name)} + +${_("Thanks for submitting your photos!")} + +${_("We've received your information and the verification process has begun. You can check the status of the verification process on your dashboard.")} + +${_("Thank you,")} + +${_("The {platform_name} team").format(platform_name=platform_name)}