/[drupal]/contributions/sandbox/jeremy/4.4.0/kerneltrap/remember_me.patch
ViewVC logotype

Contents of /contributions/sandbox/jeremy/4.4.0/kerneltrap/remember_me.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Tue Mar 30 04:30:04 2004 UTC (5 years, 7 months ago) by jeremy
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-patch
Derived from the patch found here:
  http://drupal.org/node/view/2974
(Just resynched to apply cleanly, no functional changes)

Restores "remember me" functionality.
1 --- includes/session.inc.orig 2004-03-29 23:19:51.156184925 -0500
2 +++ includes/session.inc 2004-03-29 23:20:05.559649226 -0500
3 @@ -15,18 +15,29 @@ function sess_close() {
4 }
5
6 function sess_read($key) {
7 - global $user;
8 -
9 - $result = db_query_range("SELECT u.*, s.*, r.name AS role FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid LEFT JOIN {role} r ON u.rid = r.rid WHERE s.sid = '%s' AND u.status < 3", $key, 0, 1);
10
11 - if (!db_num_rows($result)) {
12 - $result = db_query("SELECT u.*, r.name AS role FROM {users} u INNER JOIN {role} r ON u.rid = r.rid WHERE u.uid = 0");
13 - db_query("INSERT INTO {sessions} (uid, sid, hostname, timestamp) values(%d, '%s', '%s', %d)", $user->uid, $key, $_SERVER["REMOTE_ADDR"], time());
14 + if ($_COOKIE['remember_me']) {
15 + $sids[] = $_COOKIE['remember_me'];
16 + }
17 + $sids[] = $key;
18 +
19 + foreach ($sids as $sid) {
20 + $result = db_query_range("SELECT u.*, s.*, r.name AS role FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid LEFT JOIN {role} r ON u.rid = r.rid WHERE s.sid = '%s' AND u.status < 3", $sid, 0, 1);
21 + if (db_num_rows($result)) {
22 + return sess_construct_user($result);
23 + }
24 }
25 +
26 + $result = db_query("SELECT u.*, r.name AS role FROM {users} u INNER JOIN {role} r ON u.rid = r.rid WHERE u.uid = 0");
27 + db_query("INSERT INTO {sessions} (uid, sid, hostname, timestamp) values(%d, '%s', '%s', %d)", $user->uid, $key, $_SERVER["REMOTE_ADDR"], time());
28 + return sess_construct_user($result);
29 +}
30
31 +function sess_construct_user($result) {
32 + global $user;
33 +
34 $user = db_fetch_object($result);
35 $user = drupal_unpack($user);
36 -
37 return !empty($user->session) ? $user->session : '';
38 }
39
40 --- modules/user.module.orig 2004-03-29 23:19:41.293236520 -0500
41 +++ modules/user.module 2004-03-29 23:20:05.560649119 -0500
42 @@ -348,6 +348,14 @@ function user_block($op = "list", $delta
43 $output .= form_hidden("destination", $edit["destination"]);
44 $output .= form_textfield(t("Username"), 'name', $edit['name'], 15, 64);
45 $output .= form_password(t("Password"), 'pass', $pass, 15, 64);
46 +
47 + if (variable_get("user_remember", 0) == 0) {
48 + $output .= form_checkbox(t("Remember me"), "remember_me");
49 + }
50 + elseif (variable_get("user_remember", 1) == 1) {
51 + $output .= form_hidden("remember_me", 1);
52 + }
53 +
54 $output .= form_submit(t("Log in"));
55 $output .= "</div>\n";
56
57 @@ -605,7 +613,9 @@ function user_login($edit = array(), $ms
58 */
59
60 $path = preg_replace("/.+\/\/[^\/]+(.*)/", "\$1/", $base_url);
61 - setcookie(session_name(), session_id(), FALSE, $path);
62 + if ($edit["remember_me"]) {
63 + setcookie('remember_me', session_id(), time() + 3600 * 24 * 365, $path);
64 + }
65
66 /*
67 ** Redirect the user to the page he logged on from.
68 @@ -658,6 +668,7 @@ function user_login($edit = array(), $ms
69 $output .= form_textfield(t("Username"), 'name', $edit['name'], 30, 64, t("Enter your %s username.", array("%s" => variable_get("site_name", "local"))));
70 }
71 $output .= form_password(t("Password"), 'pass', $pass, 30, 64, t("Enter the password that accompanies your username."));
72 + $output .= form_checkbox(t("Remember me"), "remember_me");
73 $output .= form_submit(t("Log in"));
74 $items[] = l(t("Request new password"), "user/password");
75 if (variable_get("user_register", 1)) {
76 @@ -675,16 +686,18 @@ function _user_authenticated_id() {
77 }
78
79 function user_logout() {
80 - global $user;
81 + global $user, $base_url;
82
83 if ($user->uid) {
84 watchdog('user', "session closed for '$user->name'");
85
86 - /*
87 - ** Destroy the current session:
88 - */
89 -
90 + // destroy the current session
91 session_destroy();
92 +
93 + //expire the 'remember me' cookie
94 + $path = preg_replace("/.+\/\/[^\/]+(.*)/", "\$1/", $base_url);
95 + setcookie('remember_me', '', time()-999, $path);
96 +
97 module_invoke_all('user', "logout", NULL, $user);
98 unset($user);
99 }
100 @@ -1112,6 +1125,7 @@ function _user_mail_text($messageid, $va
101 function user_settings() {
102 // user registration settings
103 $group = form_radios(t("Public registrations"), "user_register", variable_get("user_register", 1), array(t("Only site administrators can create new user accounts."), t("Visitors can create accounts and no administrator approval is required."), t("Visitors can create accounts but administrator approval is required.")));
104 + $group .= form_radios(t("Remember authenticated users"), "user_remember", variable_get("user_remember", 0), array(t("Let the user decide whether he should be logged out when leaving the site."), t("Authenticated users are not logged out upon leaving the site."), t("Authenticated users are logged out upon leaving the site.")));
105 $group .= form_textarea(t("User registration guidelines"), "user_registration_help", variable_get("user_registration_help", ""), 70, 4, t("This text is displayed at the top of the user registration form. It's useful for helping or instructing your users."));
106 $output = form_group(t("User registration settings"), $group);
107

  ViewVC Help
Powered by ViewVC 1.1.2