2010-07-15 16:09:22 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ownCloud
|
|
|
|
*
|
|
|
|
* @author Frank Karlitschek
|
|
|
|
* @copyright 2010 Frank Karlitschek karlitschek@kde.org
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
|
|
|
*
|
2011-02-09 17:50:27 +03:00
|
|
|
* You should have received a copy of the GNU Affero General Public
|
2010-07-15 16:09:22 +04:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-07-21 19:53:51 +04:00
|
|
|
oc_require_once('inc/User/backend.php');
|
2010-07-19 23:33:29 +04:00
|
|
|
|
2010-07-15 16:09:22 +04:00
|
|
|
|
2010-07-15 21:56:13 +04:00
|
|
|
|
2010-07-15 16:09:22 +04:00
|
|
|
/**
|
2010-07-21 19:53:51 +04:00
|
|
|
* Class for user management in a SQL Database (e.g. MySQL, SQLite)
|
2010-07-15 22:57:14 +04:00
|
|
|
*
|
2010-07-15 16:09:22 +04:00
|
|
|
*/
|
2010-07-21 19:53:51 +04:00
|
|
|
class OC_USER_DATABASE extends OC_USER_BACKEND {
|
2010-09-12 19:04:52 +04:00
|
|
|
static private $userGroupCache=array();
|
|
|
|
|
2010-07-15 16:09:22 +04:00
|
|
|
/**
|
2010-07-23 01:42:18 +04:00
|
|
|
* Check if the login button is pressed and log the user in
|
|
|
|
*
|
|
|
|
*/
|
2011-01-01 03:01:57 +03:00
|
|
|
public static function loginListener(){
|
2010-07-23 01:42:18 +04:00
|
|
|
if ( isset($_POST['loginbutton']) AND isset($_POST['password']) AND isset($_POST['login']) ) {
|
|
|
|
if ( OC_USER::login($_POST['login'], $_POST['password']) ) {
|
2010-07-15 16:09:22 +04:00
|
|
|
echo 1;
|
2010-07-23 01:42:18 +04:00
|
|
|
OC_LOG::event($_SESSION['username'], 1, '');
|
2010-07-15 16:09:22 +04:00
|
|
|
echo 2;
|
2010-07-23 01:42:18 +04:00
|
|
|
if ( (isset($CONFIG_HTTPFORCESSL) AND $CONFIG_HTTPFORCESSL)
|
|
|
|
OR (isset($_SERVER['HTTPS']) AND ('on' == $_SERVER['HTTPS'])) ) {
|
|
|
|
$url = 'https://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
|
|
|
|
} else {
|
|
|
|
$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
|
2010-07-15 16:09:22 +04:00
|
|
|
}
|
2010-07-21 19:53:51 +04:00
|
|
|
header("Location: $url");
|
2010-07-15 16:09:22 +04:00
|
|
|
die();
|
2010-07-23 01:42:18 +04:00
|
|
|
} else {
|
2010-07-21 19:53:51 +04:00
|
|
|
return('error');
|
2010-07-23 01:42:18 +04:00
|
|
|
}
|
2010-07-15 16:09:22 +04:00
|
|
|
}
|
|
|
|
return('');
|
|
|
|
}
|
2010-07-19 20:52:49 +04:00
|
|
|
|
2010-07-15 16:09:22 +04:00
|
|
|
/**
|
2010-07-23 01:42:18 +04:00
|
|
|
* Try to create a new user
|
|
|
|
*
|
|
|
|
* @param string $username The username of the user to create
|
|
|
|
* @param string $password The password of the new user
|
|
|
|
*/
|
|
|
|
public static function createUser($username, $password) {
|
2010-09-20 22:27:43 +04:00
|
|
|
self::clearCache();
|
2010-07-15 16:09:22 +04:00
|
|
|
global $CONFIG_DBTABLEPREFIX;
|
2010-07-23 01:42:18 +04:00
|
|
|
// Check if the user already exists
|
|
|
|
if ( 0 != OC_USER::getUserId($username, true) ) {
|
2010-07-15 16:09:22 +04:00
|
|
|
return false;
|
2010-07-23 01:42:18 +04:00
|
|
|
} else {
|
|
|
|
$usernameClean = strToLower($username);
|
|
|
|
$password = sha1($password);
|
|
|
|
$username = OC_DB::escape($username);
|
|
|
|
$usernameClean = OC_DB::escape($usernameClean);
|
|
|
|
$query = "INSERT INTO `{$CONFIG_DBTABLEPREFIX}users` (`user_name` ,`user_name_clean` ,`user_password`) "
|
|
|
|
. "VALUES ('$username', '$usernameClean', '$password')";
|
|
|
|
$result = OC_DB::query($query);
|
|
|
|
return $result ? true : false;
|
2010-07-15 21:56:13 +04:00
|
|
|
}
|
2010-07-21 19:53:51 +04:00
|
|
|
}
|
2010-07-23 01:42:18 +04:00
|
|
|
|
2010-07-15 16:09:22 +04:00
|
|
|
/**
|
2010-07-23 01:42:18 +04:00
|
|
|
* Try to login a user
|
|
|
|
*
|
|
|
|
* @param string $username The username of the user to log in
|
|
|
|
* @param string $password The password of the user
|
|
|
|
*/
|
2010-07-21 19:53:51 +04:00
|
|
|
public static function login($username,$password){
|
2010-07-15 16:09:22 +04:00
|
|
|
global $CONFIG_DBTABLEPREFIX;
|
|
|
|
|
2010-07-23 01:42:18 +04:00
|
|
|
$password = sha1($password);
|
|
|
|
$usernameClean = strtolower($username);
|
|
|
|
$username = OC_DB::escape($username);
|
|
|
|
$usernameClean = OC_DB::escape($usernameClean);
|
|
|
|
$query = "SELECT user_id FROM {$CONFIG_DBTABLEPREFIX}users "
|
|
|
|
. "WHERE user_name_clean = '$usernameClean' AND user_password = '$password' LIMIT 1";
|
|
|
|
$result = OC_DB::select($query);
|
|
|
|
if ( isset($result[0]) AND isset($result[0]['user_id']) ) {
|
|
|
|
$_SESSION['user_id'] = $result[0]['user_id'];
|
|
|
|
$_SESSION['username'] = $username;
|
|
|
|
$_SESSION['username_clean'] = $usernameClean;
|
2010-07-15 16:09:22 +04:00
|
|
|
return true;
|
2010-07-23 01:42:18 +04:00
|
|
|
} else {
|
2010-07-15 16:09:22 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-07-23 01:42:18 +04:00
|
|
|
|
2010-07-15 16:09:22 +04:00
|
|
|
/**
|
2010-07-23 01:42:18 +04:00
|
|
|
* Check if the logout button is pressed and logout the user
|
|
|
|
*
|
|
|
|
*/
|
2011-01-01 03:01:57 +03:00
|
|
|
public static function logoutListener() {
|
2010-11-04 21:42:51 +03:00
|
|
|
global $WEBROOT;
|
2010-07-23 01:42:18 +04:00
|
|
|
if ( isset($_GET['logoutbutton']) AND isset($_SESSION['username']) ) {
|
|
|
|
OC_LOG::event($_SESSION['username'], 2, '');
|
|
|
|
$_SESSION['user_id'] = false;
|
|
|
|
$_SESSION['username'] = '';
|
|
|
|
$_SESSION['username_clean'] = '';
|
2010-11-04 21:42:51 +03:00
|
|
|
|
|
|
|
header("location: $WEBROOT");
|
2010-07-15 16:09:22 +04:00
|
|
|
}
|
|
|
|
}
|
2010-07-23 01:42:18 +04:00
|
|
|
|
2010-07-15 16:09:22 +04:00
|
|
|
/**
|
2010-07-23 01:42:18 +04:00
|
|
|
* Check if the user is logged in
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function isLoggedIn() {
|
|
|
|
if ( isset($_SESSION['user_id']) AND $_SESSION['user_id'] ) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2010-07-15 16:09:22 +04:00
|
|
|
}
|
2010-07-23 01:42:18 +04:00
|
|
|
|
2010-07-15 16:09:22 +04:00
|
|
|
/**
|
2010-07-23 01:42:18 +04:00
|
|
|
* Try to create a new group
|
|
|
|
*
|
|
|
|
* @param string $groupName The name of the group to create
|
|
|
|
*/
|
|
|
|
public static function createGroup($groupName) {
|
2010-09-20 22:27:43 +04:00
|
|
|
self::clearCache();
|
2010-07-15 16:09:22 +04:00
|
|
|
global $CONFIG_DBTABLEPREFIX;
|
2010-09-20 22:27:43 +04:00
|
|
|
if (0 == OC_USER::getGroupId($groupName) ) {
|
2010-07-23 01:42:18 +04:00
|
|
|
$groupName = OC_DB::escape($groupName);
|
|
|
|
$query = "INSERT INTO `{$CONFIG_DBTABLEPREFIX}groups` (`group_name`) VALUES ('$groupName')";
|
|
|
|
$result = OC_DB::query($query);
|
|
|
|
return $result ? true : false;
|
|
|
|
} else {
|
2010-07-15 16:09:22 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-07-23 01:42:18 +04:00
|
|
|
|
2010-07-15 16:09:22 +04:00
|
|
|
/**
|
2010-07-23 01:42:18 +04:00
|
|
|
* Get the ID of a user
|
|
|
|
*
|
|
|
|
* @param string $username Name of the user to find the ID
|
|
|
|
* @param boolean $noCache If false the cache is used to find the ID
|
|
|
|
*/
|
|
|
|
public static function getUserId($username, $noCache=false) {
|
2010-07-15 16:09:22 +04:00
|
|
|
global $CONFIG_DBTABLEPREFIX;
|
2010-07-23 01:42:18 +04:00
|
|
|
|
|
|
|
$usernameClean = strToLower($username);
|
|
|
|
// Try to use cached value to avoid an SQL query
|
|
|
|
if ( !$noCache AND isset($_SESSION['user_id_cache'][$usernameClean]) ) {
|
|
|
|
return $_SESSION['user_id_cache'][$usernameClean];
|
2010-07-15 16:09:22 +04:00
|
|
|
}
|
2010-07-23 01:42:18 +04:00
|
|
|
$usernameClean = OC_DB::escape($usernameClean);
|
|
|
|
$query = "SELECT user_id FROM {$CONFIG_DBTABLEPREFIX}users WHERE user_name_clean = '$usernameClean'";
|
|
|
|
$result = OC_DB::select($query);
|
|
|
|
if ( !is_array($result) ) {
|
2010-07-15 16:09:22 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2010-07-23 01:42:18 +04:00
|
|
|
if ( isset($result[0]) AND isset($result[0]['user_id']) ) {
|
|
|
|
$_SESSION['user_id_cache'][$usernameClean] = $result[0]['user_id'];
|
2010-07-15 16:09:22 +04:00
|
|
|
return $result[0]['user_id'];
|
2010-07-23 01:42:18 +04:00
|
|
|
} else {
|
2010-07-15 16:09:22 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2010-07-23 01:42:18 +04:00
|
|
|
|
2010-07-15 16:09:22 +04:00
|
|
|
/**
|
2010-07-23 01:42:18 +04:00
|
|
|
* Get the ID of a group
|
|
|
|
*
|
|
|
|
* @param string $groupName Name of the group to find the ID
|
|
|
|
* @param boolean $noCache If false the cache is used to find the ID
|
|
|
|
*/
|
|
|
|
public static function getGroupId($groupName, $noCache=false) {
|
2010-07-15 16:09:22 +04:00
|
|
|
global $CONFIG_DBTABLEPREFIX;
|
2010-07-23 01:42:18 +04:00
|
|
|
|
|
|
|
// Try to use cached value to avoid an SQL query
|
|
|
|
if ( !$noCache AND isset($_SESSION['group_id_cache'][$groupName]) ) {
|
|
|
|
return $_SESSION['group_id_cache'][$groupName];
|
2010-07-15 16:09:22 +04:00
|
|
|
}
|
2010-07-23 01:42:18 +04:00
|
|
|
$groupName = OC_DB::escape($groupName);
|
|
|
|
$query = "SELECT group_id FROM {$CONFIG_DBTABLEPREFIX}groups WHERE group_name = '$groupName'";
|
|
|
|
$result = OC_DB::select($query);
|
|
|
|
if ( !is_array($result) ) {
|
2010-07-15 16:09:22 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2010-07-23 01:42:18 +04:00
|
|
|
if ( isset($result[0]) AND isset($result[0]['group_id']) ){
|
|
|
|
$_SESSION['group_id_cache'][$groupName] = $result[0]['group_id'];
|
2010-07-15 16:09:22 +04:00
|
|
|
return $result[0]['group_id'];
|
2010-07-23 01:42:18 +04:00
|
|
|
} else {
|
2010-07-15 16:09:22 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2010-07-23 01:42:18 +04:00
|
|
|
|
2010-07-15 16:09:22 +04:00
|
|
|
/**
|
2010-07-23 01:42:18 +04:00
|
|
|
* Get the name of a group
|
|
|
|
*
|
|
|
|
* @param string $groupId ID of the group
|
|
|
|
* @param boolean $noCache If false the cache is used to find the name of the group
|
|
|
|
*/
|
|
|
|
public static function getGroupName($groupId, $noCache=false) {
|
2010-07-15 16:09:22 +04:00
|
|
|
global $CONFIG_DBTABLEPREFIX;
|
2010-07-23 01:42:18 +04:00
|
|
|
|
|
|
|
// Try to use cached value to avoid an sql query
|
|
|
|
if ( !$noCache AND ($name = array_search($groupId, $_SESSION['group_id_cache'])) ) {
|
2010-07-15 16:09:22 +04:00
|
|
|
return $name;
|
|
|
|
}
|
2010-07-23 01:42:18 +04:00
|
|
|
$groupId = (integer)$groupId;
|
|
|
|
$query = "SELECT group_name FROM {$CONFIG_DBTABLEPREFIX}groups WHERE group_id = '$groupId' LIMIT 1";
|
|
|
|
$result = OC_DB::select($query);
|
|
|
|
if ( isset($result[0]) AND isset($result[0]['group_name']) ) {
|
2010-07-15 16:09:22 +04:00
|
|
|
return $result[0]['group_name'];
|
2010-07-23 01:42:18 +04:00
|
|
|
} else {
|
2010-07-15 16:09:22 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2010-07-23 01:42:18 +04:00
|
|
|
|
2010-07-15 16:09:22 +04:00
|
|
|
/**
|
2010-07-23 01:42:18 +04:00
|
|
|
* Check if a user belongs to a group
|
|
|
|
*
|
|
|
|
* @param string $username Name of the user to check
|
|
|
|
* @param string $groupName Name of the group
|
|
|
|
*/
|
|
|
|
public static function inGroup($username,$groupName) {
|
2010-07-15 16:09:22 +04:00
|
|
|
global $CONFIG_DBTABLEPREFIX;
|
2010-09-12 19:04:52 +04:00
|
|
|
$userId = OC_USER::getUserId($username);
|
|
|
|
$groupId = OC_USER::getGroupId($groupName);
|
|
|
|
self::getUserGroups($username);
|
|
|
|
$groups=self::$userGroupCache[$userId];
|
|
|
|
return (array_search($groupId,$groups)!==false);
|
2010-07-15 16:09:22 +04:00
|
|
|
}
|
2010-07-23 01:42:18 +04:00
|
|
|
|
2010-07-15 16:09:22 +04:00
|
|
|
/**
|
2010-07-23 01:42:18 +04:00
|
|
|
* Add a user to a group
|
|
|
|
*
|
|
|
|
* @param string $username Name of the user to add to group
|
|
|
|
* @param string $groupName Name of the group in which add the user
|
|
|
|
*/
|
|
|
|
public static function addToGroup($username, $groupName) {
|
2010-07-15 16:09:22 +04:00
|
|
|
global $CONFIG_DBTABLEPREFIX;
|
2010-09-20 22:27:43 +04:00
|
|
|
self::clearCache();
|
2010-07-23 01:42:18 +04:00
|
|
|
if ( !OC_USER::inGroup($username, $groupName) ) {
|
2010-09-20 22:27:43 +04:00
|
|
|
$userId = OC_USER::getUserId($username,true);
|
|
|
|
$groupId = OC_USER::getGroupId($groupName,true);
|
2010-07-23 01:42:18 +04:00
|
|
|
if ( (0 != $groupId) AND (0 != $userId) ) {
|
|
|
|
$query = "INSERT INTO `{$CONFIG_DBTABLEPREFIX}user_group` (`user_id` ,`group_id`) VALUES ('$userId', '$groupId');";
|
|
|
|
$result = OC_DB::query($query);
|
|
|
|
if ( $result ) {
|
2010-09-20 22:27:43 +04:00
|
|
|
self::clearCache();
|
2010-07-15 16:09:22 +04:00
|
|
|
return true;
|
2010-07-23 01:42:18 +04:00
|
|
|
} else {
|
2010-07-15 16:09:22 +04:00
|
|
|
return false;
|
|
|
|
}
|
2010-07-23 01:42:18 +04:00
|
|
|
} else {
|
2010-07-15 16:09:22 +04:00
|
|
|
return false;
|
|
|
|
}
|
2010-07-23 01:42:18 +04:00
|
|
|
} else {
|
2010-07-15 16:09:22 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2010-09-20 22:27:43 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a user from a group
|
|
|
|
*
|
|
|
|
* @param string $username Name of the user to remove from group
|
|
|
|
* @param string $groupName Name of the group from which remove the user
|
|
|
|
*/
|
|
|
|
public static function removeFromGroup($username,$groupName){
|
|
|
|
global $CONFIG_DBTABLEPREFIX;
|
|
|
|
self::clearCache();
|
|
|
|
if (OC_USER::inGroup($username, $groupName) ) {
|
|
|
|
$userId = OC_USER::getUserId($username,true);
|
|
|
|
$groupId = OC_USER::getGroupId($groupName,true);
|
|
|
|
if ( (0 != $groupId) AND (0 != $userId) ) {
|
|
|
|
$query="DELETE FROM `{$CONFIG_DBTABLEPREFIX}user_group` WHERE `group_id` =$groupId AND `user_id`=$userId";
|
|
|
|
$result = OC_DB::query($query);
|
|
|
|
if ( $result ) {
|
|
|
|
self::clearCache();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2010-07-23 01:42:18 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate a random password
|
|
|
|
*/
|
2010-07-21 19:53:51 +04:00
|
|
|
public static function generatePassword(){
|
2010-07-23 01:42:18 +04:00
|
|
|
return uniqId();
|
2010-07-15 16:09:22 +04:00
|
|
|
}
|
2010-07-19 20:52:49 +04:00
|
|
|
|
2010-07-15 16:09:22 +04:00
|
|
|
/**
|
2010-07-23 01:42:18 +04:00
|
|
|
* Get all groups the user belongs to
|
|
|
|
*
|
|
|
|
* @param string $username Name of the user
|
|
|
|
*/
|
|
|
|
public static function getUserGroups($username) {
|
2010-07-15 16:09:22 +04:00
|
|
|
global $CONFIG_DBTABLEPREFIX;
|
2010-09-12 19:04:52 +04:00
|
|
|
|
2010-07-23 01:42:18 +04:00
|
|
|
$userId = OC_USER::getUserId($username);
|
2010-09-12 19:04:52 +04:00
|
|
|
if(!isset(self::$userGroupCache[$userId])){
|
|
|
|
$query = "SELECT group_id FROM {$CONFIG_DBTABLEPREFIX}user_group WHERE user_id = '$userId'";
|
|
|
|
$result = OC_DB::select($query);
|
|
|
|
$groupsId = array();
|
|
|
|
if ( is_array($result) ) {
|
|
|
|
foreach ( $result as $group ) {
|
|
|
|
$groupId = $group['group_id'];
|
|
|
|
$groupsId[]=$groupId;
|
|
|
|
}
|
2010-07-15 16:09:22 +04:00
|
|
|
}
|
2010-09-12 19:04:52 +04:00
|
|
|
self::$userGroupCache[$userId]=$groupsId;
|
2010-09-20 22:27:43 +04:00
|
|
|
return $groupsId;
|
2010-09-12 19:04:52 +04:00
|
|
|
}else{
|
|
|
|
return self::$userGroupCache[$userId];
|
2010-07-15 16:09:22 +04:00
|
|
|
}
|
|
|
|
}
|
2010-07-23 01:42:18 +04:00
|
|
|
|
2010-07-15 16:09:22 +04:00
|
|
|
/**
|
2010-07-23 01:42:18 +04:00
|
|
|
* Set the password of a user
|
|
|
|
*
|
|
|
|
* @param string $username User who password will be changed
|
|
|
|
* @param string $password The new password for the user
|
|
|
|
*/
|
|
|
|
public static function setPassword($username, $password) {
|
2010-07-15 16:09:22 +04:00
|
|
|
global $CONFIG_DBTABLEPREFIX;
|
|
|
|
|
2010-07-23 01:42:18 +04:00
|
|
|
$password = sha1($password);
|
|
|
|
$userId = OC_USER::getUserId($username);
|
|
|
|
$query = "UPDATE {$CONFIG_DBTABLEPREFIX}users SET user_password = '$password' WHERE user_id ='$userId'";
|
|
|
|
$result = OC_DB::query($query);
|
|
|
|
if ( $result ) {
|
2010-07-21 19:53:51 +04:00
|
|
|
return true;
|
2010-07-23 01:42:18 +04:00
|
|
|
} else {
|
2010-07-21 19:53:51 +04:00
|
|
|
return false;
|
|
|
|
}
|
2010-07-15 16:09:22 +04:00
|
|
|
}
|
2010-07-19 20:52:49 +04:00
|
|
|
|
2010-07-15 16:09:22 +04:00
|
|
|
/**
|
2010-07-23 01:42:18 +04:00
|
|
|
* Check if the password of the user is correct
|
|
|
|
*
|
|
|
|
* @param string $username Name of the user
|
|
|
|
* @param string $password Password of the user
|
|
|
|
*/
|
|
|
|
public static function checkPassword($username, $password) {
|
2010-07-15 16:09:22 +04:00
|
|
|
global $CONFIG_DBTABLEPREFIX;
|
|
|
|
|
2010-07-23 01:42:18 +04:00
|
|
|
$password = sha1($password);
|
|
|
|
$usernameClean = strToLower($username);
|
|
|
|
$usernameClean = OC_DB::escape($usernameClean);
|
|
|
|
$username = OC_DB::escape($username);
|
2010-09-20 22:27:43 +04:00
|
|
|
$query = "SELECT user_id FROM `{$CONFIG_DBTABLEPREFIX}users` "
|
2010-07-23 01:42:18 +04:00
|
|
|
. "WHERE user_name_clean = '$usernameClean' AND user_password = '$password' LIMIT 1";
|
|
|
|
$result = OC_DB::select($query);
|
|
|
|
if ( isset($result[0]) AND isset($result[0]['user_id']) AND ($result[0]['user_id'] > 0) ) {
|
2010-07-15 16:09:22 +04:00
|
|
|
return true;
|
2010-07-23 01:42:18 +04:00
|
|
|
} else {
|
2010-07-15 16:09:22 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-12 19:04:52 +04:00
|
|
|
/**
|
|
|
|
* get a list of all users
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getUsers() {
|
|
|
|
global $CONFIG_DBTABLEPREFIX;
|
|
|
|
|
2010-09-20 22:27:43 +04:00
|
|
|
$query = "SELECT user_name FROM `{$CONFIG_DBTABLEPREFIX}users`";
|
2010-09-12 19:04:52 +04:00
|
|
|
$result = OC_DB::select($query);
|
|
|
|
$users=array();
|
|
|
|
foreach($result as $user){
|
|
|
|
$users[]=$user['user_name'];
|
|
|
|
}
|
|
|
|
return $users;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get a list of all groups
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getGroups() {
|
|
|
|
global $CONFIG_DBTABLEPREFIX;
|
|
|
|
|
2010-09-20 22:27:43 +04:00
|
|
|
$query = "SELECT group_name FROM `{$CONFIG_DBTABLEPREFIX}groups`";
|
2010-09-12 19:04:52 +04:00
|
|
|
$result = OC_DB::select($query);
|
|
|
|
$groups=array();
|
|
|
|
foreach($result as $group){
|
|
|
|
$groups[]=$group['group_name'];
|
|
|
|
}
|
|
|
|
return $groups;
|
|
|
|
}
|
2010-09-20 22:27:43 +04:00
|
|
|
|
|
|
|
private static function clearCache(){
|
|
|
|
self::$userGroupCache=array();
|
|
|
|
$_SESSION['user_id_cache']=array();
|
|
|
|
$_SESSION['group_id_cache']=array();
|
|
|
|
}
|
2010-07-15 21:56:13 +04:00
|
|
|
}
|