summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--httemplate/elements/change_password.html36
-rw-r--r--httemplate/elements/contact.html16
-rw-r--r--httemplate/elements/validate_password.html2
-rw-r--r--httemplate/misc/process/change-password.html71
-rw-r--r--httemplate/misc/xmlhttp-validate_password.html34
5 files changed, 123 insertions, 36 deletions
diff --git a/httemplate/elements/change_password.html b/httemplate/elements/change_password.html
index a84e823d2..b3a432f95 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 b0a7caca1..8936569ce 100644
--- a/httemplate/elements/contact.html
+++ b/httemplate/elements/contact.html
@@ -85,6 +85,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 a488c4f16..bd385a6ca 100644
--- a/httemplate/elements/validate_password.html
+++ b/httemplate/elements/validate_password.html
@@ -27,7 +27,7 @@ function add_password_validation (fieldid) {
var resultfield = document.getElementById(fieldid);
if (this.value) {
resultfield.innerHTML = '<SPAN STYLE="color: blue;">Validating password...</SPAN>';
- validate_password('fieldid',fieldid,'svcnum','<% $opt{'svcnum'} %>','password',this.value,
+ 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);
diff --git a/httemplate/misc/process/change-password.html b/httemplate/misc/process/change-password.html
index d58ce544d..250e8320b 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 28dbf6460..4d9716bb9 100644
--- a/httemplate/misc/xmlhttp-validate_password.html
+++ b/httemplate/misc/xmlhttp-validate_password.html
@@ -28,17 +28,33 @@ 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 $svc_acct = $svcnum
- ? qsearchs('svc_acct',{'svcnum' => $svcnum})
- : (new FS::svc_acct {});
- $result{'syserror'} = 'Could not find service' unless $svc_acct;
- return \%result if $result{'syserror'};
+ my $contact = $contactnum
+ ? qsearchs('contact',{'contactnum' => $contactnum})
+ : '';
+
+ $result{'error'} = $contact->is_password_allowed($password);
+ }
+
+ if ($arg{'svcnum'}) {
+ 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})
+ : (new FS::svc_acct {});
+ $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;
};