RT# 82132 - updated selfservice login to use config username-uppercase
authorChristopher Burger <burgerc@freeside.biz>
Tue, 7 May 2019 13:19:57 +0000 (09:19 -0400)
committerChristopher Burger <burgerc@freeside.biz>
Tue, 7 May 2019 19:12:42 +0000 (15:12 -0400)
Conflicts:
FS/FS/ClientAPI/MyAccount.pm
FS/FS/contact.pm

FS/FS/ClientAPI/MyAccount.pm
FS/FS/contact.pm

index cb6a938..dae2e19 100644 (file)
@@ -216,9 +216,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') ) { 
 
@@ -237,9 +237,16 @@ 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'))
           )
   {
+    if ($conf->exists('username-uppercase') || $conf->exists('username-uppercase', $contact->cust_main->agentnum)) {
+      $contact = FS::contact->by_selfservice_email_custnum($p->{email}, $contact->custnum);
+    }
+
+    return { error => 'Email '.$p->{email}.' not found!'}
+      unless $contact;
+
     return { error => 'Incorrect contact password.' }
       unless $contact->authenticate_password($p->{'password'});
 
index 8f6b6a3..761f751 100644 (file)
@@ -586,7 +586,33 @@ has that email address.
 =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 selfservice_access = 'Y' ".
+                   " AND ( disabled IS NULL OR disabled = '' )",
+  }) 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',