summaryrefslogtreecommitdiff
path: root/forum/utils/login.php
diff options
context:
space:
mode:
authordeva <deva>2008-10-04 10:38:03 +0000
committerdeva <deva>2008-10-04 10:38:03 +0000
commitcce5e7710295021b41d9aaecc503a60fb99256be (patch)
tree660235be91fb821e976c7ae62347eb368ce87524 /forum/utils/login.php
Initial revision
Diffstat (limited to 'forum/utils/login.php')
-rw-r--r--forum/utils/login.php105
1 files changed, 105 insertions, 0 deletions
diff --git a/forum/utils/login.php b/forum/utils/login.php
new file mode 100644
index 0000000..50d0da2
--- /dev/null
+++ b/forum/utils/login.php
@@ -0,0 +1,105 @@
+<?php
+
+include_once($UTIL_DIR . "/users.php");
+include_once($UTIL_DIR . "/log.php");
+
+$users = new Users($DATA_DIR . "/users.xml");
+
+function checklogin()
+{
+ // The cookies...
+ global $HTTP_COOKIE_VARS;
+
+ // User vars
+ global $users;
+ global $current_user;
+ global $current_username;
+ global $current_password;
+
+ // What are we doin'?
+ global $action;
+
+ // Config vars
+ global $DATA_DIR;
+ global $ADMIN_TIMEOUT;
+
+ if($action == "login") {
+ /**
+ * Login
+ */
+
+ $current_uid = $users->getUserID($current_username);
+ $u = $users->getUser($current_uid);
+
+ if($u && $u->checkPassword($current_password) ) {
+ $current_user = $u;
+ setcookie("current_uid", $current_uid, time()+$ADMIN_TIMEOUT);
+ setcookie("current_password", $current_password, time()+$ADMIN_TIMEOUT);
+
+ _log($u->username, "logged in");
+
+ if($current_user->notified > 0) {
+ $current_user->notified = 0;
+ $users->write();
+ }
+
+ } else {
+ // Remove cookies
+ setcookie("current_uid", "", time()-1);
+ setcookie("current_password", "", time()-1);
+ }
+
+ } else if($action == "logout") {
+
+ /**
+ * Logout
+ */
+ $u = $users->getUser($HTTP_COOKIE_VARS["current_uid"]);
+
+ // Remove cookies
+ setcookie("current_uid", "", time()-1);
+ setcookie("current_password", "", time()-1);
+
+ $current_uid = "";
+ $current_password = "";
+ $current_user = false;
+
+ _log($u->username, "logged out");
+
+ } else {
+
+ /**
+ * Usage
+ */
+
+ if($HTTP_COOKIE_VARS["current_uid"] == "") return;
+
+ $u = $users->getUser($HTTP_COOKIE_VARS["current_uid"]);
+ if($u->checkPassword($HTTP_COOKIE_VARS["current_password"]) ) {
+ setcookie("current_uid", $HTTP_COOKIE_VARS["current_uid"], time()+$ADMIN_TIMEOUT);
+ setcookie("current_password", $HTTP_COOKIE_VARS["current_password"], time()+$ADMIN_TIMEOUT);
+
+ $current_user = $u;
+
+ if($current_user->notified > 0) {
+ $current_user->notified = 0;
+ $users->write();
+ }
+
+ _log($u->username, "seen");
+
+ } else {
+ // Remove cookies
+ setcookie("current_uid", "", time()-1);
+ setcookie("current_password", "", time()-1);
+
+ $current_uid = "";
+ $current_password = "";
+ $current_user = false;
+
+ }
+ }
+
+}
+
+?>