From 6016bc83d369186275044bd8539f66a3cb03c4cb 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 Conflicts: httemplate/elements/validate_password.html httemplate/misc/xmlhttp-validate_password.html --- 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(-) diff --git a/httemplate/edit/cust_main-contacts.html b/httemplate/edit/cust_main-contacts.html index 381cdc2ea..7dedfe04d 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 f6bc1abb5..099b0a57e 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 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 ec4916dfa..779905234 100644 --- a/httemplate/elements/contact.html +++ b/httemplate/elements/contact.html @@ -72,6 +72,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 f067ad8fc..01e8b94d9 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 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 1efb4aaa3..b340170f8 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; }; -- 2.11.0