Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update user details API #51

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cms/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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')),
Expand Down
31 changes: 30 additions & 1 deletion common/djangoapps/student/views/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -1415,4 +1415,33 @@ def extras_get_mettl_report(request):
if response["status"] != "SUCCESS" :
return HttpResponse("Please Contact Support")

return redirect(response["candidate"]["testStatus"]["htmlReport"])
return redirect(response["candidate"]["testStatus"]["htmlReport"])

@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")
Loading