[freeside-commits] branch FREESIDE_4_BRANCH updated. 705c00ea8175958ae4cf6a9f0fb2cf9a4aae564f

Christopher Burger burgerc at freeside.biz
Sun Sep 9 14:59:25 PDT 2018


The branch, FREESIDE_4_BRANCH has been updated
       via  705c00ea8175958ae4cf6a9f0fb2cf9a4aae564f (commit)
       via  1f1cc2da8ffcd4d27e3ae8a79268d688e0c5c519 (commit)
       via  150aefab60e1b4c4b66533f644cf67893e4d0659 (commit)
       via  7bc6903bac6439f2bcfeb7c842779904c4b59e68 (commit)
       via  d8496a347433b812a17c750698510ee0eec7e4cf (commit)
       via  95a519db7d3b8b09206831b41e4a020cef23cee1 (commit)
       via  93ef20155af222e8b3f0737715975e0fc86741b0 (commit)
      from  fe0e5a810960200b5352128139e6b040ea08eada (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 705c00ea8175958ae4cf6a9f0fb2cf9a4aae564f
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Sun Sep 9 17:34:35 2018 -0400

    RT# 75817 - fixed redirect error

diff --git a/httemplate/edit/process/cust_main-contacts.html b/httemplate/edit/process/cust_main-contacts.html
index 2a7185b5c..6e94a290f 100644
--- a/httemplate/edit/process/cust_main-contacts.html
+++ b/httemplate/edit/process/cust_main-contacts.html
@@ -1,6 +1,6 @@
 <% include('elements/process.html',
      'table'          => 'cust_main',
-     'error_redirect' => popurl(3). 'edit/cust_main-contacts.html?',
+     'error_redirect' => popurl(3). 'edit/cust_main-contacts.html',
      'agent_virt'     => 1,
      'skip_process'   => 1, #we don't want to make any changes to cust_main
      'precheck_callback' => $precheck_callback,
diff --git a/httemplate/edit/process/elements/process.html b/httemplate/edit/process/elements/process.html
index a3ea7ee59..d2b037053 100644
--- a/httemplate/edit/process/elements/process.html
+++ b/httemplate/edit/process/elements/process.html
@@ -127,7 +127,7 @@ Example:
 %          " attempting to set redirect$session to ". $cgi->query_string."\n";
 %    }
 %
-<% $cgi->redirect("$error_redirect"."redirect=$session") %>
+<% $cgi->redirect("$error_redirect?redirect=$session") %>
 %
 %  } else {
 %

commit 1f1cc2da8ffcd4d27e3ae8a79268d688e0c5c519
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Sun Sep 9 16:12:23 2018 -0400

    RT# 75817 - cleaned up password validation error message

diff --git a/httemplate/elements/contact.html b/httemplate/elements/contact.html
index 5302c4a3f..31b4e49cb 100644
--- a/httemplate/elements/contact.html
+++ b/httemplate/elements/contact.html
@@ -102,7 +102,7 @@
           <BR>
           <FONT SIZE="-1"><% $label{$field} %></FONT>
 %       if ( $field eq 'password' ) {
-          <div id="changepw<%$id%>_<%$field%>_result"></div>
+          <DIV ID="changepw<%$id%>_<%$field%>_result" STYLE="font-size: smaller"></DIV>
 %       }
         </TD>
 %     }

commit 150aefab60e1b4c4b66533f644cf67893e4d0659
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Fri Sep 7 10:55:19 2018 -0400

    RT# 75817 - fixed saving of password for new contacts, and password validation on dynamicly created rows
    
    Conflicts:
            httemplate/edit/elements/edit.html

diff --git a/FS/FS/contact.pm b/FS/FS/contact.pm
index 02c6d0659..fc06ca82b 100644
--- a/FS/FS/contact.pm
+++ b/FS/FS/contact.pm
@@ -199,8 +199,6 @@ sub insert {
 
   }
 
-  $error ||= $self->insert_password_history;
-
   if ( $error ) {
     $dbh->rollback if $oldAutoCommit;
     return $error;
@@ -302,6 +300,15 @@ sub insert {
     }
   }
 
+  if ( $self->get('password') ) {
+    my $error = $self->is_password_allowed($self->get('password'))
+          ||  $self->change_password($self->get('password'));
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error;
+    }
+  }
+
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
 
   '';
