From 2eefefbe2f93bd6f306c7f73443028dbfd70782e Mon Sep 17 00:00:00 2001 From: Christopher Burger Date: Tue, 20 Jun 2017 09:04:14 -0400 Subject: [PATCH] RT# 75817 - Added the ability to set contacts password on the backend --- httemplate/elements/change_password.html | 36 ++++++++++--- httemplate/elements/contact.html | 16 ++++++ httemplate/elements/validate_password.html | 2 +- httemplate/misc/process/change-password.html | 71 +++++++++++++++++++------- httemplate/misc/xmlhttp-validate_password.html | 34 ++++++++---- 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; } -(<% emt('change') %>) +(<% emt( $change_title ) %>)
- + <% $change_id_input %> <& /elements/random_pass.html, $pre.'password', 'randomize' &>
<& '/elements/validate_password.html', - 'fieldid' => $pre.'password', - 'svcnum' => $svc_acct->svcnum, - + 'fieldid' => $pre.'password', + 'svcnum' => $svcnum, + 'contactnum' => $contactnum, &> % if ( $error ) {
<% $error |h %> @@ -40,8 +40,28 @@ function <%$pre%>toggle(val) { <%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 = ''; + $pre .= $svc_acct->svcnum . '_'; + $svcnum = $svc_acct->svcnum; +} +elsif ($opt{'contact_num'}) { + $change_id_input = ' + + + '; + $pre .= $opt{'contact_num'} . '_'; +} + + my $error = $cgi->param($pre.'error'); 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 @@ <% $label{$field} %> % } +% my $pwd_change_label = 'change password'; +% $pwd_change_label = 'setup password' unless $contact->_password; +% if ($curr_value) { + + + <& /elements/change_password.html, + 'contact_num' => $curr_value, + 'custnum' => $opt{'custnum'}, + 'curr_value' => '', + 'label' => $pwd_change_label, + &> + +
+ Password + +% } 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 = 'Validating password...'; - 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'); +} + % 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; }; -- 2.11.0