RT# 77504 - Fixed error display issue, and javascript to prevent error.
authorChristopher Burger <burgerc@freeside.biz>
Tue, 12 Sep 2017 16:08:41 +0000 (12:08 -0400)
committerChristopher Burger <burgerc@freeside.biz>
Wed, 13 Sep 2017 14:11:30 +0000 (10:11 -0400)
httemplate/elements/change_password.html
httemplate/elements/validate_password.html
httemplate/misc/process/change-password.html
httemplate/view/svc_acct.cgi

index 463384f..7d95e19 100644 (file)
@@ -13,7 +13,7 @@
 % }
 <DIV ID="<%$pre%>form" CLASS="passwordbox">
 % if (!$opt{'noformtag'}) {
-  <FORM METHOD="POST" ACTION="<%$fsurl%>misc/process/change-password.html">
+  <FORM METHOD="POST" ACTION="<%$fsurl%>misc/process/change-password.html" onsubmit="return checkPasswordValidation()">
 % }
 
     <% $change_id_input %>
@@ -33,9 +33,6 @@
          'contactnum' => $opt{'contact_num'},
          'submitid'   => $change_button_id,
     &>
-% if ( $error ) {
-    <BR><SPAN STYLE="color: #ff0000"><% $error |h %></SPAN>
-% }
 
 % if (!$opt{'noformtag'}) {
   </FORM>
@@ -58,6 +55,16 @@ function <%$pre%>toggle(toggle, clear) {
     toggle ? 'none' : 'inline';
 % }
 }
+
+function checkPasswordValidation()  {
+  var validationResult = document.getElementById('<%$pre%>password_result').innerHTML;
+  if (validationResult.match(/Password valid!/)) {
+    return true;
+  }
+  else {
+    return false;
+  }
+}
 </SCRIPT>
 <%init>
 my %opt = @_;
index 1b0688e..8c8cf42 100644 (file)
@@ -23,6 +23,15 @@ should be the input id plus '_result'.
 <SCRIPT>
 function add_password_validation (fieldid, submitid) {
   var inputfield = document.getElementById(fieldid);
+  inputfield.onkeydown = function(e) {
+    var key;
+    if (window.event) { key = window.event.keyCode; }
+    else { key = e.which; }
+    if (key == '13') {
+      var check = checkPasswordValidation();
+      return check;
+    }
+  }
   inputfield.onkeyup = function () {
     var fieldid = this.id+'_result';
     var resultfield = document.getElementById(fieldid);
index be83786..a3e0601 100644 (file)
@@ -7,6 +7,7 @@
 %              $cgi->param('contactnum', $contactnum);
 %              $cgi->param("changepw${contactnum}_error", $error);
 %      }
+%    $cgi->param('error', $error);
 % } else {
 %      if ($svcnum) { $cgi->query_string($svcnum); }
 %      elsif ($contactnum) { $cgi->query_string($contactnum); }
@@ -52,7 +53,7 @@ if ($svcnum) {
            ! $part_svc->restrict_edit_password )
          );
 
-       my $error = $svc_acct->is_password_allowed($newpass)
+       $error = $svc_acct->is_password_allowed($newpass)
                ||  $svc_acct->set_password($newpass)
                ||  $svc_acct->replace;
 
@@ -63,7 +64,7 @@ elsif ($contactnum) {
        my $contact = qsearchs('contact', { 'contactnum' => $contactnum } )
       or return { 'error' => "Contact not found" . $contactnum };
 
-       my $error = $contact->is_password_allowed($newpass)
+       $error = $contact->is_password_allowed($newpass)
                ||  $contact->change_password($newpass);
 
        # annoyingly specific to view/svc_acct.cgi, for now...
index 7474779..026effb 100755 (executable)
@@ -20,8 +20,9 @@
             "javascript:areyousure(\'${p}misc/cancel-unaudited.cgi?$svcnum\')",
   ) &>
 
-% } 
+% }
 
+<& /elements/error.html &>
 
 <& elements/svc_radius_usage.html,
               'svc'      => $svc_acct,