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