From b023b9a96799ee2ad11abc0c23fcaf33a8bf12ca Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 29 Nov 2008 21:54:35 +0000 Subject: [PATCH] add selfservice_server-single_domain config, and login_info self-service method to give the login page a bit more configurability --- FS/FS/ClientAPI/MyAccount.pm | 14 +++++ FS/FS/svc_phone.pm | 2 +- fs_selfservice/FS-SelfService/SelfService.pm | 50 +++++++++++---- fs_selfservice/FS-SelfService/cgi/login.html | 76 ++++++++++++++++++++--- fs_selfservice/FS-SelfService/cgi/selfservice.cgi | 23 +++++-- 5 files changed, 136 insertions(+), 29 deletions(-) diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index 114a359b7..e15476153 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -55,6 +55,20 @@ sub _cache { } ); } +sub login_info { + my $p = shift; + + my $conf = new FS::Conf; + + my %info = ( + 'phone_login' => $conf->exists('selfservice_server-phone_login'), + 'single_domain'=> scalar($conf->config('selfservice_server-single_domain')), + ); + + return \%info; + +} + #false laziness w/FS::ClientAPI::passwd::passwd sub login { my $p = shift; diff --git a/FS/FS/svc_phone.pm b/FS/FS/svc_phone.pm index 237bbf5c7..5dcb39ef8 100644 --- a/FS/FS/svc_phone.pm +++ b/FS/FS/svc_phone.pm @@ -224,7 +224,7 @@ sucessful authentication, false if no match. sub check_pin { my($self, $check_pin) = @_; - $check_pin eq $self->pin; + length($self->pin) && $check_pin eq $self->pin; } =item radius_reply diff --git a/fs_selfservice/FS-SelfService/SelfService.pm b/fs_selfservice/FS-SelfService/SelfService.pm index cba85e0db..56c96f61b 100644 --- a/fs_selfservice/FS-SelfService/SelfService.pm +++ b/fs_selfservice/FS-SelfService/SelfService.pm @@ -25,6 +25,7 @@ $socket .= '.'.$tag if defined $tag && length($tag); 'passwd' => 'passwd/passwd', 'chfn' => 'passwd/passwd', 'chsh' => 'passwd/passwd', + 'login_info' => 'MyAccount/login_info', 'login' => 'MyAccount/login', 'logout' => 'MyAccount/logout', 'customer_info' => 'MyAccount/customer_info', @@ -63,7 +64,11 @@ $socket .= '.'.$tag if defined $tag && length($tag); 'call_time_nanpa' => 'PrepaidPhone/call_time_nanpa', 'phonenum_balance' => 'PrepaidPhone/phonenum_balance', ); -@EXPORT_OK = ( keys(%autoload), qw( regionselector expselect popselector domainselector didselector) ); +@EXPORT_OK = ( + keys(%autoload), + qw( regionselector regionselector_hashref + expselect popselector domainselector didselector ) +); $ENV{'PATH'} ='/usr/bin:/usr/ucb:/bin'; $ENV{'SHELL'} = '/bin/sh'; @@ -1189,24 +1194,45 @@ END } $state_html .= ''; - $state_html .= ''; + my $country_html = ''; + if ( scalar( keys %cust_main_county ) > 1 ) { + + $country_html = qq('; + } else { + + $country_html = qq('; - my $country_html = qq!'; ($county_html, $state_html, $country_html); } +sub regionselector_hashref { + my ($county_html, $state_html, $country_html) = regionselector(@_); + { + 'county_html' => $county_html, + 'state_html' => $state_html, + 'country_html' => $country_html, + }; +} + #=item expselect HASHREF | LIST # #Takes as input a hashref or list of key/value pairs with the following keys: diff --git a/fs_selfservice/FS-SelfService/cgi/login.html b/fs_selfservice/FS-SelfService/cgi/login.html index 5607de783..e5daec859 100644 --- a/fs_selfservice/FS-SelfService/cgi/login.html +++ b/fs_selfservice/FS-SelfService/cgi/login.html @@ -1,29 +1,85 @@ Login Login

<%= $error %> +
+ + - - - - - + +<%= +if ( $single_domain ) { + + $OUT .= qq(); + +} else { + + $OUT .= qq( + + + + + ); + +} + +%> + + + +
Username - -
Domain - + <%= $single_domain ? '@'.$single_domain : '' %>
Domain + +
Password
-

-
+ + +<%= + +if ( $phone_login ) { + + $OUT .= qq( + + OR

+ +
+ + + + + + + + + + + + + + +
Phone number + +
PIN + +
+
+ + ); + +} + +%> + diff --git a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi index 539877bf2..cd81aeb8d 100644 --- a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi +++ b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi @@ -9,7 +9,7 @@ use Text::Template; use HTML::Entities; use Date::Format; use Number::Format 1.50; -use FS::SelfService qw( login customer_info edit_info invoice +use FS::SelfService qw( login_info login customer_info edit_info invoice payment_info process_payment process_prepay list_pkgs order_pkg signup_info order_recharge @@ -28,7 +28,9 @@ $form_max = 255; $cgi = new CGI; unless ( defined $cgi->param('session') ) { - do_template('login',{}); + my $login_info = login_info(); + + do_template('login', $login_info ); exit; } @@ -52,10 +54,12 @@ if ( $cgi->param('session') eq 'login' ) { 'password' => $password, ); if ( $rv->{error} ) { + my $login_info = login_info(); do_template('login', { 'error' => $rv->{error}, 'username' => $username, 'domain' => $domain, + %$login_info, } ); exit; } else { @@ -81,7 +85,10 @@ die $@ if $@; if ( $result->{error} eq "Can't resume session" || $result->{error} eq "Expired session" ) { #ick - do_template('login',{}); + my $login_info = login_info(); + use Data::Dumper; + warn Dumper($login_info); + do_template('login', $login_info); exit; } @@ -620,12 +627,16 @@ sub do_template { $fill_in->{'selfurl'} = $cgi->self_url; $fill_in->{'cgi'} = \$cgi; - my $template = new Text::Template( TYPE => 'FILE', - SOURCE => "$template_dir/$name.html", + my $source = "$template_dir/$name.html"; + #warn "creating template for $source\n"; + my $template = new Text::Template( TYPE => 'FILE', + SOURCE => $source, DELIMITERS => [ '<%=', '%>' ], - UNTAINT => 1, ) + UNTAINT => 1, + ) or die $Text::Template::ERROR; + #warn "filling in $template with $fill_in\n"; print $cgi->header( '-expires' => 'now' ), $template->fill_in( PACKAGE => 'FS::SelfService::_selfservicecgi', HASH => $fill_in -- 2.11.0