From 42315f8de89e90ee0a4b08d41753dfdde35181f2 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 12 Apr 2011 19:28:35 +0400 Subject: [PATCH] config: add AUTO_ADD_USER (closes #294) --- config.php-dist | 5 +++++ functions.php | 30 ++++++++++++++++++++++++++++++ sanity_config.php | 4 ++-- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/config.php-dist b/config.php-dist index 4fea9cc0..3e4e924b 100644 --- a/config.php-dist +++ b/config.php-dist @@ -140,6 +140,11 @@ // Otherwise users will be redirected to login form with their login // information pre-filled. + define('AUTO_CREATE_USER', false); + // If users are authenticated by your web server, set this to true if + // You want new users to be automaticaly created in tt-rss database + // on first login + define('LOCK_DIRECTORY', 'lock'); // Directory for lockfiles, must be writable to the user you run // daemon process or cronjobs under. diff --git a/functions.php b/functions.php index 98158029..069c8535 100644 --- a/functions.php +++ b/functions.php @@ -1892,6 +1892,19 @@ FROM ttrss_users WHERE login = '$login'"; + if (defined('AUTO_CREATE_USER') && AUTO_CREATE_USER + && $_SERVER["REMOTE_USER"]) { + $result = db_query($link, $query); + + // First login ? + if (db_num_rows($result) == 0) { + $query = "INSERT INTO ttrss_users + (login,access_level,last_login,created) + VALUES ('$login', 0, null, NOW())"; + db_query($link, $query); + } + } + } else { $query = "SELECT id,login,access_level,pwd_hash FROM ttrss_users WHERE @@ -1909,6 +1922,23 @@ db_query($link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " . $_SESSION["uid"]); + + // LemonLDAP can send user informations via HTTP HEADER + if (defined('AUTO_CREATE_USER') && AUTO_CREATE_USER){ + // update user name + if ($_SERVER['HTTP_USER_NAME']){ + $fullname = db_escape_string($_SERVER['HTTP_USER_NAME']); + db_query($link, "UPDATE ttrss_users SET full_name = '$fullname' WHERE id = " . + $_SESSION["uid"]); + } + // update user mail + if ($_SERVER['HTTP_USER_MAIL']){ + $email = db_escape_string($_SERVER['HTTP_USER_MAIL']); + db_query($link, "UPDATE ttrss_users SET email = '$email' WHERE id = " . + $_SESSION["uid"]); + } + } + $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"]; $_SESSION["pwd_hash"] = db_fetch_result($result, 0, "pwd_hash"); diff --git a/sanity_config.php b/sanity_config.php index 24827926..974753bc 100644 --- a/sanity_config.php +++ b/sanity_config.php @@ -1,3 +1,3 @@ - +$requred_defines = array( 'DB_TYPE', 'DB_HOST', 'DB_USER', 'DB_NAME', 'DB_PASS', 'SELF_URL_PATH', 'MAGPIE_FETCH_TIME_OUT', 'MAGPIE_CACHE_DIR', 'ICONS_DIR', 'ICONS_URL', 'SINGLE_USER_MODE', 'TMP_DIRECTORY', 'ENABLE_UPDATE_DAEMON', 'DAEMON_SLEEP_INTERVAL', 'DATABASE_BACKED_SESSIONS', 'SESSION_CHECK_ADDRESS', 'SESSION_COOKIE_LIFETIME', 'SESSION_EXPIRE_TIME', 'DAEMON_UPDATE_LOGIN_LIMIT', 'CHECK_FOR_NEW_VERSION', 'DIGEST_ENABLE', 'DIGEST_EMAIL_LIMIT', 'DAEMON_SENDS_DIGESTS', 'MYSQL_CHARSET', 'DEFAULT_UPDATE_METHOD', 'SIMPLEPIE_CACHE_DIR', 'SIMPLEPIE_CACHE_IMAGES', 'COUNTERS_MAX_AGE', 'DIGEST_FROM_NAME', 'DIGEST_FROM_ADDRESS', 'DIGEST_SUBJECT', 'DIGEST_SMTP_HOST', 'DIGEST_SMTP_LOGIN', 'DIGEST_SMTP_PASSWORD', 'DAEMON_FEED_LIMIT', 'ALLOW_REMOTE_USER_AUTH', 'AUTO_LOGIN', 'AUTO_CREATE_USER', 'LOCK_DIRECTORY', 'ENABLE_GZIP_OUTPUT', 'PHP_EXECUTABLE', 'ENABLE_REGISTRATION', 'REG_NOTIFY_ADDRESS', 'REG_MAX_USERS', 'FEEDBACK_URL', 'FORCE_ARTICLE_PURGE', 'SPHINX_ENABLED', 'SPHINX_INDEX', 'ENABLE_TWEET_BUTTON', 'CONSUMER_KEY', 'CONSUMER_SECRET', 'PUBSUBHUBBUB_HUB', 'ISCONFIGURED', 'CONFIG_VERSION'); ?> -- 2.39.5