@@ -817,7 +824,7 @@ sub authenticate_password {
 
     $hash eq $check_hash;
 
-  } else { 
+  } else {
 
     return 0 if $self->_password eq '';
 
diff --git a/httemplate/edit/cust_main-contacts.html b/httemplate/edit/cust_main-contacts.html
index 7c5a78209..abef7505d 100644
--- a/httemplate/edit/cust_main-contacts.html
+++ b/httemplate/edit/cust_main-contacts.html
@@ -60,6 +60,13 @@ this one isn't being maintained well.  :/
 my $curuser = $FS::CurrentUser::CurrentUser;
 my $conf = new FS::Conf;
 
+if ( $cgi->param('redirect') ) {
+  my $session = $cgi->param('redirect');
+  my $pref = $curuser->option("redirect$session");
+  die "unknown redirect session $session\n" unless length($pref);
+  $cgi = new CGI($pref);
+}
+
 my $custnum;
 if ( $cgi->param('error') ) {
   $custnum = scalar($cgi->param('custnum'));
diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html
index 9f3738830..0062b7e2d 100644
--- a/httemplate/edit/elements/edit.html
+++ b/httemplate/edit/elements/edit.html
@@ -669,7 +669,7 @@ Example:
           var newrow =  <% include(@layer_opt, html_only=>1) |js_string %>;
 
 %         #until the rest have html/js_only
-%         if ( $type eq 'selectlayers' || $type =~ /^select-cgp_rule_/ ) {
+%         if ( ($type eq 'selectlayers') || ($type =~ /^select-cgp_rule_/) || ($type eq 'contact') ) {
             var newfunc = <% include(@layer_opt, js_only=>1) |js_string %>;
 %         } else {
             var newfunc = '';
diff --git a/httemplate/edit/process/elements/process.html b/httemplate/edit/process/elements/process.html
index d2b037053..a3ea7ee59 100644
--- a/httemplate/edit/process/elements/process.html
+++ b/httemplate/edit/process/elements/process.html
@@ -127,7 +127,7 @@ Example:
 %          " attempting to set redirect$session to ". $cgi->query_string."\n";
 %    }
 %
-<% $cgi->redirect("$error_redirect?redirect=$session") %>
+<% $cgi->redirect("$error_redirect"."redirect=$session") %>
 %
 %  } else {
 %
diff --git a/httemplate/elements/contact.html b/httemplate/elements/contact.html
index 18e552507..5302c4a3f 100644
--- a/httemplate/elements/contact.html
+++ b/httemplate/elements/contact.html
@@ -1,4 +1,6 @@
-% unless ( $opt{'js_only'} ) {
+% if ( $opt{'js_only'} ) {
+<% $js %>
+% } else {
 
   <INPUT TYPE="hidden" NAME="<%$name%>" ID="<%$id%>" VALUE="<% $curr_value %>">
 
@@ -74,23 +76,8 @@
                    VALUE = ""
                    placeholder = "<% $value |h %>"
             >
-%           my $contactnum = $curr_value ? $curr_value : '0';
-
             <SCRIPT>
-              add_password_validation('<% "changepw".$id."_password" %>', 'submit', '', '<% $contactnum %>');
-            </SCRIPT>
-
-            <SCRIPT TYPE="text/javascript">
-                    var selfService = document.getElementById("<%$id%>_selfservice_access").value;
-
-                    if (selfService !== "Y") { document.getElementById("changepw<%$id%>_password").disabled = 'true'; }
-                    document.getElementById("<%$id%>_selfservice_access").onchange = function() {
-                      if (this.value == "P" || this.value == "E" || this.value =="Y") {
-                        document.getElementById("changepw<%$id%>_password").disabled = '';
-                      }
-                      else { document.getElementById("changepw<%$id%>_password").disabled = 'true'; }
-                      return false;
-                    }
+              <% $js %>
             </SCRIPT>
 %         } elsif ( $field eq 'invoice_dest' ) {
 %           my $curr_value = $cgi->param($name . '_' . $field);
@@ -135,6 +122,7 @@ my $name = $opt{'element_name'} || $opt{'field'} || 'contactnum';
 my $id = $opt{'id'} || 'contactnum';
 
 my $curr_value = $opt{'curr_value'} || $opt{'value'};
+my $contactnum = $curr_value ? $curr_value : '0';
 
 my $onchange = '';
 if ( $opt{'onchange'} ) {
@@ -201,4 +189,19 @@ $label{'comment'} = 'Comment';
 
 my @fields = $opt{'name_only'} ? qw( first last ) : keys %label;
 
+my $js = qq(
+    add_password_validation('changepw$id\_password', 'submit', '', '$contactnum');
+
+    var selfService = document.getElementById("$id\_selfservice_access").value;
+
+    if (selfService !== "Y") { document.getElementById("changepw$id\_password").disabled = 'true'; }
+    document.getElementById("$id\_selfservice_access").onchange = function() {
+      if (this.value == "P" || this.value == "E" || this.value =="Y") {
+        document.getElementById("changepw$id\_password").disabled = '';
+      }
+      else { document.getElementById("changepw$id\_password").disabled = 'true'; }
+      return false;
+    }
+);
+
 </%init>

commit 7bc6903bac6439f2bcfeb7c842779904c4b59e68
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 d8496a347433b812a17c750698510ee0eec7e4cf
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 1b4c16e88..18e552507 100644
--- a/httemplate/elements/contact.html
+++ b/httemplate/elements/contact.html
@@ -75,12 +75,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 94488670d..2209d30f3 100644
--- a/httemplate/view/cust_main/contacts_new.html
+++ b/httemplate/view/cust_main/contacts_new.html
@@ -21,6 +21,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">);
@@ -37,6 +38,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>
@@ -61,6 +72,7 @@
 %      } else {
 %        $bgcolor = $bgcolor1;
 %      }
+%     $count++;
 %   }
 </TABLE>
 %}
@@ -78,6 +90,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>

commit 95a519db7d3b8b09206831b41e4a020cef23cee1
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Wed Aug 29 14:24:47 2018 -0400

    RT# 75817 - removed change password link as it is not needed anymore

diff --git a/httemplate/elements/contact.html b/httemplate/elements/contact.html
index 99ac0133d..1b4c16e88 100644
--- a/httemplate/elements/contact.html
+++ b/httemplate/elements/contact.html
@@ -62,7 +62,6 @@
                 <OPTION VALUE="<% $value eq 'Y' ? 'Y' : 'E' %>" <% $value eq 'Y' ? 'SELECTED' : '' %>>Enabled
 %               if ( $value eq 'Y' && $self_base_url ) {
                   <OPTION VALUE="R">Re-email
-                  <OPTION VALUE="P"><% $pwd_change_label %>
 %               }
 %             }
             </SELECT>
@@ -204,7 +203,4 @@ $label{'comment'} = 'Comment';
 
 my @fields = $opt{'name_only'} ? qw( first last ) : keys %label;
 
-my $pwd_change_label = 'Change Password';
-$pwd_change_label = 'Setup Password' unless $contact->_password;
-
 </%init>

commit 93ef20155af222e8b3f0737715975e0fc86741b0
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Wed Aug 29 14:09:58 2018 -0400

    RT# 75817 - updated UI to be more intuitive

diff --git a/httemplate/edit/cust_main-contacts.html b/httemplate/edit/cust_main-contacts.html
index 76929a7c9..3783cb9e9 100644
--- a/httemplate/edit/cust_main-contacts.html
+++ b/httemplate/edit/cust_main-contacts.html
@@ -4,6 +4,19 @@ Hmm, this is now entirely redundant with edit/cust_main/contacts_new.html, and
 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;
+  }
+  else {
+    return false;
+  }
+}
+</SCRIPT>
+
 <& elements/edit.html,
      'name_singular'    => 'customer contacts', #yes, we're editing all of them
      'table'            => 'cust_main',
