|
|
@@ -7,10 +7,32 @@ if ($_SERVER['REQUEST_METHOD'] != 'POST') {
|
|
|
exit();
|
|
|
}
|
|
|
|
|
|
-if (!isset($_POST['login'], $_POST['password'])) {
|
|
|
+if (!isset($_POST['id'], $_POST['password'])) {
|
|
|
header('Location: signin.php');
|
|
|
exit();
|
|
|
}
|
|
|
|
|
|
-$login = htmlspecialchars($_POST['login']);
|
|
|
-$passwd = htmlspecialchars($_POST['password']);
|
|
|
+$id = htmlspecialchars($_POST['id']);
|
|
|
+
|
|
|
+$ini = parse_ini_file('includes/config.ini');
|
|
|
+
|
|
|
+try {
|
|
|
+ $ldapconn = ldap_connect($ini['hostname'], $ini['port']);
|
|
|
+ ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
|
|
|
+ ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
|
|
|
+} catch (Exception $e) {
|
|
|
+ die ('ERROR: ' . $e->getMessage());
|
|
|
+}
|
|
|
+
|
|
|
+if ($ldapconn) {
|
|
|
+ $ldapbind = ldap_bind($ldapconn, "uid=" . ldap_escape($id) . ',' . $ini["binddn"], $_POST['password']);
|
|
|
+ if ($ldapbind) {
|
|
|
+ $_SESSION['user'] = $id;
|
|
|
+ header('Location: home.php');
|
|
|
+ exit();
|
|
|
+ } else {
|
|
|
+ $_SESSION['message'] = "Wrong username or password";
|
|
|
+ header('Location: signin.php');
|
|
|
+ exit();
|
|
|
+ }
|
|
|
+}
|