[freeside-commits] branch FREESIDE_3_BRANCH updated. 6016bc83d369186275044bd8539f66a3cb03c4cb

Christopher Burger burgerc at 420.am
Thu Jun 22 13:32:00 PDT 2017


The branch, FREESIDE_3_BRANCH has been updated
       via  6016bc83d369186275044bd8539f66a3cb03c4cb (commit)
      from  cebbf273c639066cb3fd4997b58efe1fdb7322e4 (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 6016bc83d369186275044bd8539f66a3cb03c4cb
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Tue Jun 20 09:04:14 2017 -0400

    RT# 75817 - Added the ability to set contacts password on the backend
    
    Conflicts:
    	httemplate/elements/validate_password.html
    	httemplate/misc/xmlhttp-validate_password.html

diff --git a/httemplate/edit/cust_main-contacts.html b/httemplate/edit/cust_main-contacts.html
index 381cdc2..7dedfe0 100644
--- a/httemplate/edit/cust_main-contacts.html
+++ b/httemplate/edit/cust_main-contacts.html
@@ -10,6 +10,7 @@
        { 'field'             => 'contactnum',
          'type'              => 'contact',
          'colspan'           => 6,
+         'custnum'           => $custnum, 
          'm2m_method'        => 'cust_contact',
          'm2m_dstcol'        => 'contactnum',   
          'm2_label'          => ' ', #'Contact',
diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html
index f6bc1ab..099b0a5 100644
--- a/httemplate/edit/elements/edit.html
+++ b/httemplate/edit/elements/edit.html
@@ -329,6 +329,10 @@ Example:
 %     #any?
 %     'colspan'       => $f->{'colspan'},
 %     'required'      => $f->{'required'},
+%
+%     #contact
+%     'custnum'     => $f->{'custnum'},
+%     'prospectnum' => $f->{'prospectnum'},
 %   );
 %
 %   $include_common{$_} = $f->{$_} foreach grep exists($f->{$_}),
diff --git a/httemplate/elements/change_password.html b/httemplate/elements/change_password.html
index a84e823..b3a432f 100644
--- a/httemplate/elements/change_password.html
+++ b/httemplate/elements/change_password.html
@@ -8,19 +8,19 @@
   display: none;
 }
 </STYLE>
-<A ID="<%$pre%>link" HREF="javascript:void(0)" onclick="<%$pre%>toggle(true)">(<% emt('change') %>)</A>
+<A ID="<%$pre%>link" HREF="javascript:void(0)" onclick="<%$pre%>toggle(true)">(<% emt( $change_title ) %>)</A>
 <DIV ID="<%$pre%>form" CLASS="passwordbox">
   <FORM METHOD="POST" ACTION="<%$fsurl%>misc/process/change-password.html">
-    <INPUT TYPE="hidden" NAME="svcnum" VALUE="<% $svc_acct->svcnum |h%>">
+    <% $change_id_input %>
     <INPUT TYPE="text" ID="<%$pre%>password" NAME="password" VALUE="<% $curr_value |h%>">
     <& /elements/random_pass.html, $pre.'password', 'randomize' &>
     <INPUT TYPE="submit" VALUE="change">
     <INPUT TYPE="button" VALUE="cancel" onclick="<%$pre%>toggle(false)">
     <DIV ID="<%$pre%>password_result" STYLE="font-size: smaller"></DIV>
     <& '/elements/validate_password.html', 
