add missing require in login.php
[plewww.git] / planetlab / common / login.php
1 <?php
2 //
3 // Login form
4 //
5 // Mark Huang <mlhuang@cs.princeton.edu>
6 // Copyright (C) 2006 The Trustees of Princeton University
7 //
8 // $Id$ $
9 //
10
11 // Get session and API handles
12 require_once 'plc_session.php';
13 require_once 'plekit-utils.php';
14 global $plc, $api;
15
16 // Print header
17 require_once 'plc_drupal.php';
18 drupal_set_title('Login');
19 include 'plc_header.php';
20
21 if (!empty($_REQUEST['email']) &&
22     !empty($_REQUEST['password'])) {
23   $plc = new PLCSession($_REQUEST['email'], $_REQUEST['password']);
24
25   if ($plc->person) {
26     // Login admins to Drupal as the superuser
27     if (in_array('admin', $plc->person['roles']) &&
28         function_exists('user_load')) {
29       global $user;
30       $user = user_load(array('uid' => 1));
31     }
32
33     if (empty($_REQUEST['url'])) {
34       // XXX Redirect to default home page
35       header("Location: /");
36       exit();
37     } else {
38       // Make sure that redirections are always local
39       $url = urldecode($_REQUEST['url']);
40       if ($url[0] != "/") {
41         $url = "/$url";
42       }
43       header("Location: $url");
44       exit();
45     }
46   } else {
47     // XXX Use our own stylesheet instead of drupal.css
48     print '<div class="messages error">Sorry. Unrecognized username or password.</div>';
49   }
50 }
51
52 $self = $_SERVER['PHP_SELF'];
53 if (!empty($_SERVER['QUERY_STRING'])) {
54   $self .= "?" . $_SERVER['QUERY_STRING'];
55 }
56
57 $url = htmlspecialchars(get_array($_REQUEST, 'url'));
58
59 // XXX Use our own stylesheet instead of drupal.css
60 print <<<EOF
61 <div class="content">
62 <form action="$self" method="post">
63
64 <table border="0" cellpadding="0" cellspacing="0">
65   <tr>
66     <td>
67       <div class="form-item">
68         <label for="edit-name">E-mail: <span class="form-required" title="This field is required.">*</span></label>
69         <input type="text" maxlength="60" name="email" id="edit-name" size="30" value="" class="form-text required" />
70       </div>
71       <div class="form-item">
72         <label for="edit-password">Password: <span class="form-required" title="This field is required.">*</span></label>
73         <input type="password" maxlength="" name="password" id="edit-password" size="30" class="form-text required" />
74       </div>
75       <input type="submit" name="op" value="Log in"  class="form-submit" />
76       <p><p><a href="/db/persons/reset_password.php">Forgot your password?</a></p>
77       <p><a href="/db/persons/register.php">Create an account</a></p>
78       <p><a href="/db/sites/register.php">File a site registration</a></p>
79       <input type="hidden" name="url" value="$url" />
80     </td>
81   </tr>
82 </table>
83
84 </form>
85 </div>
86
87 EOF;
88
89 include 'plc_footer.php';
90
91 ?>