Commit b9633dcd authored by Dries's avatar Dries

- Patch by Bart Jansen:

  <quote>

  This adds session support for anonymous users and fixes a bug/typo.

    1. changed rid for user #0 from 0 to 1 (rid 1 == anonymous user) to make
       inner join work.

    2. replaced "if ($user .." by "if ($user->uid .." because now $user is
       always set (my previous change probably caused this).

    3. db_next_id("user_uid") -> db_next_id("users_uid");
  </quote>

  I repeat:

  "This adds session support for anonymous users and fixes a bug/typo."
parent 81591038
......@@ -472,7 +472,7 @@ INSERT INTO system VALUES ('themes/marvin/marvin.theme','marvin','theme','Intern
INSERT INTO variable(name,value) VALUES('update_start', 's:10:"2002-05-15";');
INSERT INTO variable(name,value) VALUES('theme_default','s:6:"marvin";');
INSERT INTO users(uid,name,mail) VALUES(0,'Anonymous','root@localhost');
INSERT INTO users(uid,name,mail,rid) VALUES(0,'Anonymous','root@localhost','1');
INSERT INTO blocks(module,delta,status,custom,region,weight,path) VALUES('user', 0, 1, 0, 1, 0, '');
INSERT INTO blocks(module,delta,status,custom,region,weight,path) VALUES('user', 1, 1, 0, 1, 0, '');
......
......@@ -578,7 +578,7 @@ INSERT INTO system VALUES ('modules/page.module','page','module','',1);
INSERT INTO system VALUES ('modules/story.module','story','module','',1);
INSERT INTO system VALUES ('modules/taxonomy.module','taxonomy','module','',1);
INSERT INTO system VALUES ('themes/marvin/marvin.theme','marvin','theme','Internet explorer, Netscape, Opera',1);
INSERT INTO users (uid, name, mail) VALUES ('0', 'Anonymous', 'root@localhost');
INSERT INTO users (uid, name, mail, rid) VALUES ('0', 'Anonymous', 'root@localhost', '1');
REPLACE variable SET name='update_start', value='s:10:"2003-04-19;"';
REPLACE variable SET name='theme_default', value='s:6:"marvin";';
......
......@@ -580,7 +580,7 @@ INSERT INTO system VALUES ('themes/marvin/marvin.theme','marvin','theme','Intern
INSERT INTO variable(name,value) VALUES('update_start', 's:10:"2003-04-19";');
INSERT INTO variable(name,value) VALUES('theme_default','s:6:"marvin";');
INSERT INTO users(uid,name,mail) VALUES(0,'Anonymous','root@localhost');
INSERT INTO users(uid,name,mail,rid) VALUES(0,'Anonymous','root@localhost', '1');
INSERT INTO blocks(module,delta,status) VALUES('user', '0', '1');
INSERT INTO blocks(module,delta,status) VALUES('user', '1', '1');
......
......@@ -670,7 +670,7 @@ function format_rss_channel($title, $link, $description, $items, $language = "en
$output .= " <description>". drupal_specialchars($description) ."</description>\n";
$output .= " <language>". drupal_specialchars(strip_tags($language)) ."</language>\n";
foreach ($args as $key => $value) {
$output .= "<$key>". drupal_specialchars(strip_tags($value)) ."</$key>";
$output .= " <$key>". drupal_specialchars(strip_tags($value)) ."</$key>\n";
}
$output .= $items;
$output .= "</channel>\n";
......
......@@ -37,8 +37,13 @@ function sess_read($key) {
}
function sess_write($key, $value) {
global $user;
db_query("UPDATE {sessions} SET uid = %d, hostname = '%s', session = '%s', timestamp = %d WHERE sid = '$key'", $user->uid, $_SERVER["REMOTE_ADDR"], $value, time());
db_query("UPDATE {sessions} SET hostname = '%s', session = '%s', timestamp = %d WHERE sid = '$key'", $_SERVER["REMOTE_ADDR"], $value, time());
if (!db_affected_rows()) {
db_query("INSERT INTO {sessions} (uid, sid, hostname, session, timestamp) values(%d, '%s', '%s', '%s', %d)", $user->uid, $key, $_SERVER["REMOTE_ADDR"], $value, time());
}
return '';
}
......@@ -142,7 +147,7 @@ function user_save($account, $array = array()) {
}
else {
$array["timestamp"] = time();
$array["uid"] = db_next_id("user_uid");
$array["uid"] = db_next_id("users_uid");
foreach ($array as $key => $value) {
if ($key == "pass") {
......@@ -587,7 +592,7 @@ function user_login($edit = array(), $msg = "") {
** Try to log in the user locally:
*/
if (!$user) {
if (!$user->uid) {
$name = $edit["name"];
$pass = $edit["pass"];
$user = user_load(array("name" => $name, "pass" => $pass, "status" => 1));
......@@ -607,7 +612,7 @@ function user_login($edit = array(), $msg = "") {
** When possible, determine corrosponding external auth source. Invoke source, and login user if successful:
*/
if (!$user && $server && $result = user_get_authmaps("$name@$server")) {
if (!$user->uid && $server && $result = user_get_authmaps("$name@$server")) {
if (module_invoke(key($result), "auth", $name, $pass, $server)) {
$user = user_external_load("$name@$server");
watchdog("user", "external load: $name@$server, module: ". key($result));
......@@ -621,7 +626,7 @@ function user_login($edit = array(), $msg = "") {
** Try each external authentication source in series. Register user if successful.
*/
else if (!$user && $server) {
else if (!$user->uid && $server) {
foreach (module_list() as $module) {
if (module_hook($module, "auth")) {
if (module_invoke($module, "auth", $name, $pass, $server)) {
......@@ -638,24 +643,8 @@ function user_login($edit = array(), $msg = "") {
if ($user->uid) {
watchdog("user", "session opened for '$user->name'");
/*
** Write session ID to database:
** (TODO: Currently we only save the session if a user is logged in.
** we should also add support for anonymous user sessions.)
*/
if ($user->uid) {
// update the user's session if it already exists
db_query("UPDATE {sessions} SET timestamp = '%d' WHERE sid = '%s'", time(), session_id());
// if no changes, this is a new session to be added
if (!db_affected_rows()) {
db_query("INSERT INTO {sessions} (uid, sid, hostname, timestamp) values(%d, '%s', '%s', %d)", $user->uid, session_id(), $_SERVER["REMOTE_ADDR"], time());
}
// also update the user table timestamp noting user has logged in
// update the user table timestamp noting user has logged in
db_query("UPDATE {users} SET timestamp = '%d' WHERE uid = '%s'", time(), $user->uid);
}
/*
** If the user wants to be remembered, set the proper cookie such
......
......@@ -37,8 +37,13 @@ function sess_read($key) {
}
function sess_write($key, $value) {
global $user;
db_query("UPDATE {sessions} SET uid = %d, hostname = '%s', session = '%s', timestamp = %d WHERE sid = '$key'", $user->uid, $_SERVER["REMOTE_ADDR"], $value, time());
db_query("UPDATE {sessions} SET hostname = '%s', session = '%s', timestamp = %d WHERE sid = '$key'", $_SERVER["REMOTE_ADDR"], $value, time());
if (!db_affected_rows()) {
db_query("INSERT INTO {sessions} (uid, sid, hostname, session, timestamp) values(%d, '%s', '%s', '%s', %d)", $user->uid, $key, $_SERVER["REMOTE_ADDR"], $value, time());
}
return '';
}
......@@ -142,7 +147,7 @@ function user_save($account, $array = array()) {
}
else {
$array["timestamp"] = time();
$array["uid"] = db_next_id("user_uid");
$array["uid"] = db_next_id("users_uid");
foreach ($array as $key => $value) {
if ($key == "pass") {
......@@ -587,7 +592,7 @@ function user_login($edit = array(), $msg = "") {
** Try to log in the user locally:
*/
if (!$user) {
if (!$user->uid) {
$name = $edit["name"];
$pass = $edit["pass"];
$user = user_load(array("name" => $name, "pass" => $pass, "status" => 1));
......@@ -607,7 +612,7 @@ function user_login($edit = array(), $msg = "") {
** When possible, determine corrosponding external auth source. Invoke source, and login user if successful:
*/
if (!$user && $server && $result = user_get_authmaps("$name@$server")) {
if (!$user->uid && $server && $result = user_get_authmaps("$name@$server")) {
if (module_invoke(key($result), "auth", $name, $pass, $server)) {
$user = user_external_load("$name@$server");
watchdog("user", "external load: $name@$server, module: ". key($result));
......@@ -621,7 +626,7 @@ function user_login($edit = array(), $msg = "") {
** Try each external authentication source in series. Register user if successful.
*/
else if (!$user && $server) {
else if (!$user->uid && $server) {
foreach (module_list() as $module) {
if (module_hook($module, "auth")) {
if (module_invoke($module, "auth", $name, $pass, $server)) {
......@@ -638,24 +643,8 @@ function user_login($edit = array(), $msg = "") {
if ($user->uid) {
watchdog("user", "session opened for '$user->name'");
/*
** Write session ID to database:
** (TODO: Currently we only save the session if a user is logged in.
** we should also add support for anonymous user sessions.)
*/
if ($user->uid) {
// update the user's session if it already exists
db_query("UPDATE {sessions} SET timestamp = '%d' WHERE sid = '%s'", time(), session_id());
// if no changes, this is a new session to be added
if (!db_affected_rows()) {
db_query("INSERT INTO {sessions} (uid, sid, hostname, timestamp) values(%d, '%s', '%s', %d)", $user->uid, session_id(), $_SERVER["REMOTE_ADDR"], time());
}
// also update the user table timestamp noting user has logged in
// update the user table timestamp noting user has logged in
db_query("UPDATE {users} SET timestamp = '%d' WHERE uid = '%s'", time(), $user->uid);
}
/*
** If the user wants to be remembered, set the proper cookie such
......
......@@ -44,7 +44,8 @@
"2003-08-15" => "update_60",
"2003-08-20" => "update_61",
"2003-08-27" => "update_62",
"2003-09-09" => "update_63"
"2003-09-09" => "update_63",
"2003-09-10" => "update_64"
);
function update_32() {
......@@ -388,6 +389,10 @@ function update_63() {
update_sql("INSERT INTO sequences (name, id) VALUES ('users_uid', '$users')");
}
function update_64() {
update_sql("UPDATE users SET rid = 1 WHERE uid = 0");
}
/*
** System functions
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment