From 9f5df450f0d84f2897915acaf2deedb4cbf81fd8 Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 7 Mar 2008 19:12:20 +0000 Subject: Log in and logout git-svn-id: https://code.elgg.org/elgg/trunk@113 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/users.php | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) (limited to 'engine/lib/users.php') 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"); } @@ -426,6 +426,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 * -- cgit v1.2.3