[freeside-commits] branch master updated. 0c9c9e95f2f32e7d55dd53f2903c21eb8ce7af6b

Christopher Burger burgerc at freeside.biz
Tue Sep 4 05:34:06 PDT 2018


The branch, master has been updated
       via  0c9c9e95f2f32e7d55dd53f2903c21eb8ce7af6b (commit)
       via  8ca45ec1f1ab960ee1e262ee764f05d214728d05 (commit)
      from  5e2b0a5efb81642e86f7704a528767c2ea2961ca (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 0c9c9e95f2f32e7d55dd53f2903c21eb8ce7af6b
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Tue Sep 4 08:32:21 2018 -0400

    RT# 75817 - added new file to hold javascript for password validation

diff --git a/httemplate/elements/validate_password_js.html b/httemplate/elements/validate_password_js.html
new file mode 100644
index 000000000..64db0a97b
--- /dev/null
+++ b/httemplate/elements/validate_password_js.html
@@ -0,0 +1,71 @@
+<%doc>
+
+JavaScript to perform password validation
+
+  <& '/elements/validate_password_js.html', 
+     contactnum  => $contactnum,
+     svcnum      => $svcnum
+  &>
+
+The ID of the input field can be anything;  the ID of the DIV in which to display results
+should be the input id plus '_result'.
+
+</%doc>
+
+<& '/elements/xmlhttp.html',
+    'url'  => $p.'misc/xmlhttp-validate_password.html',
+    'subs' => [ 'validate_password' ],
+    'method' => 'POST', # important not to put passwords in url
+&>
+<SCRIPT>
+function add_password_validation (fieldid, submitid, svcnum, contactnum) {
+  var inputfield = document.getElementById(fieldid);
+  inputfield.onkeydown = function(e) {
+    var key;
+    if (window.event) { key = window.event.keyCode; }
+    else { key = e.which; } // for ff browsers
+    // some browsers allow the enter key to submit a form even if the submit button is disabled
+    // below prevents enter key from submiting form if password has not been validated.
+    if (key == '13') {
+      var check = checkPasswordValidation(fieldid);
+      return check;
+    }
+  }
+  inputfield.onkeyup = function () {
+    var fieldid = this.id+'_result';
+    var resultfield = document.getElementById(fieldid);
+    if (this.value) {
+      resultfield.innerHTML = '<SPAN STYLE="color: blue;">Validating password...</SPAN>';
+      validate_password('fieldid',fieldid,'svcnum','<% $opt{'svcnum'} %>','contactnum', contactnum,'password',this.value,
+        function (result) {
+          result = JSON.parse(result);
+          var resultfield = document.getElementById(result.fieldid);
+          if (resultfield) {
+            var errorimg = '<IMG SRC="<% $p %>images/error.png" style="width: 1em; display: inline-block; padding-right: .5em">';
+            var validimg = '<IMG SRC="<% $p %>images/tick.png" style="width: 1em; display: inline-block; padding-right: .5em">';
+            if (result.valid) {
+              resultfield.innerHTML = validimg+'<SPAN STYLE="color: green;">Password valid!</SPAN>';
+              if (submitid){ document.getElementById(submitid).disabled = false; }
+            } else if (result.error) {
+              resultfield.innerHTML = errorimg+'<SPAN STYLE="color: red;">'+result.error+'</SPAN>';
+              if (submitid){ document.getElementById(submitid).disabled = true; }
+            } else {
+              result.syserror = result.syserror || 'Server error';
+              resultfield.innerHTML = errorimg+'<SPAN STYLE="color: red;">'+result.syserror+'</SPAN>';
+              if (submitid){ document.getElementById(submitid).disabled = true; }
+            }
+          }
+        }
+      );
+    } else {
+      resultfield.innerHTML = '';
+      if (submitid){ document.getElementById(submitid).disabled = false; }
+    }
+  };
+}
+
+</SCRIPT>
+
+<%init>
+my %opt = @_;
+</%init>
\ No newline at end of file

commit 8ca45ec1f1ab960ee1e262ee764f05d214728d05
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Tue Sep 4 08:30:35 2018 -0400

    RT# 75817 - Added password change link to cust main page

diff --git a/httemplate/edit/cust_main-contacts.html b/httemplate/edit/cust_main-contacts.html
index 3783cb9e9..7c5a78209 100644
--- a/httemplate/edit/cust_main-contacts.html
+++ b/httemplate/edit/cust_main-contacts.html
@@ -5,18 +5,20 @@ this one isn't being maintained well.  :/
 
 </%doc>
 
-  <SCRIPT>
-function checkPasswordValidation(fieldid)  {
-  var validationResult = document.getElementById(fieldid+'_result').innerHTML;
-  if (validationResult.match(/Password valid!/)) {
-    return true;
+<SCRIPT>
+  function checkPasswordValidation(fieldid)  {
+    var validationResult = document.getElementById(fieldid+'_result').innerHTML;
+    if (validationResult.match(/Password valid!/)) {
+      return true;
+    }
+    else {
+      return false;
+    }
   }
-  else {
-    return false;
-  }
-}
 </SCRIPT>
 
+<& '/elements/validate_password_js.html', &>
+
 <& elements/edit.html,
      'name_singular'    => 'customer contacts', #yes, we're editing all of them
      'table'            => 'cust_main',
diff --git a/httemplate/elements/change_password.html b/httemplate/elements/change_password.html
index 7d95e19dc..65b7d8502 100644
--- a/httemplate/elements/change_password.html
+++ b/httemplate/elements/change_password.html
@@ -11,9 +11,9 @@
 % if (!$opt{'no_label_display'}) {
 <A ID="<%$pre%>link" HREF="javascript:void(0)" onclick="<%$pre%>toggle(true)">(<% emt( $change_title ) %>)</A>
 % }
-<DIV ID="<%$pre%>form" CLASS="passwordbox">
+<DIV ID="<%$pre%>div" CLASS="passwordbox">
 % if (!$opt{'noformtag'}) {
-  <FORM METHOD="POST" ACTION="<%$fsurl%>misc/process/change-password.html" onsubmit="return checkPasswordValidation()">
+  <FORM ID="<%$pre%>form" METHOD="POST" ACTION="<%$fsurl%>misc/process/change-password.html" onsubmit="return <%$pre%>checkPasswordValidation()">
 % }
 
     <% $change_id_input %>
@@ -44,11 +44,8 @@ function <%$pre%>toggle(toggle, clear) {
   if (clear) {
     document.getElementById('<%$pre%>password').value = '';
     document.getElementById('<%$pre%>password_result').innerHTML = '';
-% if ($opt{'contact_num'}) {
-    document.getElementById('<% $opt{'pre_pwd_field_label'} %>selfservice_access').value = 'Y';
-% }
 }
-  document.getElementById('<%$pre%>form').style.display =
+  document.getElementById('<%$pre%>div').style.display =
     toggle ? 'inline-block' : 'none';
 % if (!$opt{'no_label_display'}) {
   document.getElementById('<%$pre%>link').style.display =
@@ -56,7 +53,7 @@ function <%$pre%>toggle(toggle, clear) {
 % }
 }
 
-function checkPasswordValidation()  {
+function <%$pre%>checkPasswordValidation(resultId)  {
   var validationResult = document.getElementById('<%$pre%>password_result').innerHTML;
   if (validationResult.match(/Password valid!/)) {
     return true;
@@ -83,8 +80,8 @@ if ($opt{'svc_acct'}) {
 }
 elsif ($opt{'contact_num'}) {
   $change_id_input = '
-    <INPUT TYPE="hidden" NAME="'.$opt{'pre_pwd_field_label'}.'contactnum" VALUE="' . $opt{'contact_num'} . '">
-    <INPUT TYPE="hidden" NAME="'.$opt{'pre_pwd_field_label'}.'custnum" VALUE="' . $opt{'custnum'} . '">
+    <INPUT TYPE="hidden" NAME="contactnum" VALUE="' . $opt{'contact_num'} . '">
+    <INPUT TYPE="hidden" NAME="custnum" VALUE="' . $opt{'custnum'} . '">
   ';
   $pre .= $opt{'pre_pwd_field_label'};
 }
diff --git a/httemplate/elements/contact.html b/httemplate/elements/contact.html
index 7b6c853d4..5588890c8 100644
--- a/httemplate/elements/contact.html
+++ b/httemplate/elements/contact.html
@@ -76,12 +76,10 @@
                    placeholder = "<% $value |h %>"
             >
 %           my $contactnum = $curr_value ? $curr_value : '0';
-            <& '/elements/validate_password.html',
-             'fieldid'    => "changepw".$id."_password",
-             'svcnum'     => '',
-             'contactnum' => $contactnum,
-             'submitid'   => "submit",
-           &>
+
+            <SCRIPT>
+              add_password_validation('<% "changepw".$id."_password" %>', 'submit', '', '<% $contactnum %>');
+            </SCRIPT>
 
             <SCRIPT TYPE="text/javascript">
                     var selfService = document.getElementById("<%$id%>_selfservice_access").value;
diff --git a/httemplate/elements/validate_password.html b/httemplate/elements/validate_password.html
index 73c0db281..6aada2fee 100644
--- a/httemplate/elements/validate_password.html
+++ b/httemplate/elements/validate_password.html
@@ -14,59 +14,10 @@ should be the input id plus '_result'.
 
 </%doc>
 
-<& '/elements/xmlhttp.html',
-    'url'  => $p.'misc/xmlhttp-validate_password.html',
-    'subs' => [ 'validate_password' ],
-    'method' => 'POST', # important not to put passwords in url
-&>
-<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; } // for ff browsers
-    // some browsers allow the enter key to submit a form even if the submit button is disabled
-    // below prevents enter key from submiting form if password has not been validated.
-    if (key == '13') {
-      var check = checkPasswordValidation(fieldid);
-      return check;
-    }
-  }
-  inputfield.onkeyup = function () {
-    var fieldid = this.id+'_result';
-    var resultfield = document.getElementById(fieldid);
-    if (this.value) {
-      resultfield.innerHTML = '<SPAN STYLE="color: blue;">Validating password...</SPAN>';
-      validate_password('fieldid',fieldid,'svcnum','<% $opt{'svcnum'} %>','contactnum','<% $opt{'contactnum'} %>','password',this.value,
-        function (result) {
-          result = JSON.parse(result);
-          var resultfield = document.getElementById(result.fieldid);
-          if (resultfield) {
-            var errorimg = '<IMG SRC="<% $p %>images/error.png" style="width: 1em; display: inline-block; padding-right: .5em">';
-            var validimg = '<IMG SRC="<% $p %>images/tick.png" style="width: 1em; display: inline-block; padding-right: .5em">';
-            if (result.valid) {
-              resultfield.innerHTML = validimg+'<SPAN STYLE="color: green;">Password valid!</SPAN>';
-              if (submitid){ document.getElementById(submitid).disabled = false; }
-            } else if (result.error) {
-              resultfield.innerHTML = errorimg+'<SPAN STYLE="color: red;">'+result.error+'</SPAN>';
-              if (submitid){ document.getElementById(submitid).disabled = true; }
-            } else {
-              result.syserror = result.syserror || 'Server error';
-              resultfield.innerHTML = errorimg+'<SPAN STYLE="color: red;">'+result.syserror+'</SPAN>';
-              if (submitid){ document.getElementById(submitid).disabled = true; }
-            }
-          }
-        }
-      );
-    } else {
-      resultfield.innerHTML = '';
-      if (submitid){ document.getElementById(submitid).disabled = false; }
-    }
-  };
-}
+<& '/elements/validate_password_js.html', %opt &>
 
-add_password_validation('<% $opt{'fieldid'} %>', '<% $opt{'submitid'} %>');
+<SCRIPT>
+  add_password_validation('<% $opt{'fieldid'} %>', '<% $opt{'submitid'} %>', '<% $opt{'svcnum'} %>', '<% $opt{'contactnum'} %>');
 </SCRIPT>
 
 <%init>
diff --git a/httemplate/misc/process/change-password.html b/httemplate/misc/process/change-password.html
index a3e060168..37ad6d915 100644
--- a/httemplate/misc/process/change-password.html
+++ b/httemplate/misc/process/change-password.html
@@ -18,7 +18,7 @@
 	 <% $cgi->redirect($fsurl.'view/svc_acct.cgi?'.$cgi->query_string) %>
 %   }
 %   elsif ($contactnum) { 
-	 <% $cgi->redirect($fsurl.'edit/cust_main-contacts.html?'.$cgi->param('custnum')) %>
+	 <% $cgi->redirect($fsurl.'view/cust_main.cgi?'.$cgi->param('custnum')) %>
 %   }
 % }
 
@@ -34,6 +34,10 @@ my $curuser = $FS::CurrentUser::CurrentUser;
 $cgi->param('svcnum') =~ /^(\d+)$/ or die "illegal svcnum" if $cgi->param('svcnum');
 my $svcnum = $1;
 
+foreach my $prefix (grep /^(.*)(password)$/, $cgi->param) {
+     $cgi->param('password' => $cgi->param($prefix));
+}
+
 $cgi->param('contactnum') =~ /^(\d+)$/ or die "illegal contactnum" if $cgi->param('contactnum');
 my $contactnum = $1;
 
diff --git a/httemplate/view/cust_main/contacts_new.html b/httemplate/view/cust_main/contacts_new.html
index fe412cc00..9252b2197 100644
--- a/httemplate/view/cust_main/contacts_new.html
+++ b/httemplate/view/cust_main/contacts_new.html
@@ -22,6 +22,7 @@
 %   my $bgcolor1 = '#ffffff';
 %   my $bgcolor2 = '#eeeeee';
 %   my $bgcolor = $bgcolor2;
+%   my $count = 0;
 %   foreach my $cust_contact ( @cust_contacts ) {
 %     my $contact = $cust_contact->contact;
 %     my $td = qq(<TD CLASS="grid" BGCOLOR="$bgcolor">);
@@ -39,6 +40,16 @@
             Enabled
 %#            <FONT SIZE="-1"><A HREF="XXX">disable</A>
 %#                            <A HREF="XXX">re-email</A></FONT>
+            <FONT SIZE="-1">
+              <& /elements/change_password.html,
+                'contact_num'      => $cust_contact->contactnum,
+                'custnum'          => $cust_contact->custnum,
+                'no_label_display' => '',
+                'label'            => 'change password',
+                'curr_value'       => '',
+                'pre_pwd_field_label' => 'contact'.$count.'_',
+              &>
+            </FONT>
 %         } else {
             Disabled
 %#            <FONT SIZE="-1"><A HREF="XXX">enable</A></FONT>
@@ -63,6 +74,7 @@
 %      } else {
 %        $bgcolor = $bgcolor1;
 %      }
+%     $count++;
 %   }
 </TABLE>
 %}
@@ -80,6 +92,6 @@ my @cust_contacts = $cust_main->cust_contact;
 
 # residential customers have a default "invisible" contact, but if they
 # somehow get more than one contact, show them
-my $display = scalar(@cust_contacts) > 1;
+my $display = scalar(@cust_contacts) > 0;
 
 </%init>

-----------------------------------------------------------------------

Summary of changes:
 httemplate/edit/cust_main-contacts.html            | 20 ++++----
 httemplate/elements/change_password.html           | 15 +++---
 httemplate/elements/contact.html                   | 10 ++--
 httemplate/elements/validate_password.html         | 55 ++--------------------
 ...ate_password.html => validate_password_js.html} | 19 +++-----
 httemplate/misc/process/change-password.html       |  6 ++-
 httemplate/view/cust_main/contacts_new.html        | 14 +++++-
 7 files changed, 49 insertions(+), 90 deletions(-)
 copy httemplate/elements/{validate_password.html => validate_password_js.html} (85%)




More information about the freeside-commits mailing list