diff --git a/common/djangoapps/student/tests/test_auto_auth.py b/common/djangoapps/student/tests/test_auto_auth.py index d94e89d097..0b5304bb54 100644 --- a/common/djangoapps/student/tests/test_auto_auth.py +++ b/common/djangoapps/student/tests/test_auto_auth.py @@ -43,7 +43,9 @@ class AutoAuthEnabledTestCase(UrlResetMixin, TestCase): """ self._auto_auth() self.assertEqual(User.objects.count(), 1) - self.assertTrue(User.objects.all()[0].is_active) + user = User.objects.all()[0] + self.assertTrue(user.is_active) + self.assertFalse(user.profile.requires_parental_consent()) def test_create_same_user(self): self._auto_auth(username='test') diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 9aad5d538a..8915934789 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -1758,13 +1758,14 @@ def auto_auth(request): # If successful, this will return a tuple containing # the new user object. try: - user, _profile, reg = _do_create_account(form) + user, profile, reg = _do_create_account(form) except AccountValidationError: # Attempt to retrieve the existing user. user = User.objects.get(username=username) user.email = email user.set_password(password) user.save() + profile = UserProfile.objects.get(user=user) reg = Registration.objects.get(user=user) # Set the user's global staff bit @@ -1776,6 +1777,12 @@ def auto_auth(request): reg.activate() reg.save() + # ensure parental consent threshold is met + year = datetime.date.today().year + age_limit = settings.PARENTAL_CONSENT_AGE_LIMIT + profile.year_of_birth = (year - age_limit) - 1 + profile.save() + # Enroll the user in a course if course_key is not None: CourseEnrollment.enroll(user, course_key)