]> git.sur5r.net Git - contagged/blobdiff - login.php
Merge pull request #15 from cweiske/master
[contagged] / login.php
index f7ad08ec1d02c16886ba4aa109bfe49b7123a866..96d0c4f850bc8a35237d3aa216ed1c053ef3e7ad 100644 (file)
--- a/login.php
+++ b/login.php
@@ -1,26 +1,44 @@
-<?
-  require_once('init.php');
+<?php
+/**
+ * Do the login/logout process
+ */
 
-  $msg = $lang[msg_login];
-  if(isset($_REQUEST[username])){
-    if (do_ldap_bind($_REQUEST[username],$_REQUEST[password])){
-      //forward to next page
-      if(!empty($_SESSION[ldapab][lastlocation])){
-        header('Location: '.$_SESSION[ldapab][lastlocation]);
-      }else{
-        header('Location: index.php');
-      }
-      exit;
+require_once('inc/init.php');
+
+$msg = $lang['msg_login'];
+if(!empty($_REQUEST['username'])){
+    if (empty($_REQUEST['password'])) { $_REQUEST['password']=''; }
+    if (do_ldap_bind($_REQUEST['username'],$_REQUEST['password'])){
+
+        //create private address book if simple enough
+        if(preg_match('/ou=([^,]+)$/',$conf['privatebook'],$match)){
+            $privatedn = $conf['privatebook'].', '.$_SESSION['ldapab']['binddn'];
+            if(!@ldap_read($LDAP_CON,$privatedn,'')){
+                @ldap_add($LDAP_CON,$privatedn,
+                         array('objectClass' => array ('organizationalUnit','top'),
+                               'ou' => $match[1]));
+            }
+        }
+
+        //forward to next page
+        if(!empty($_SESSION['ldapab']['lastlocation'])){
+            header('Location: '.$_SESSION['ldapab']['lastlocation']);
+        }else{
+            header('Location: index.php');
+        }
+        exit;
     }else{
-      $msg = $lang[msg_loginfail];;
+        $msg = $lang['msg_loginfail'];;
     }
-  }
+}else{
+    //logout
+    unset($_SESSION['ldapab']);
+}
+
+//prepare templates
+tpl_std();
+$smarty->assign('msg',$msg);
+//display templates
+header('Content-Type: text/html; charset=utf-8');
+$smarty->display('login.tpl');
 
-  //prepare templates
-  tpl_std();
-  $smarty->assign('msg',$msg);
-  //display templates
-  $smarty->display('header.tpl');
-  $smarty->display('login.tpl');
-  $smarty->display('footer.tpl');
-?>