From 367ff2ec9a5d8e6bf73c67d02834460c069c7ede Mon Sep 17 00:00:00 2001 From: Christopher Burger Date: Fri, 7 Sep 2018 10:55:19 -0400 Subject: [PATCH] RT# 75817 - fixed saving of password for new contacts, and password validation on dynamicly created rows Conflicts: FS/FS/contact.pm httemplate/edit/elements/edit.html --- FS/FS/contact.pm | 12 +++++++-- httemplate/edit/cust_main-contacts.html | 7 +++++ httemplate/edit/elements/edit.html | 2 +- httemplate/edit/process/elements/process.html | 2 +- httemplate/elements/contact.html | 37 +++++++++++++++------------ 5 files changed, 39 insertions(+), 21 deletions(-) diff --git a/FS/FS/contact.pm b/FS/FS/contact.pm index 4db3cdfd1..8f6b6a3b5 100644 --- a/FS/FS/contact.pm +++ b/FS/FS/contact.pm @@ -131,7 +131,6 @@ sub insert { my $dbh = dbh; my $error = $self->SUPER::insert; - $error ||= $self->insert_password_history; if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -191,6 +190,15 @@ sub insert { } } + 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; ''; @@ -614,7 +622,7 @@ sub authenticate_password { $hash eq $check_hash; - } else { + } else { return 0 if $self->_password eq ''; diff --git a/httemplate/edit/cust_main-contacts.html b/httemplate/edit/cust_main-contacts.html index b3f67726b..b046c5b18 100644 --- a/httemplate/edit/cust_main-contacts.html +++ b/httemplate/edit/cust_main-contacts.html @@ -51,6 +51,13 @@ my $curuser = $FS::CurrentUser::CurrentUser; my $conf = new FS::Conf; +if ( $cgi->param('redirect') ) { + my $session = $cgi->param('redirect'); + my $pref = $curuser->option("redirect$session"); + die "unknown redirect session $session\n" unless length($pref); + $cgi = new CGI($pref); +} + my $custnum; if ( $cgi->param('error') ) { $custnum = scalar($cgi->param('custnum')); diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html index 3826f9752..ff1da4945 100644 --- a/httemplate/edit/elements/edit.html +++ b/httemplate/edit/elements/edit.html @@ -633,7 +633,7 @@ Example: var newrow = <% include(@layer_opt, html_only=>1) |js_string %>; % #until the rest have html/js_only -% if ( $type eq 'selectlayers' || $type =~ /^select-cgp_rule_/ ) { +% if ( $type eq 'selectlayers' || $type =~ /^select-cgp_rule_/ || $type eq 'contact') { var newfunc = <% include(@layer_opt, js_only=>1) |js_string %>; % } else { var newfunc = ''; diff --git a/httemplate/edit/process/elements/process.html b/httemplate/edit/process/elements/process.html index 11757237a..5b9ed6b52 100644 --- a/httemplate/edit/process/elements/process.html +++ b/httemplate/edit/process/elements/process.html @@ -123,7 +123,7 @@ Example: % " attempting to set redirect$session to ". $cgi->query_string."\n"; % } % -<% $cgi->redirect("$error_redirect?redirect=$session") %> +<% $cgi->redirect("$error_redirect"."redirect=$session") %> % % } else { % diff --git a/httemplate/elements/contact.html b/httemplate/elements/contact.html index e330e1fea..ccbb431ab 100644 --- a/httemplate/elements/contact.html +++ b/httemplate/elements/contact.html @@ -1,4 +1,6 @@ -% unless ( $opt{'js_only'} ) { +% if ( $opt{'js_only'} ) { +<% $js %> +% } else { @@ -70,23 +72,8 @@ VALUE = "" placeholder = "<% $value |h %>" > -% my $contactnum = $curr_value ? $curr_value : '0'; - - - % } elsif ( $field eq 'invoice_dest' ) { % my $curr_value = $cgi->param($name . '_' . $field); @@ -131,6 +118,7 @@ my $name = $opt{'element_name'} || $opt{'field'} || 'contactnum'; my $id = $opt{'id'} || 'contactnum'; my $curr_value = $opt{'curr_value'} || $opt{'value'}; +my $contactnum = $curr_value ? $curr_value : '0'; my $onchange = ''; if ( $opt{'onchange'} ) { @@ -177,4 +165,19 @@ $label{'comment'} = 'Comment'; my @fields = $opt{'name_only'} ? qw( first last ) : keys %label; +my $js = qq( + add_password_validation('changepw$id\_password', 'submit', '', '$contactnum'); + + var selfService = document.getElementById("$id\_selfservice_access").value; + + if (selfService !== "Y") { document.getElementById("changepw$id\_password").disabled = 'true'; } + document.getElementById("$id\_selfservice_access").onchange = function() { + if (this.value == "P" || this.value == "E" || this.value =="Y") { + document.getElementById("changepw$id\_password").disabled = ''; + } + else { document.getElementById("changepw$id\_password").disabled = 'true'; } + return false; + } +); + -- 2.11.0