-         'fieldid' => $pre.'password',
-         'svcnum'  => $svc_acct->svcnum,
-
+         'fieldid'    => $pre.'password',
+         'svcnum'     => $svcnum,
+         'contactnum' => $contactnum,
     &>
 % if ( $error ) {
     <BR><SPAN STYLE="color: #ff0000"><% $error |h %></SPAN>
@@ -40,8 +40,28 @@ function <%$pre%>toggle(val) {
 </SCRIPT>
 <%init>
 my %opt = @_;
-my $svc_acct = $opt{'svc_acct'};
+
+my $contactnum = $opt{'contact_num'};
 my $curr_value = $opt{'curr_value'} || '';
-my $pre = 'changepw'.$svc_acct->svcnum.'_';
-my $error = $cgi->param($pre.'error');
+my $change_title = $opt{'label'} || 'change';
+
+my $svcnum;
+my $change_id_input = '';
+my $pre = 'changepw';
+
+if ($opt{'svc_acct'}) {
+  my $svc_acct = $opt{'svc_acct'};
+  $change_id_input = '<INPUT TYPE="hidden" NAME="svcnum" VALUE="' . $svc_acct->svcnum . '">';
+  $pre .= $svc_acct->svcnum . '_';
+  $svcnum = $svc_acct->svcnum;
+}
+elsif ($opt{'contact_num'}) {
+  $change_id_input = '
+    <INPUT TYPE="hidden" NAME="contactnum" VALUE="' . $opt{'contact_num'} . '">
+    <INPUT TYPE="hidden" NAME="custnum" VALUE="' . $opt{'custnum'} . '">
+  ';
+  $pre .= $opt{'contact_num'} . '_';
+}
+
+ my $error = $cgi->param($pre.'error');
 </%init>
diff --git a/httemplate/elements/contact.html b/httemplate/elements/contact.html
index ec4916d..7799052 100644
--- a/httemplate/elements/contact.html
+++ b/httemplate/elements/contact.html
@@ -72,6 +72,22 @@
           <FONT SIZE="-1"><% $label{$field} %></FONT>
         </TD>
 %     }
+%     my $pwd_change_label = 'change password';
+%     $pwd_change_label = 'setup password' unless $contact->_password;
+%     if ($curr_value) {
+        <TD>
+          <span STYLE="white-space: nowrap">
+            <& /elements/change_password.html,
+              'contact_num' => $curr_value,
+              'custnum'     => $opt{'custnum'},
+              'curr_value'  => '',
+              'label'       => $pwd_change_label,
+            &>
+          </span>
+          <br>
+          <FONT SIZE="-1">Password</FONT>
+        </TD>
+%     }
     </TR>
   </TABLE>
 
diff --git a/httemplate/elements/validate_password.html b/httemplate/elements/validate_password.html
index f067ad8..01e8b94 100644
--- a/httemplate/elements/validate_password.html
+++ b/httemplate/elements/validate_password.html
@@ -31,6 +31,7 @@ function add_password_validation (fieldid) {
       validate_password('fieldid',fieldid,
                         'svcnum',<% $opt{'svcnum'} |js_string %>,
                         'pkgnum',<% $opt{'pkgnum'} |js_string %>,
+                        'contactnum',<% $opt{'contactnum'} |js_string %>,
                         'password',this.value,
         function (result) {
           result = JSON.parse(result);
diff --git a/httemplate/misc/process/change-password.html b/httemplate/misc/process/change-password.html
index d58ce54..250e832 100644
--- a/httemplate/misc/process/change-password.html
+++ b/httemplate/misc/process/change-password.html
@@ -1,28 +1,63 @@
 <%init>
 my $curuser = $FS::CurrentUser::CurrentUser;
 
-$cgi->param('svcnum') =~ /^(\d+)$/ or die "illegal svcnum";
+$cgi->param('svcnum') =~ /^(\d+)$/ or die "illegal svcnum" if $cgi->param('svcnum');
 my $svcnum = $1;
-my $svc_acct = FS::svc_acct->by_key($svcnum)
-  or die "svc_acct $svcnum not found";
-my $part_svc = $svc_acct->part_svc;
-die "access denied" unless (
-  $curuser->access_right('Provision customer service') or
-  ( $curuser->access_right('Edit password') and 
-    ! $part_svc->restrict_edit_password )
-  );
+
+$cgi->param('contactnum') =~ /^(\d+)$/ or die "illegal contactnum" if $cgi->param('contactnum');
+my $contactnum = $1;
+
 my $newpass = $cgi->param('password');
-my $error = $svc_acct->is_password_allowed($newpass)
-        ||  $svc_acct->set_password($newpass)
-        ||  $svc_acct->replace;
 
-# annoyingly specific to view/svc_acct.cgi, for now...
-$cgi->delete('password');
+my $error;
+
+if ($svcnum) {
+	my $svc_acct = FS::svc_acct->by_key($svcnum)
+	  or die "svc_acct $svcnum not found";
+	my $part_svc = $svc_acct->part_svc;
+	die "access denied" unless (
+	  $curuser->access_right('Provision customer service') or
+	  ( $curuser->access_right('Edit password') and 
+	    ! $part_svc->restrict_edit_password )
+	  );
+
+	my $error = $svc_acct->is_password_allowed($newpass)
+	        ||  $svc_acct->set_password($newpass)
+	        ||  $svc_acct->replace;
+
+	# annoyingly specific to view/svc_acct.cgi, for now...
+	$cgi->delete('password');
+}
+elsif ($contactnum) {
+	my $contact = qsearchs('contact', { 'contactnum' => $contactnum } )
+      or return { 'error' => "Contact not found" . $contactnum };
+
+	my $error = $contact->is_password_allowed($newpass)
+	        ||  $contact->change_password($newpass);
+
+	# annoyingly specific to view/svc_acct.cgi, for now...
+	#$cgi->delete('password');
+}
+
 </%init>
 % if ( $error ) {
-%   $cgi->param('svcnum', $svcnum);
-%   $cgi->param("changepw${svcnum}_error", $error);
+%	if ($svcnum) {
+%   		$cgi->param('svcnum', $svcnum);
+%   		$cgi->param("changepw${svcnum}_error", $error);
+%	}
+%	elsif ($contactnum) {
+%   		$cgi->param('contactnum', $contactnum);
+%   		$cgi->param("changepw${contactnum}_error", $error);
+%	}
 % } else {
-%   $cgi->query_string($svcnum);
+%	if ($svcnum) { $cgi->query_string($svcnum); }
+%	elsif ($contactnum) { $cgi->query_string($contactnum); }
+% }
+%warn('my pwd error is ' . $error . ' end');
+% if ($svcnum) { 
+	<% $cgi->redirect($fsurl.'view/svc_acct.cgi?'.$cgi->query_string) %>
 % }
-<% $cgi->redirect($fsurl.'view/svc_acct.cgi?'.$cgi->query_string) %>
+% elsif ($contactnum) { 
+	<% $cgi->redirect($fsurl.'edit/cust_main-contacts.html?'.$cgi->param('custnum')) %>
+% }
+
diff --git a/httemplate/misc/xmlhttp-validate_password.html b/httemplate/misc/xmlhttp-validate_password.html
index 1efb4aa..b340170 100644
--- a/httemplate/misc/xmlhttp-validate_password.html
+++ b/httemplate/misc/xmlhttp-validate_password.html
@@ -29,21 +29,37 @@ my $validate_password = sub {
   $result{'syserror'} = 'Invoked without password' unless $password;
   return \%result if $result{'syserror'};
 
-  my $svcnum = $arg{'svcnum'};
-  $result{'syserror'} = 'Invalid svcnum' unless $svcnum =~ /^\d*$/;
-  return \%result if $result{'syserror'};
+  if ($arg{'contactnum'}) {
+    my $contactnum = $arg{'contactnum'};
+    $result{'syserror'} = 'Invalid contactnum' unless $contactnum =~ /^\d*$/;
+    return \%result if $result{'syserror'};
 
-  my $pkgnum = $arg{'pkgnum'};
-  $result{'syserror'} = 'Invalid pkgnum' unless $pkgnum =~ /^\d*$/;
-  return \%result if $result{'syserror'};
+    my $contact = $contactnum 
+      ? qsearchs('contact',{'contactnum' => $contactnum})
+      : '';
 
-  my $svc_acct = $svcnum 
-    ? qsearchs('svc_acct',{'svcnum' => $svcnum})
-    : FS::svc_acct->new({ 'pkgnum' => $pkgnum });
-  $result{'syserror'} = 'Could not find service' unless $svc_acct;
-  return \%result if $result{'syserror'};
+    $result{'error'} = $contact->is_password_allowed($password);
+  }
+
+  if ($arg{'svcnum'}) {
+    my $pkgnum = $arg{'pkgnum'};
+    $result{'syserror'} = 'Invalid pkgnum' unless $pkgnum =~ /^\d*$/;
+    return \%result if $result{'syserror'};
+
+    my $svcnum = $arg{'svcnum'};
+    $result{'syserror'} = 'Invalid svcnum' unless $svcnum =~ /^\d*$/;
+    return \%result if $result{'syserror'};
+
+    my $svc_acct = $svcnum 
+      ? qsearchs('svc_acct',{'svcnum' => $svcnum})
+      : FS::svc_acct->new({ 'pkgnum' => $pkgnum });
+    $result{'syserror'} = 'Could not find service' unless $svc_acct;
+    return \%result if $result{'syserror'};
+
+    $result{'error'} = $svc_acct->is_password_allowed($password);
+  }
 
-  $result{'error'} = $svc_acct->is_password_allowed($password);
+ # $result{'error'} = $svc_acct->is_password_allowed($password);
   $result{'valid'} = 1 unless $result{'error'};
   return \%result;
 };

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

Summary of changes:
 httemplate/edit/cust_main-contacts.html        |    1 +
 httemplate/edit/elements/edit.html             |    4 ++
 httemplate/elements/change_password.html       |   36 +++++++++---
 httemplate/elements/contact.html               |   16 ++++++
 httemplate/elements/validate_password.html     |    1 +
 httemplate/misc/process/change-password.html   |   71 ++++++++++++++++++------
 httemplate/misc/xmlhttp-validate_password.html |   40 +++++++++----
 7 files changed, 131 insertions(+), 38 deletions(-)




More information about the freeside-commits mailing list