diff --git a/httemplate/elements/contact.html b/httemplate/elements/contact.html
index faee7ead4..99ac0133d 100644
--- a/httemplate/elements/contact.html
+++ b/httemplate/elements/contact.html
@@ -40,6 +40,8 @@
 %         }
 %       } elsif ( $field eq 'emailaddress' ) {
 %         $value = join(', ', map $_->emailaddress, $contact->contact_email);
+%       } elsif ( $field eq 'password' ) {
+%          $value = $contact->get('_password') ? '********' : '';
 %       } elsif ( $field eq 'selfservice_access'
 %              or $field eq 'comment'
 %              or $field eq 'invoice_dest' ) {
@@ -55,7 +57,7 @@
                     ID   = "<%$id%>_<%$field%>"
                     STYLE = "width: 140px"
             >
-              <OPTION VALUE="">Disabled
+              <OPTION VALUE="" <% !$value ? 'SELECTED' : '' %>>Disabled
 %             if ( $value || $self_base_url ) {
                 <OPTION VALUE="<% $value eq 'Y' ? 'Y' : 'E' %>" <% $value eq 'Y' ? 'SELECTED' : '' %>>Enabled
 %               if ( $value eq 'Y' && $self_base_url ) {
@@ -64,18 +66,33 @@
 %               }
 %             }
             </SELECT>
-                  <& /elements/change_password.html,
-                   'contact_num'         => $curr_value,
-                   'custnum'             => $opt{'custnum'},
-                   'curr_value'          => '',
-                   'no_label_display'    => '1',
-                   'noformtag'           => '1',
-                   'pre_pwd_field_label' => $id.'_',
-                  &>
+% #password form
+%         } elsif ( $field eq 'password') {
+            <INPUT TYPE  = "text"
+                   NAME  = "<%$name%>_<%$field%>"
+                   ID    = "changepw<%$id%>_<%$field%>"
+                   SIZE  = "<% $size{$field} || 14 %>"
+                   VALUE = ""
+                   placeholder = "<% $value |h %>"
+            >
+%           my $contactnum = $curr_value ? $curr_value : '0';
+            <& '/elements/validate_password.html',
+             'fieldid'    => "changepw".$id."_password",
+             'svcnum'     => '',
+             'contactnum' => $contactnum,
+             'submitid'   => "submit",
+           &>
+
             <SCRIPT TYPE="text/javascript">
-                    document.getElementById("<%$id%>_<%$field%>").onchange = function() {
-                      if (this.value == "P" || this.value == "E") { changepw<%$id%>_toggle(true); }
-                      return false
+                    var selfService = document.getElementById("<%$id%>_selfservice_access").value;
+
+                    if (selfService !== "Y") { document.getElementById("changepw<%$id%>_password").disabled = 'true'; }
+                    document.getElementById("<%$id%>_selfservice_access").onchange = function() {
+                      if (this.value == "P" || this.value == "E" || this.value =="Y") {
+                        document.getElementById("changepw<%$id%>_password").disabled = '';
+                      }
+                      else { document.getElementById("changepw<%$id%>_password").disabled = 'true'; }
+                      return false;
                     }
             </SCRIPT>
 %         } elsif ( $field eq 'invoice_dest' ) {
@@ -100,6 +117,9 @@
 %         }
           <BR>
           <FONT SIZE="-1"><% $label{$field} %></FONT>
+%       if ( $field eq 'password' ) {
+          <div id="changepw<%$id%>_<%$field%>_result"></div>
+%       }
         </TD>
 %     }
     </TR>
