From: Christopher Burger Date: Tue, 7 May 2019 13:19:57 +0000 (-0400) Subject: RT# 82132 - updated selfservice login to use config username-uppercase X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=4f53fbbb88637f3c7d44db2e16933d1754323b78 RT# 82132 - updated selfservice login to use config username-uppercase Conflicts: FS/FS/ClientAPI/MyAccount.pm FS/FS/contact.pm --- diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index cb6a938da..dae2e1929 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -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'}); diff --git a/FS/FS/contact.pm b/FS/FS/contact.pm index 8f6b6a3b5..761f751cd 100644 --- a/FS/FS/contact.pm +++ b/FS/FS/contact.pm @@ -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',