summaryrefslogtreecommitdiff
path: root/shell/login.php
diff options
context:
space:
mode:
Diffstat (limited to 'shell/login.php')
-rw-r--r--shell/login.php59
1 files changed, 59 insertions, 0 deletions
diff --git a/shell/login.php b/shell/login.php
new file mode 100644
index 0000000..eff6eca
--- /dev/null
+++ b/shell/login.php
@@ -0,0 +1,59 @@
+<?php if (!isset($LTS)) { die(); }
+
+// BEGIN AUTH CODE /////////////////////////////////////////////////////////////
+global $auth_html;
+include_once('lightopenid.php');
+@session_start();
+if ( isset($_SESSION['user']) && ($_SESSION['user']!='') ) {
+ // someone is already logged in
+ if ( isset($_GET['openid_mode']) && ($_GET['openid_mode']=='logout') ) {
+ // logout
+ $auth_html.='<p>'.$_SESSION['user'].' is now logged out</p>';
+ $_SESSION['user']='';
+ } else {
+ $auth_html.='
+ <p>Currently logged in as '.$_SESSION['user'].'.</p>
+ <form action="" method="get">
+ <input type="hidden" name="openid_mode" value="logout" />
+ <input type="submit" value="Log Out" />
+ </form>
+ ';
+ }
+} else {
+ // not already logged in
+ try {
+ if(!isset($_GET['openid_mode'])) {
+ if(isset($_POST['openid_identifier'])) {
+ $openid = new LightOpenID;
+ $openid->identity = $_POST['openid_identifier'];
+ header('Location: ' . $openid->authUrl());
+ }
+ $auth_html.='
+ <form action="" method="post">
+ OpenID: <input type="text" name="openid_identifier" /> <input type="submit" value="Submit" />
+ </form>
+ ';
+ } elseif($_GET['openid_mode'] == 'cancel') {
+ $auth_html.='<p>User has canceled authentication!</p>';
+ } else {
+ $openid = new LightOpenID;
+ if ($openid->validate()) {
+ // is logged in
+ global $users;
+ include_once('passwd.php');
+ if (in_array($openid->identity,$users)) {
+ $_SESSION['user']=$openid->identity;
+ $auth_html.='<p>Welcome, '.$_SESSION['user'].'!</p>';
+ } else {
+ $auth_html.='<p>Authentication was successful, but '.$openid->identity.' is not an authorized user.</p>';
+ }
+ } else {
+ // is not logged in
+ $auth_html.='<p>User '.$openid->identity.' is not logged in </p>';
+ }
+ }
+ } catch(ErrorException $e) {
+ $auth_html.=$e->getMessage();
+ }
+}
+// END AUTH CODE ///////////////////////////////////////////////////////////////