@@ -169,6 +189,7 @@ tie my %label, 'Tie::IxHash',
 unless ($opt{'for_prospect'}) {
   $label{'invoice_dest'} = 'Send invoices';
   $label{'selfservice_access'} = 'Self-service';
+  $label{'password'} = 'Password';
 }
 
 my $first = 0;
diff --git a/httemplate/elements/validate_password.html b/httemplate/elements/validate_password.html
index 4057f5d3f..73c0db281 100644
--- a/httemplate/elements/validate_password.html
+++ b/httemplate/elements/validate_password.html
@@ -29,7 +29,7 @@ function add_password_validation (fieldid, submitid) {
     // 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();
+      var check = checkPasswordValidation(fieldid);
       return check;
     }
   }
@@ -61,6 +61,7 @@ function add_password_validation (fieldid, submitid) {
       );
     } else {
       resultfield.innerHTML = '';
+      if (submitid){ document.getElementById(submitid).disabled = false; }
     }
   };
 }
diff --git a/httemplate/misc/xmlhttp-validate_password.html b/httemplate/misc/xmlhttp-validate_password.html
index 4d9716bb9..c53abe883 100644
--- a/httemplate/misc/xmlhttp-validate_password.html
+++ b/httemplate/misc/xmlhttp-validate_password.html
@@ -28,14 +28,14 @@ my $validate_password = sub {
   $result{'syserror'} = 'Invoked without password' unless $password;
   return \%result if $result{'syserror'};
 
-  if ($arg{'contactnum'}) {
+  if ($arg{'contactnum'} =~ /^\d+$/) {
     my $contactnum = $arg{'contactnum'};
     $result{'syserror'} = 'Invalid contactnum' unless $contactnum =~ /^\d*$/;
     return \%result if $result{'syserror'};
 
     my $contact = $contactnum 
       ? qsearchs('contact',{'contactnum' => $contactnum})
-      : '';
+      : (new FS::contact {});
 
     $result{'error'} = $contact->is_password_allowed($password);
   }

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

Summary of changes:
 FS/FS/contact.pm                                   | 13 ++++--
 httemplate/edit/cust_main-contacts.html            | 22 +++++++++
 httemplate/edit/elements/edit.html                 |  2 +-
 httemplate/edit/process/cust_main-contacts.html    |  2 +-
 httemplate/elements/change_password.html           | 15 +++---
 httemplate/elements/contact.html                   | 54 ++++++++++++++--------
 httemplate/elements/validate_password.html         | 54 ++--------------------
 ...ate_password.html => validate_password_js.html} | 22 ++++-----
 httemplate/misc/process/change-password.html       |  6 ++-
 httemplate/misc/xmlhttp-validate_password.html     |  4 +-
 httemplate/view/cust_main/contacts_new.html        | 14 +++++-
 11 files changed, 108 insertions(+), 100 deletions(-)
 copy httemplate/elements/{validate_password.html => validate_password_js.html} (83%)




More information about the freeside-commits mailing list