From a08453e81bddef781785954516d4ca176bf7a6d8 Mon Sep 17 00:00:00 2001 From: Christopher Burger Date: Thu, 6 Jul 2017 11:52:22 -0400 Subject: [PATCH] RT# 75817 - fixed contact password page to be more consistant with svc password page, updated javascript to check password as you type rather than when you leave the field. Conflicts: FS/FS/contact.pm FS/FS/cust_contact.pm httemplate/elements/contact.html --- FS/FS/contact.pm | 12 ++- FS/FS/cust_contact.pm | 151 +++++++++++++++++++++++++++++ httemplate/elements/change_password.html | 60 +++++++----- httemplate/elements/contact.html | 52 +++++----- httemplate/elements/random_pass.html | 8 +- httemplate/elements/validate_password.html | 10 +- 6 files changed, 241 insertions(+), 52 deletions(-) create mode 100644 FS/FS/cust_contact.pm diff --git a/FS/FS/contact.pm b/FS/FS/contact.pm index ad0de6e32..76ebe98bb 100644 --- a/FS/FS/contact.pm +++ b/FS/FS/contact.pm @@ -370,6 +370,15 @@ sub replace { } } + 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; ''; @@ -456,7 +465,7 @@ and replace methods. sub check { my $self = shift; - if ( $self->selfservice_access eq 'R' ) { + if ( $self->selfservice_access eq 'R' || $self->selfservice_access eq 'P' ) { $self->selfservice_access('Y'); $self->_resend('Y'); } @@ -742,6 +751,7 @@ sub cgi_contact_fields { my @contact_fields = qw( classnum first last title comment emailaddress selfservice_access + invoice_dest password ); push @contact_fields, 'phonetypenum'. $_->phonetypenum diff --git a/FS/FS/cust_contact.pm b/FS/FS/cust_contact.pm new file mode 100644 index 000000000..6820ac4b4 --- /dev/null +++ b/FS/FS/cust_contact.pm @@ -0,0 +1,151 @@ +package FS::cust_contact; +use base qw( FS::Record ); + +use strict; +use FS::Record qw( qsearch qsearchs ); + +=head1 NAME + +FS::cust_contact - Object methods for cust_contact records + +=head1 SYNOPSIS + + use FS::cust_contact; + + $record = new FS::cust_contact \%hash; + $record = new FS::cust_contact { 'column' => 'value' }; + + $error = $record->insert; + + $error = $new_record->replace($old_record); + + $error = $record->delete; + + $error = $record->check; + +=head1 DESCRIPTION + +An FS::cust_contact object represents a contact's attachment to a specific +customer. FS::cust_contact inherits from FS::Record. The following fields are +currently supported: + +=over 4 + +=item custcontactnum + +primary key + +=item custnum + +custnum + +=item contactnum + +contactnum + +=item classnum + +classnum + +=item comment + +comment + +=item selfservice_access + +empty or Y + +=item invoice_dest + +'Y' if the customer should get invoices sent to this address, null if not + +=back + +=head1 METHODS + +=over 4 + +=item new HASHREF + +Creates a new record. To add the record to the database, see L<"insert">. + +Note that this stores the hash reference, not a distinct copy of the hash it +points to. You can ask the object for a copy with the I method. + +=cut + +# the new method can be inherited from FS::Record, if a table method is defined + +sub table { 'cust_contact'; } + +=item insert + +Adds this record to the database. If there is an error, returns the error, +otherwise returns false. + +=item delete + +Delete this record from the database. + +=item replace OLD_RECORD + +Replaces the OLD_RECORD with this one in the database. If there is an error, +returns the error, otherwise returns false. + +=item check + +Checks all fields to make sure this is a valid record. If there is +an error, returns the error, otherwise returns false. Called by the insert +and replace methods. + +=cut + +# the check method should currently be supplied - FS::Record contains some +# data checking routines + +sub check { + my $self = shift; + + if ( $self->selfservice_access eq 'R' || $self->selfservice_access eq 'P') { + $self->selfservice_access('Y'); + $self->_resend('Y'); + } + + my $error = + $self->ut_numbern('custcontactnum') + || $self->ut_number('custnum') + || $self->ut_number('contactnum') + || $self->ut_numbern('classnum') + || $self->ut_textn('comment') + || $self->ut_enum('selfservice_access', [ '', 'Y' ]) + || $self->ut_flag('invoice_dest') + ; + return $error if $error; + + $self->SUPER::check; +} + +=item contact_classname + +Returns the name of this contact's class (see L). + +=cut + +sub contact_classname { + my $self = shift; + my $contact_class = $self->contact_class or return ''; + $contact_class->classname; +} + +=back + +=head1 BUGS + +=head1 SEE ALSO + +L, L, L + +=cut + +1; + diff --git a/httemplate/elements/change_password.html b/httemplate/elements/change_password.html index a8cc883b9..463384f2f 100644 --- a/httemplate/elements/change_password.html +++ b/httemplate/elements/change_password.html @@ -8,69 +8,81 @@ display: none; } +% if (!$opt{'no_label_display'}) { (<% emt( $change_title ) %>) +% }
+% if (!$opt{'noformtag'}) {
- <% $change_id_input %> - - <& /elements/random_pass.html, $pre.'password', 'randomize' &> - -% if ($opt{'popup'}) { - % } -% else { - + + <% $change_id_input %> + + <& /elements/random_pass.html, $pre.'password', 'randomize', $change_button_id &> +% if (!$opt{'noformtag'}) { + +% } else { + %} + +
<& '/elements/validate_password.html', 'fieldid' => $pre.'password', 'svcnum' => $svcnum, - 'contactnum' => $contactnum, + 'contactnum' => $opt{'contact_num'}, + 'submitid' => $change_button_id, &> % if ( $error ) {
<% $error |h %> % } + +% if (!$opt{'noformtag'}) {
+% } +
<%init> my %opt = @_; -my $contactnum = $opt{'contact_num'}; my $curr_value = $opt{'curr_value'} || ''; 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 = ''; + $change_id_input = ''; $pre .= $svc_acct->svcnum . '_'; $svcnum = $svc_acct->svcnum; } elsif ($opt{'contact_num'}) { $change_id_input = ' - - + + '; - $pre .= $opt{'contact_num'} . '_'; + $pre .= $opt{'pre_pwd_field_label'}; } -if ($opt{'popup'}) { - $change_id_input .= ''; -} +my $change_button_id = $pre.'change_button'; my $error = $cgi->param($pre.'error'); diff --git a/httemplate/elements/contact.html b/httemplate/elements/contact.html index 755daed24..df2107ac1 100644 --- a/httemplate/elements/contact.html +++ b/httemplate/elements/contact.html @@ -46,18 +46,44 @@ % if ( $field eq 'selfservice_access' ) { + - + <& /elements/change_password.html, + 'contact_num' => $curr_value, + 'custnum' => $opt{'custnum'}, + 'curr_value' => '', + 'no_label_display' => '1', + 'noformtag' => '1', + 'pre_pwd_field_label' => $id.'_', + &> + +% } elsif ( $field eq 'invoice_dest' ) { +% my $curr_value = $cgi->param($name . '_' . $field); +% $curr_value = $value if !defined($curr_value); + <& select.html, + field => $name . '_' . $field, + curr_value => $curr_value, + options => [ '', 'Y' ], + option_labels => { '' => 'no', 'Y' => 'yes' }, + style => 'width: 100%', + &> % } else { <% $label{$field} %> % } -% my $pwd_change_label = 'change'; -% $pwd_change_label = 'setup' unless $contact->_password; -% my $action = $fsurl . "edit/cust_main-contacts-password.html?custnum=" . $opt{'custnum'} . "&contactnum=" . $curr_value . "&label=" . $pwd_change_label . "&popup=1"; -% if ($curr_value) { - - <% include('/elements/popup_link.html', - 'action' => $action, - 'width' => '763', - 'height' => '408', - 'actionlabel' => "$pwd_change_label password", - 'html_label' => "$pwd_change_label password", - - ) - %> -
- Password - -% } @@ -100,9 +108,6 @@ my( %opt ) = @_; my $conf = new FS::Conf; -use Data::Dumper; -print Dumper($conf->config); - my $self_base_url = $conf->config('selfservice_server-base_url'); my $name = $opt{'element_name'} || $opt{'field'} || 'contactnum'; @@ -150,4 +155,7 @@ $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; + diff --git a/httemplate/elements/random_pass.html b/httemplate/elements/random_pass.html index 1517a55d7..778aa20e6 100644 --- a/httemplate/elements/random_pass.html +++ b/httemplate/elements/random_pass.html @@ -1,6 +1,6 @@ - + <%init> my $id = shift; my $label = shift || 'Generate'; +my $submitid = shift; my $pw_set = join('', FS::Password_Mixin->pw_set); my $lower = join('', $pw_set =~ /[[:lower:]]/g); my $upper = join('', $pw_set =~ /[[:upper:]]/g); diff --git a/httemplate/elements/validate_password.html b/httemplate/elements/validate_password.html index cb1502939..3ca311db1 100644 --- a/httemplate/elements/validate_password.html +++ b/httemplate/elements/validate_password.html @@ -21,9 +21,9 @@ should be the input id plus '_result'. 'method' => 'POST', # important not to put passwords in url &> <%init> -- 2.11.0