[freeside-commits] branch FREESIDE_4_BRANCH updated. 590301adce46a6f8237b5bdfb134d68285fb01de

Christopher Burger burgerc at freeside.biz
Tue May 7 09:23:19 PDT 2019


The branch, FREESIDE_4_BRANCH has been updated
       via  590301adce46a6f8237b5bdfb134d68285fb01de (commit)
       via  231831c3aa77729fb0cf75557099659ab0082259 (commit)
      from  37e986126fa8e061b3e366d855eae067736dda3a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 590301adce46a6f8237b5bdfb134d68285fb01de
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Tue May 7 12:02:22 2019 -0400

    RT# 82132 - updated password reset by mail to use username-uppercase config

diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm
index 315454592..91248a532 100644
--- a/FS/FS/ClientAPI/MyAccount.pm
+++ b/FS/FS/ClientAPI/MyAccount.pm
@@ -3306,13 +3306,22 @@ sub reset_passwd {
   my $cust_main = '';
   if ( $p->{'email'} ) { #new-style, changes contact and svc_acct
   
-    $contact = FS::contact->by_selfservice_email($p->{'email'});
+    $contact = FS::contact->by_selfservice_email($p->{'email'}, 'case_insensitive');
 
-    if ( $contact ) {
-      my @cust_contact = grep $_->selfservice_access, $contact->cust_contact;
-      $cust_main = $cust_contact[0]->cust_main if scalar(@cust_contact) == 1;
+    my @customers = grep $_->selfservice_access, $contact->cust_contact;
+    my @cust_contact;
+
+    foreach my $customer (@customers) {
+      if ($conf->exists('username-uppercase') || $conf->exists('username-uppercase', $customer->cust_main->agentnum)) {
+        my $check_contact = FS::contact->by_selfservice_email_custnum($p->{email}, $customer->custnum);
+        push @cust_contact, $customer if $check_contact;
+      }
+      else { push @cust_contact, $customer; }
     }
 
+    $contact = '' unless @cust_contact;
+    $cust_main = $cust_contact[0]->cust_main if scalar(@cust_contact) == 1;
+
     #also look for an svc_acct, otherwise it would be super confusing
 
     my($username, $domain) = split('@', $p->{'email'});

commit 231831c3aa77729fb0cf75557099659ab0082259
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Tue May 7 09:19:57 2019 -0400

    RT# 82132 - updated selfservice login to use config username-uppercase

diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm
index 162e6ae76..315454592 100644
--- a/FS/FS/ClientAPI/MyAccount.pm
+++ b/FS/FS/ClientAPI/MyAccount.pm
@@ -217,9 +217,9 @@ sub login {
   my $p = shift;
 
   my $conf = new FS::Conf;
-
   my $svc_x = '';
   my $session = {};
+
   if ( $p->{'domain'} eq 'svc_phone'
        && $conf->exists('selfservice_server-phone_login') ) { 
 
@@ -238,15 +238,28 @@ sub login {
     $svc_x = $svc_phone;
 
   } elsif ( $p->{email}
-              && (my $contact = FS::contact->by_selfservice_email($p->{email}))
+              && (my $contact = FS::contact->by_selfservice_email($p->{email},'case_insensitive'))
           )
   {
+    my @customers = grep $_->selfservice_access, $contact->cust_contact;
+    my @cust_contact;
+
+    foreach my $customer (@customers) {
+      if ($conf->exists('username-uppercase') || $conf->exists('username-uppercase', $customer->cust_main->agentnum)) {
+        my $check_contact = FS::contact->by_selfservice_email_custnum($p->{email}, $customer->custnum);
+        push @cust_contact, $customer if $check_contact;
+      }
+      else { push @cust_contact, $customer; }
+    }
+
+    return { error => 'Email '.$p->{email}.' not found!'}
+      unless @cust_contact;
+
     return { error => 'Incorrect contact password.' }
       unless $contact->authenticate_password($p->{'password'});
 
     $session->{'contactnum'} = $contact->contactnum;
 
-    my @cust_contact = grep $_->selfservice_access, $contact->cust_contact;
     if ( scalar(@cust_contact) == 1 ) {
       $session->{'custnum'} = $cust_contact[0]->custnum;
     } elsif ( scalar(@cust_contact) ) {
diff --git a/FS/FS/contact.pm b/FS/FS/contact.pm
index 03023e5e7..7f2470ab9 100644
--- a/FS/FS/contact.pm
+++ b/FS/FS/contact.pm
@@ -834,7 +834,38 @@ or there isn't one, returns the empty string.
 =cut
 
 sub by_selfservice_email {
-  my($class, $email) = @_;
+  my($class, $email, $case_insensitive) = @_;
+
+  my $email_search = "emailaddress = '".$email."'";
+  $email_search = "LOWER(emailaddress) = LOWER('".$email."')" if $case_insensitive;
+
+  my $contact_email = qsearchs({
+    'table'     => 'contact_email',
+    'addl_from' => ' LEFT JOIN contact USING ( contactnum ) ',
+    'extra_sql' => "
+      WHERE $email_search
+      AND ( contact.disabled IS NULL )
+      AND EXISTS ( SELECT 1 FROM cust_contact
+                     WHERE contact.contactnum = cust_contact.contactnum
+                       AND cust_contact.selfservice_access = 'Y'
+                 )
+    ",
+  }) or return '';
+
+  $contact_email->contact;
+
+}
+
+=item by_selfservice_email_custnum EMAILADDRESS, CUSTNUM
+
+Alternate search constructor (class method).  Given an email address and custnum, returns
+the contact for that address and custnum. If that contact doesn't have selfservice access,
+or there isn't one, returns the empty string.
+
+=cut
+
+sub by_selfservice_email_custnum {
+  my($class, $email, $custnum) = @_;
 
   my $contact_email = qsearchs({
     'table'     => 'contact_email',
@@ -845,6 +876,7 @@ sub by_selfservice_email {
       AND EXISTS ( SELECT 1 FROM cust_contact
                      WHERE contact.contactnum = cust_contact.contactnum
                        AND cust_contact.selfservice_access = 'Y'
+                       AND cust_contact.custnum = $custnum
                  )
     ",
   }) or return '';

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/ClientAPI/MyAccount.pm | 36 +++++++++++++++++++++++++++++-------
 FS/FS/contact.pm             | 34 +++++++++++++++++++++++++++++++++-
 2 files changed, 62 insertions(+), 8 deletions(-)




More information about the freeside-commits mailing list