wordpress plugin, RT#75279
[freeside.git] / fs_selfservice / wordpress / process_login.php
1 <?php
2
3 $GLOBALS['FREESIDE_PROCESS_LOGIN'] = true;
4 //error_log($GLOBALS['$FREESIDE_PROCESS_LOGIN']);
5
6 require( dirname( __FILE__ ) . '/wp-blog-header.php' );
7
8 //add_action('muplugins_loaded', 'freeside_process_login');
9 //error_log("action added");
10
11 function notfreeside_process_login() {
12 error_log("FINALLY action run");
13
14 $freeside = new FreesideSelfService();
15
16 $response = $freeside->login( array( 
17   'email'    => strtolower($_POST['email']),
18   'username' => strtolower($_POST['username']),
19   'domain'   => strtolower($_POST['domain']),
20   'password' => $_POST['password'],
21 ) );
22
23 #error_log("[login] received response from freeside: $response");
24
25 $error = $response['error'];
26
27 if ( $error ) {
28
29   wp_redirect('example_login.php?username='. urlencode($username).
30                            '&domain='.   urlencode($domain).
31                            '&email='.    urlencode($email).
32                            '&freeside_error='.    urlencode($error)
33         );
34   exit;
35
36 }
37
38 // sucessful login
39
40 $session_id = $response['session_id'];
41
42 error_log("[login] logged into freeside with session_id=$session_id, setting cookie");
43
44 // now what?  for now, always redirect to the main page (or the select a
45 // customer diversion).
46 // eventually, other options?
47
48 setcookie('session_id', $session_id);
49
50 }
51
52 $response = $GLOBALS['FREESIDE_LOGIN_RESPONSE'];
53
54 if ( $response['custnum'] || $response['svcnum'] ) {
55
56   error_log('redirecting to example_selfservice.php');
57   wp_redirect("example_selfservice.php");
58   exit;
59
60 } elseif ( $response['customers'] ) {
61   error_log('sending header');
62   get_header();
63 ?>
64
65   <?php include('elements/error.php'); ?>
66
67   <FORM NAME="SelectCustomerForm" ACTION="process_select_cust.php" METHOD=POST>
68   <INPUT TYPE="hidden" NAME="action" VALUE="switch_cust">
69
70   <TABLE BGCOLOR="#c0c0c0" BORDER=0 CELLSPACING=2 CELLPADDING=0>
71
72     <TR>
73       <TH ALIGN="right">Customer </TH>
74       <TD>
75         <SELECT NAME="custnum" ID="custnum" onChange="custnum_changed()">
76           <OPTION VALUE="">Select a customer
77           <?php foreach ( $response['customers'] AS $custnum => $customer ) { ?>
78             <OPTION VALUE="<?php echo $custnum ?>"><?php echo htmlspecialchars( $customer ) ?>
79           <?php } ?>
80         </SELECT>
81       </TD>
82     </TR>
83
84     <TR>
85       <TD COLSPAN=2 ALIGN="center"><INPUT TYPE="submit" ID="submit" VALUE="Select customer" DISABLED></TD>
86     </TR>
87
88   </TABLE>
89   </FORM>
90
91   <SCRIPT TYPE="text/javascript">
92
93   function custnum_changed () {
94     var form = document.SelectCustomerForm;
95     if ( form.custnum.selectedIndex > 0 ) {
96       form.submit.disabled = false;
97     } else {
98       form.submit.disabled = true;
99     }
100   }
101
102   </SCRIPT>
103
104 <?php
105
106 // } else {
107 // 
108 //   die 'login successful, but unrecognized info (no custnum, svcnum or customers)';
109   
110 }
111
112 ?>
113
114 <?php get_footer(); ?>
115