diff options
author | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-03-07 19:12:20 +0000 |
---|---|---|
committer | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-03-07 19:12:20 +0000 |
commit | 9f5df450f0d84f2897915acaf2deedb4cbf81fd8 (patch) | |
tree | 926f336900acaf76523b9bed72a08974ff4f2b05 | |
parent | 33bb9b2098b3c2cfd79671f22e6443bd70846979 (diff) | |
download | elgg-9f5df450f0d84f2897915acaf2deedb4cbf81fd8.tar.gz elgg-9f5df450f0d84f2897915acaf2deedb4cbf81fd8.tar.bz2 |
Log in and logout
git-svn-id: https://code.elgg.org/elgg/trunk@113 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r-- | engine/lib/users.php | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/engine/lib/users.php b/engine/lib/users.php index 1a865d68e..9ea66763e 100644 --- a/engine/lib/users.php +++ b/engine/lib/users.php @@ -287,7 +287,7 @@ $where = "where (" . $where . ")";
}
- return get_data("select {$fields}, 'users' as type from {$CONFIG->dbprefix}users {$where}");
+ return get_data("select {$fields}, 'users' as type from {$CONFIG->dbprefix}users {$where}","row_to_elgguser");
}
@@ -427,6 +427,67 @@ }
/**
+ * Log in
+ *
+ * @param string $username
+ * @param string $password
+ * @param true|false $persistent
+ * @return true|false
+ */
+ function login($username, $password, $persistent = false) {
+
+ global $CONFIG;
+ $dbpassword = md5($password);
+
+ if ($users = get_users(array("username" => $username,
+ "password" => $dbpassword))) {
+ foreach($users as $user) {
+
+ $_SESSION['id'] = $user->id;
+ $_SESSION['username'] = $user->username;
+ $_SESSION['name'] = $user->name;
+
+ $code = (md5($user->name . $user->username . time() . rand()));
+ update_data("update {$CONFIG->dbprefix}users set code = '".md5($code)."' where id = {$user->id}");
+
+ //$code = md5($code); // This is a deliberate re-MD5-ing
+
+ $_SESSION['code'] = $code;
+ //if (!empty($persistent)) {
+
+ setcookie("elggperm", $code, (time()+(86400 * 30)),"/");
+
+ //}
+ // set_login_fields($user->id);
+
+ }
+
+ return true;
+ } else {
+ return false;
+ }
+
+ }
+
+ /**
+ * Log the current user out
+ *
+ * @return true|false
+ */
+ function logout() {
+ global $CONFIG;
+
+ unset($_SESSION['username']);
+ unset($_SESSION['name']);
+ unset($_SESSION['code']);
+ update_data("update {$CONFIG->dbprefix}users set code = '' where id = {$_SESSION['id']}");
+ $_SESSION['id'] = -1;
+ setcookie("elggperm", "", (time()-(86400 * 30)),"/");
+
+ return true;
+ }
+
+ /**
* Initialises the system session and potentially logs the user in
*
* This function looks for:
|