4 # $Id: signup.cgi,v 1.3 2006-08-29 17:50:06 lawrence Exp $
7 use vars qw( @payby $cgi $init_data
8 $self_url $error $agentnum
10 $ieak_file $ieak_template
11 $signup_html $signup_template
12 $success_html $success_template
13 $decline_html $decline_template
16 use subs qw( print_form print_okay print_decline
17 success_default decline_default
20 #use CGI::Carp qw(fatalsToBrowser);
22 use Business::CreditCard;
23 use HTTP::BrowserDetect;
24 use FS::SelfService qw( signup_info new_customer );
26 #acceptable payment methods
28 #@payby = qw( CARD BILL COMP );
29 #@payby = qw( CARD BILL );
31 @payby = qw( CARD PREPAY );
33 $ieak_file = '/usr/local/freeside/ieak.template';
34 $signup_html = -e 'signup.html'
36 : '/usr/local/freeside/signup.html';
37 $success_html = -e 'success.html'
39 : '/usr/local/freeside/success.html';
40 $decline_html = -e 'decline.html'
42 : '/usr/local/freeside/decline.html';
45 if ( -e $ieak_file ) {
46 my $ieak_txt = Text::Template::_load_text($ieak_file)
47 or die $Text::Template::ERROR;
48 $ieak_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
50 $ieak_txt =~ s/\r//g; # don't double \r on old templates
51 $ieak_txt =~ s/\n/\r\n/g;
52 $ieak_template = new Text::Template ( TYPE => 'STRING', SOURCE => $ieak_txt )
53 or die $Text::Template::ERROR;
59 if ( -e $signup_html ) {
60 my $signup_txt = Text::Template::_load_text($signup_html)
61 or die $Text::Template::ERROR;
62 $signup_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
64 $signup_template = new Text::Template ( TYPE => 'STRING',
65 SOURCE => $signup_txt,
66 DELIMITERS => [ '<%=', '%>' ]
68 or die $Text::Template::ERROR;
70 /<\s*INPUT TYPE="?hidden"?\s+NAME="?agentnum"?\s+VALUE="?(\d+)"?\s*>/si
75 #too much maintenance hassle to keep in this file
76 die "can't find ./signup.html or /usr/local/freeside/signup.html";
77 #$signup_template = new Text::Template ( TYPE => 'STRING',
78 # SOURCE => &signup_default,
79 # DELIMITERS => [ '<%=', '%>' ]
81 # or die $Text::Template::ERROR;
84 if ( -e $success_html ) {
85 my $success_txt = Text::Template::_load_text($success_html)
86 or die $Text::Template::ERROR;
87 $success_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
89 $success_template = new Text::Template ( TYPE => 'STRING',
90 SOURCE => $success_txt,
91 DELIMITERS => [ '<%=', '%>' ],
93 or die $Text::Template::ERROR;
95 $success_template = new Text::Template ( TYPE => 'STRING',
96 SOURCE => &success_default,
97 DELIMITERS => [ '<%=', '%>' ],
99 or die $Text::Template::ERROR;
102 if ( -e $decline_html ) {
103 my $decline_txt = Text::Template::_load_text($decline_html)
104 or die $Text::Template::ERROR;
105 $decline_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
107 $decline_template = new Text::Template ( TYPE => 'STRING',
108 SOURCE => $decline_txt,
109 DELIMITERS => [ '<%=', '%>' ],
111 or die $Text::Template::ERROR;
113 $decline_template = new Text::Template ( TYPE => 'STRING',
114 SOURCE => &decline_default,
115 DELIMITERS => [ '<%=', '%>' ],
117 or die $Text::Template::ERROR;
122 $init_data = signup_info( 'agentnum' => $agentnum,
123 'promo_code' => scalar($cgi->param('promo_code')),
124 'reg_code' => uc(scalar($cgi->param('reg_code'))),
127 if ( ( defined($cgi->param('magic')) && $cgi->param('magic') eq 'process' )
128 || ( defined($cgi->param('action')) && $cgi->param('action') eq 'process_signup' )
133 $cgi->param('agentnum', $agentnum) if $agentnum;
134 $cgi->param('reg_code', uc(scalar($cgi->param('reg_code'))) );
136 #false laziness w/agent.cgi, identical except for agentnum
137 my $payby = $cgi->param('payby');
138 if ( $payby eq 'CHEK' || $payby eq 'DCHK' ) {
139 #$payinfo = join('@', map { $cgi->param( $payby. "_payinfo$_" ) } (1,2) );
140 $cgi->param('payinfo' => $cgi->param($payby. '_payinfo1'). '@'.
141 $cgi->param($payby. '_payinfo2')
144 $cgi->param('payinfo' => $cgi->param( $payby. '_payinfo' ) );
146 $cgi->param('paydate' => $cgi->param( $payby. '_month' ). '-'.
147 $cgi->param( $payby. '_year' )
149 $cgi->param('payname' => $cgi->param( $payby. '_payname' ) );
150 $cgi->param('paycvv' => defined $cgi->param( $payby. '_paycvv' )
151 ? $cgi->param( $payby. '_paycvv' )
155 if ( $cgi->param('invoicing_list') ) {
156 $cgi->param('invoicing_list' => $cgi->param('invoicing_list'). ', POST')
157 if $cgi->param('invoicing_list_POST');
159 $cgi->param('invoicing_list' => 'POST' );
162 if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
163 $error = $init_data->{msgcat}{passwords_dont_match}; #msgcat
164 $cgi->param('_password', '');
165 $cgi->param('_password2', '');
168 if ( $payby =~ /^(CARD|DCRD)$/ && $cgi->param('CARD_type') ) {
169 my $payinfo = $cgi->param('payinfo');
172 $payinfo =~ /^(\d{13,16})$/
173 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
176 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
177 cardtype($payinfo) eq $cgi->param('CARD_type')
178 or $error ||= $init_data->{msgcat}{not_a}. $cgi->param('CARD_type');
181 if ($init_data->{emailinvoiceonly} && (length $cgi->param('invoicing_list') < 1)) {
182 $error ||= $init_data->{msgcat}{illegal_or_empty_text};
186 my $rv = new_customer( {
187 map { $_ => scalar($cgi->param($_)) }
188 qw( last first ss company
189 address1 address2 city county state zip country
192 ship_last ship_first ship_company
193 ship_address1 ship_address2 ship_city ship_county ship_state
194 ship_zip ship_country
195 ship_daytime ship_night ship_fax
197 payby payinfo paycvv paydate payname invoicing_list
198 referral_custnum promo_code reg_code
199 pkgpart username sec_phrase _password popnum refnum
202 grep { /^snarf_/ } $cgi->param
204 $error = $rv->{'error'};
208 if ( $error eq '_decline' ) {
211 #fudge the snarf info
213 ${$_} = $cgi->param($_) foreach grep { /^snarf_/ } $cgi->param;
217 'pkgpart' => scalar($cgi->param('pkgpart')),
228 $error = "Error: $error" if $error;
236 $r->{referral_custnum} = $r->{'ref'};
237 #$cgi->delete('ref');
238 #$cgi->delete('init_popstate');
239 $r->{self_url} = $cgi->self_url;
241 print $cgi->header( '-expires' => 'now' ),
242 $signup_template->fill_in( PACKAGE => 'FS::SelfService::_signupcgi',
248 print $cgi->header( '-expires' => 'now' ),
249 $decline_template->fill_in();
254 my $user_agent = new HTTP::BrowserDetect $ENV{HTTP_USER_AGENT};
256 $cgi->param('username') =~ /^(.+)$/
257 or die "fatal: invalid username got past FS::SelfService::new_customer";
259 $cgi->param('_password') =~ /^(.+)$/
260 or die "fatal: invalid password got past FS::SelfService::new_customer";
262 ( $cgi->param('first'). ' '. $cgi->param('last') ) =~ /^(.*)$/
263 or die "fatal: invalid email_name got past FS::SelfService::new_customer";
264 my $email_name = $1; #global for template
268 foreach ( @{ $init_data->{'svc_acct_pop'} } ) {
269 #push @{ $pop{ $_->{state} }->{ $_->{ac} } }, $_;
270 $popnum2pop{$_->{popnum}} = $_;
273 my( $ac, $exch, $loc);
274 my $pop = $popnum2pop{$cgi->param('popnum')};
275 #or die "fatal: invalid popnum got past FS::SelfService::new_customer";
277 ( $ac, $exch, $loc ) = ( $pop->{'ac'}, $pop->{'exch'}, $pop->{'loc'} );
279 ( $ac, $exch, $loc ) = ( '', '', ''); #presumably you're not using them.
283 my $pkg = ( grep { $_->{'pkgpart'} eq $param{'pkgpart'} }
284 @{ $init_data->{'part_pkg'} }
287 if ( $ieak_template && $user_agent->windows && $user_agent->ie ) {
289 print $cgi->header('application/x-Internet-signup'),
290 $ieak_template->fill_in();
291 } else { #send a simple confirmation
292 print $cgi->header( '-expires' => 'now' ),
293 $success_template->fill_in( HASH => {
294 username => $username,
295 password => $password,
296 _password => $password,
297 email_name => $email_name,
306 sub success_default { #html to use if you don't specify a success file
308 <HTML><HEAD><TITLE>Signup successful</TITLE></HEAD>
309 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Signup successful</FONT><BR><BR>
310 Thanks for signing up!
312 Signup information for <%= $email_name %>:
314 Username: <%= $username %><BR>
315 Password: <%= $password %><BR>
316 Access number: (<%= $ac %>) / <%= $exch %> - <%= $local %><BR>
317 Package: <%= $pkg %><BR>
322 sub decline_default { #html to use if there is a decline
324 <HTML><HEAD><TITLE>Processing error</TITLE></HEAD>
325 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Processing error</FONT><BR><BR>
326 There has been an error processing your account. Please contact customer
332 # subs for the templates...
334 package FS::SelfService::_signupcgi;
336 use FS::SelfService qw(regionselector expselect popselector);