diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index bca8ff9d76267d651b6ea30d10e56b21521e562e..a2369574d27fbf42f2a19b6eb8a8bda39b6c52a7 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -672,9 +672,12 @@ def change_name_request(request): pnc.rationale = request.POST['rationale'] if len(pnc.new_name) < 2: return HttpResponse(json.dumps({'success': False, 'error': 'Name required'})) - if len(pnc.rationale) < 2: - return HttpResponse(json.dumps({'success': False, 'error': 'Rationale required'})) pnc.save() + + # The following automatically accepts name change requests. Remove this to + # go back to the old system where it gets queued up for admin approval. + accept_name_change_by_id(pnc.id) + return HttpResponse(json.dumps({'success': True})) @@ -709,14 +712,9 @@ def reject_name_change(request): return HttpResponse(json.dumps({'success': True})) -@ensure_csrf_cookie -def accept_name_change(request): - ''' JSON: Name change process. Course staff clicks 'accept' on a given name change ''' - if not request.user.is_staff: - raise Http404 - +def accept_name_change_by_id(id): try: - pnc = PendingNameChange.objects.get(id=int(request.POST['id'])) + pnc = PendingNameChange.objects.get(id=id) except PendingNameChange.DoesNotExist: return HttpResponse(json.dumps({'success': False, 'error': 'Invalid ID'})) @@ -735,3 +733,12 @@ def accept_name_change(request): pnc.delete() return HttpResponse(json.dumps({'success': True})) + + +@ensure_csrf_cookie +def accept_name_change(request): + ''' JSON: Name change process. Course staff clicks 'accept' on a given name change ''' + if not request.user.is_staff: + raise Http404 + + return accept_name_change_by_id(int(request.POST['id'])) diff --git a/lms/templates/dashboard.html b/lms/templates/dashboard.html index 9b59dc2cd9718c69a217672d74afd5afa5297200..3fdcbb5c1c0c864a334daf5bf784430c23bc160d 100644 --- a/lms/templates/dashboard.html +++ b/lms/templates/dashboard.html @@ -46,16 +46,33 @@ function(data) { if (data.success) { $("#change_email_title").html("Please verify your new email"); - $("#change_email_body").html("<p>You'll receive a confirmation in your " + + $("#change_email_form").html("<p>You'll receive a confirmation in your " + "in-box. Please click the link in the " + "email to confirm the email change.</p>"); } else { - $("#change_email_error").html(data.error); + $("#change_email_error").html(data.error).stop().css("display", "block"); } }); return false; }); + $("#change_name_form").submit(function(){ + var new_name = $('#new_name_field').val(); + var rationale = $('#name_rationale_field').val(); + + $.post('${reverse("change_name")}', + {"new_name":new_name, "rationale":rationale}, + function(data) { + if(data.success) { + location.reload(); + // $("#change_name_body").html("<p>Name changed.</p>"); + } else { + $("#change_name_error").html(data.error).stop().css("display", "block"); + } + }); + return false; + }); + })(this) </script> </%block> @@ -75,13 +92,13 @@ <section class="user-info"> <ul> <li> - <span class="title"><div class="icon name-icon"></div>Full Name</span> <span class="data">${ user.profile.name | h }</span> + <span class="title"><div class="icon name-icon"></div>Full Name (<a href="#apply_name_change" rel="leanModal" class="edit-name">edit</a>)</span> <span class="data">${ user.profile.name | h }</span> </li> <li> <span class="title"><div class="icon email-icon"></div>Email (<a href="#change_email" rel="leanModal" class="edit-email">edit</a>)</span> <span class="data">${ user.email | h }</span> </li> <li> - <span class="title"><a href="#" id="pwd_reset_button">Reset Password</a></span> + <span class="title"><a href="#password_reset_complete" rel="leanModal" id="pwd_reset_button">Reset Password</a></span> <form id="password_reset_form" method="post" data-remote="true" action="${reverse('password_reset')}"> <input id="id_email" type="hidden" name="email" maxlength="75" value="${user.email}" /> <!-- <input type="submit" id="pwd_reset_button" value="Reset Password" /> --> @@ -180,15 +197,16 @@ <section id="password_reset_complete" class="modal"> <div class="inner-wrapper"> - <a href="#password_reset_complete" rel="leanModal" id="password_reset_complete_link"></a> + <header> + <h2>Password Reset Email Sent</h2> + <hr/> + </header> <div> - <header> - <h2>Password Reset Email Sent</h2> - <hr/> - </header> - <section> - <p><span>An email has been sent to ${user.email}. Follow the link in the email to change your password.</span></p> - </section> + <form> <!-- Here for styling reasons --> + <section> + <p>An email has been sent to ${user.email}. Follow the link in the email to change your password.</p> + </section> + </form> </div> <div class="close-modal"> <div class="inner"> @@ -198,32 +216,60 @@ </div> </section> -<!-- Haven't Adapted this Yet --> <section id="change_email" class="modal"> <div class="inner-wrapper"> <header> - <h2><span id="change_email_title">Change e-mail</span></h2> + <h2><span id="change_email_title">Change Email</span></h2> <hr/> </header> - <div id="apply_name_change_error"></div> <div id="change_email_body"> <form id="change_email_form"> - <div id="change_email_error"> </div> + <div id="change_email_error" class="modal-form-error"> </div> <fieldset> - <ul> - <li> - <label>Please enter your new email address:</label> - <input id="new_email_field" type="email" value="" /> - </li> - <li> - <label>Please confirm your password:</label> - <input id="new_email_password" value="" type="password" /> - </li> - </ul> + <div class="input-group"> + <label>Please enter your new email address:</label> + <input id="new_email_field" type="email" value="" /> + <label>Please confirm your password:</label> + <input id="new_email_password" value="" type="password" /> + </div> <section> - <p>We will send a confirmation to both ${user.email} and your new e-mail as part of the process.</p> + <p>We will send a confirmation to both ${user.email} and your new email as part of the process.</p> </section> - <input type="submit" id="submit_email_change" /> + <div class="submit"> + <input type="submit" id="submit_email_change" value="Change Email"/> + </div> + </fieldset> + </form> + </div> + <div class="close-modal"> + <div class="inner"> + <p>✕</p> + </div> + </div> + </div> +</section> + +<section id="apply_name_change" class="modal"> + <div class="inner-wrapper"> + <header> + <h2>Change your name</h2> + <hr/> + </header> + <div id="change_name_body"> + <form id="change_name_form"> + <div id="change_name_error" class="modal-form-error"> </div> + <p>To uphold the credibility of edX certificates, all name changes will be logged and recorded.</p> + <br/> + <fieldset> + <div class="input-group"> + <label>Enter your desired full name, as it will appear on the edX certificates: </label> + <input id="new_name_field" value="" type="text" /> + <label>Reason for name change:</label> + <textarea id="name_rationale_field" value=""></textarea> + </div> + <div class="submit"> + <input type="submit" id="submit" value="Change My Name"> + </div> </fieldset> </form> </div> @@ -234,3 +280,4 @@ </div> </div> </section> + diff --git a/lms/templates/email_change_successful.html b/lms/templates/email_change_successful.html index ed3b732d6ec4404b2cf52eb92c1406fca400fb2e..e8c58a282ddd357bc697a3b0b00abe6044dc8740 100644 --- a/lms/templates/email_change_successful.html +++ b/lms/templates/email_change_successful.html @@ -1,3 +1,3 @@ <h1>E-mail change successful!</h1> -<p> You should see your new name in your profile. +<p>You should see your new name in your <a href="/dashboard">dashboard</a>.</p> \ No newline at end of file diff --git a/lms/urls.py b/lms/urls.py index ac61b8524892adc3640a4adb27f7e749e7709824..78ac898216cf18fc4cb56316d7e685f35dd102ca 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -21,7 +21,7 @@ urlpatterns = ('', url(r'^change_email$', 'student.views.change_email_request', name="change_email"), url(r'^email_confirm/(?P<key>[^/]*)$', 'student.views.confirm_email_change'), - url(r'^change_name$', 'student.views.change_name_request'), + url(r'^change_name$', 'student.views.change_name_request', name="change_name"), url(r'^accept_name_change$', 'student.views.accept_name_change'), url(r'^reject_name_change$', 'student.views.reject_name_change'), url(r'^pending_name_changes$', 'student.views.pending_name_changes'),