diff --git a/cms/urls.py b/cms/urls.py index 019a25f8b9f2..c0cc9a719763 100644 --- a/cms/urls.py +++ b/cms/urls.py @@ -24,7 +24,7 @@ from openedx.core.djangoapps.password_policy.forms import PasswordPolicyAwareAdminAuthForm from openedx.core import toggles as core_toggles -from common.djangoapps.student.views.management import extras_course_enroll_user +from common.djangoapps.student.views.management import extras_course_enroll_user, extras_update_user_details from cms.djangoapps.contentstore.views.course import extras_create_course from cms.djangoapps.contentstore.views.course import extras_get_moodle_login_url @@ -194,6 +194,7 @@ re_path(r'^extras/create_course', extras_create_course, name = 'extras_create_course'), re_path(r'^extras/course_enroll_user', extras_course_enroll_user, name = 'extras_course_enroll_user'), + re_path(r'^extras/update_user_details', extras_update_user_details, name = 'extras_update_user_details'), re_path(r'^extras/get_moodle_login_url', extras_get_moodle_login_url, name = 'extras_get_moodle_login_url'), path('api/val/v0/', include('edxval.urls')), diff --git a/common/djangoapps/student/views/management.py b/common/djangoapps/student/views/management.py index 156726f24865..e7c6d1d6854b 100644 --- a/common/djangoapps/student/views/management.py +++ b/common/djangoapps/student/views/management.py @@ -1354,4 +1354,33 @@ def _get_active_inactive_courses(user): user_active_inactive_courses.update({user_course["course_details"]["course_id"] : "Active"}) else: user_active_inactive_courses.update({user_course["course_details"]["course_id"] : "Dropped"}) - return user_active_inactive_courses \ No newline at end of file + return user_active_inactive_courses + +@csrf_exempt +def extras_update_user_details(request): + data = json.loads(request.body) + log.info(data) + try: + oldEmail = data["other"]["email"] + firstName = data["other"]["firstname"] + lastName = data["other"]["lastname"] + newEmail = data["other"]["newemail"] + old_user = User.objects.get(email = oldEmail) + + except ObjectDoesNotExist: + return HttpResponse("User doesn't exists") + if newEmail and newEmail != oldEmail: + try: + new_user = User.objects.get(email = newEmail) + if new_user: + return HttpResponse("User already exists with new email.") + except ObjectDoesNotExist: + old_user.email = newEmail + + #update firstname lastname if email not passed + if firstName is not None: + old_user.first_name = firstName + if lastName is not None: + old_user.last_name = lastName + old_user.save() + return HttpResponse("Saved") \ No newline at end of file