From f837ef4c8f5ab61c141f0859477be0675f1183bb Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 16 Mar 2008 22:24:23 +0000 Subject: [PATCH] phonenum + pin login --- FS/FS/ClientAPI/MyAccount.pm | 56 ++++++++++++++++++++++++++++++++------------ FS/FS/Conf.pm | 7 ++++++ FS/FS/svc_phone.pm | 12 ++++++++++ 3 files changed, 60 insertions(+), 15 deletions(-) diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index 2d3951006..831b21622 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -17,6 +17,7 @@ use FS::Misc qw(card_types); use FS::ClientAPI_SessionCache; use FS::svc_acct; use FS::svc_domain; +use FS::svc_phone; use FS::svc_external; use FS::part_svc; use FS::cust_main; @@ -57,28 +58,53 @@ sub _cache { sub login { my $p = shift; - my $svc_domain = qsearchs('svc_domain', { 'domain' => $p->{'domain'} } ) - or return { error => 'Domain '. $p->{'domain'}. ' not found' }; + my $conf = new FS::Conf; - my $svc_acct = qsearchs( 'svc_acct', { 'username' => $p->{'username'}, - 'domsvc' => $svc_domain->svcnum, } - ); - return { error => 'User not found.' } unless $svc_acct; + my $svc_x = ''; + if ( $p->{'domain'} eq 'svc_phone' + && $conf->exists('selfservice_server-phone_login') ) { - my $conf = new FS::Conf; - my $pkg_svc = $svc_acct->cust_svc->pkg_svc; - return { error => 'Only primary user may log in.' } - if $conf->exists('selfservice_server-primary_only') - && ( ! $pkg_svc || $pkg_svc->primary_svc ne 'Y' ); + my $svc_phone = qsearch( 'svc_phone', { 'phonenum' => $p->{'username'}, } ); + return { error => 'Number not found.' } unless $svc_phone + + #XXX? + #my $pkg_svc = $svc_acct->cust_svc->pkg_svc; + #return { error => 'Only primary user may log in.' } + # if $conf->exists('selfservice_server-primary_only') + # && ( ! $pkg_svc || $pkg_svc->primary_svc ne 'Y' ); + + return { error => 'Incorrect PIN.' } + unless $svc_phone->check_pin($p->{'password'}); + + $svc_x = $svc_phone; + + } else { - return { error => 'Incorrect password.' } - unless $svc_acct->check_password($p->{'password'}); + my $svc_domain = qsearchs('svc_domain', { 'domain' => $p->{'domain'} } ) + or return { error => 'Domain '. $p->{'domain'}. ' not found' }; + + my $svc_acct = qsearchs( 'svc_acct', { 'username' => $p->{'username'}, + 'domsvc' => $svc_domain->svcnum, } + ); + return { error => 'User not found.' } unless $svc_acct; + + my $pkg_svc = $svc_acct->cust_svc->pkg_svc; + return { error => 'Only primary user may log in.' } + if $conf->exists('selfservice_server-primary_only') + && ( ! $pkg_svc || $pkg_svc->primary_svc ne 'Y' ); + + return { error => 'Incorrect password.' } + unless $svc_acct->check_password($p->{'password'}); + + $svc_x = $svc_acct; + + } my $session = { - 'svcnum' => $svc_acct->svcnum, + 'svcnum' => $svc_x->svcnum, }; - my $cust_pkg = $svc_acct->cust_svc->cust_pkg; + my $cust_pkg = $svc_x->cust_svc->cust_pkg; if ( $cust_pkg ) { my $cust_main = $cust_pkg->cust_main; $session->{'custnum'} = $cust_main->custnum; diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index b7edd0dee..717eb6d29 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -1592,6 +1592,13 @@ worry that config_items is freeside-specific and icky. }, { + 'key' => 'selfservice_server-phone_login', + 'section' => '', + 'description' => 'Allow login to self-service with phone number and PIN.', + 'type' => 'checkbox', + }, + + { 'key' => 'card_refund-days', 'section' => 'billing', 'description' => 'After a payment, the number of days a refund link will be available for that payment. Defaults to 120.', diff --git a/FS/FS/svc_phone.pm b/FS/FS/svc_phone.pm index 00ccc1958..90ba24945 100644 --- a/FS/FS/svc_phone.pm +++ b/FS/FS/svc_phone.pm @@ -175,6 +175,18 @@ sub check { $self->SUPER::check; } +=item check_pin + +Checks the supplied PIN against the PIN in the database. Returns true for a +sucessful authentication, false if no match. + +=cut + +sub check_pin { + my($self, $check_pin) = @_; + $check_pin eq $self->pin; +} + =back =head1 BUGS -- 2.11.0