2010-04-22 21:03:54 +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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-07-15 21:10:20 +04:00
|
|
|
|
|
|
|
|
2010-07-15 22:57:14 +04:00
|
|
|
if ( !$CONFIG_INSTALLED ) {
|
2010-07-15 21:10:20 +04:00
|
|
|
$_SESSION['user_id'] = false;
|
|
|
|
$_SESSION['username'] = '';
|
|
|
|
$_SESSION['username_clean'] = '';
|
2010-04-24 14:40:20 +04:00
|
|
|
}
|
|
|
|
|
2010-06-22 03:27:44 +04:00
|
|
|
//cache the userid's an groupid's
|
2010-07-15 22:57:14 +04:00
|
|
|
if ( !isset($_SESSION['user_id_cache']) ) {
|
2010-07-15 21:10:20 +04:00
|
|
|
$_SESSION['user_id_cache'] = array();
|
2010-06-22 03:27:44 +04:00
|
|
|
}
|
2010-07-15 21:10:20 +04:00
|
|
|
if( !isset($_SESSION['group_id_cache']) ) {
|
|
|
|
$_SESSION['group_id_cache'] = array();
|
2010-06-22 03:27:44 +04:00
|
|
|
}
|
|
|
|
|
2010-07-15 21:10:20 +04:00
|
|
|
|
|
|
|
|
2010-04-22 21:03:54 +04:00
|
|
|
/**
|
2010-07-15 22:57:14 +04:00
|
|
|
* Class for user management
|
2010-04-22 21:03:54 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
class OC_USER {
|
|
|
|
|
2010-07-15 21:10:20 +04:00
|
|
|
public static $classType;
|
2010-07-15 16:11:53 +04:00
|
|
|
|
2010-04-22 21:03:54 +04:00
|
|
|
/**
|
2010-07-15 22:57:14 +04:00
|
|
|
* Check if the login button is pressed and logg the user in
|
2010-07-15 21:10:20 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function loginLisener() {
|
|
|
|
return self::classType->loginLisener();
|
2010-04-22 21:03:54 +04:00
|
|
|
}
|
|
|
|
|
2010-04-22 22:08:38 +04:00
|
|
|
|
2010-04-22 21:03:54 +04:00
|
|
|
/**
|
2010-07-15 22:57:14 +04:00
|
|
|
* Try to create a new user
|
2010-07-15 21:10:20 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function createUser($username, $password) {
|
|
|
|
return self::classType->createUser($username, $password);
|
2010-04-22 21:03:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-15 22:57:14 +04:00
|
|
|
* Try to login a user
|
2010-07-15 21:10:20 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function login($username, $password) {
|
|
|
|
return self::classType->login($username, $password);
|
2010-04-22 21:03:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-15 22:57:14 +04:00
|
|
|
* Check if the logout button is pressed and logout the user
|
2010-07-15 21:10:20 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function logoutLisener() {
|
|
|
|
return self::classType->logoutLisener();
|
2010-04-22 21:03:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-15 22:57:14 +04:00
|
|
|
* Check if a user is logged in
|
2010-07-15 21:10:20 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function isLoggedIn() {
|
|
|
|
return self::classType->isLoggedIn();
|
2010-04-22 21:03:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-15 22:57:14 +04:00
|
|
|
* Try to create a new group
|
2010-07-15 21:10:20 +04:00
|
|
|
*
|
|
|
|
*/
|
2010-07-15 22:57:14 +04:00
|
|
|
public static function createGroup($groupName) {
|
|
|
|
return self::classType->createGroup($groupName);
|
2010-04-22 21:03:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-15 22:57:14 +04:00
|
|
|
* Get the ID of a user
|
2010-07-15 21:10:20 +04:00
|
|
|
*
|
|
|
|
*/
|
2010-07-15 22:57:14 +04:00
|
|
|
public static function getUserId($username, $noCache=false) {
|
|
|
|
return self::classType->getUserId($username, $noCache);
|
2010-04-22 21:03:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-15 22:57:14 +04:00
|
|
|
* Get the ID of a group
|
2010-07-15 21:10:20 +04:00
|
|
|
*
|
|
|
|
*/
|
2010-07-15 22:57:14 +04:00
|
|
|
public static function getGroupId($groupName, $noCache=false) {
|
|
|
|
return self::classType->getGroupId($groupName, $noCache);
|
2010-04-22 21:03:54 +04:00
|
|
|
}
|
|
|
|
|
2010-04-23 02:05:04 +04:00
|
|
|
/**
|
2010-07-15 22:57:14 +04:00
|
|
|
* Get the name of a group
|
2010-07-15 21:10:20 +04:00
|
|
|
*
|
|
|
|
*/
|
2010-07-15 22:57:14 +04:00
|
|
|
public static function getGroupName($groupId, $noCache=false) {
|
|
|
|
return self::classType->getGroupName($groupId, $noCache);
|
2010-04-23 02:05:04 +04:00
|
|
|
}
|
|
|
|
|
2010-04-22 21:03:54 +04:00
|
|
|
/**
|
2010-07-15 22:57:14 +04:00
|
|
|
* Check if a user belongs to a group
|
2010-07-15 21:10:20 +04:00
|
|
|
*
|
|
|
|
*/
|
2010-07-15 22:57:14 +04:00
|
|
|
public static function inGroup($username, $groupName) {
|
|
|
|
return self::classType->inGroup($username, $groupName);
|
2010-04-22 21:03:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-15 22:57:14 +04:00
|
|
|
* Add a user to a group
|
2010-07-15 21:10:20 +04:00
|
|
|
*
|
|
|
|
*/
|
2010-07-15 22:57:14 +04:00
|
|
|
public static function addToGroup($username, $groupName) {
|
|
|
|
return self::classType->addToGroup($username, $groupName);
|
2010-04-22 21:03:54 +04:00
|
|
|
}
|
2010-04-22 22:08:38 +04:00
|
|
|
|
2010-07-15 21:10:20 +04:00
|
|
|
public static function generatePassword() {
|
2010-07-15 22:57:14 +04:00
|
|
|
return uniqId();
|
2010-04-22 22:08:38 +04:00
|
|
|
}
|
2010-04-23 02:05:04 +04:00
|
|
|
|
|
|
|
/**
|
2010-07-15 22:57:14 +04:00
|
|
|
* Get all groups the user belongs to
|
2010-07-15 21:10:20 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getUserGroups($username) {
|
|
|
|
return self::classType->getUserGroups($username);
|
2010-04-23 02:05:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-15 22:57:14 +04:00
|
|
|
* Set the password of a user
|
2010-07-15 21:10:20 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function setPassword($username, $password) {
|
|
|
|
return self::classType->setPassword($username, $password);
|
2010-04-23 02:05:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-15 22:57:14 +04:00
|
|
|
* Check the password of a user
|
2010-07-15 21:10:20 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function checkPassword($username, $password) {
|
|
|
|
return self::classType->checkPassword($username, $password);
|
2010-07-15 16:11:53 +04:00
|
|
|
}
|
|
|
|
}
|
2010-07-03 21:38:31 +04:00
|
|
|
|
2010-07-15 21:10:20 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-07-15 16:11:53 +04:00
|
|
|
* Funtion to set the User Authentication Module
|
|
|
|
*/
|
|
|
|
function set_OC_USER() {
|
|
|
|
global $CONFIG_BACKEND;
|
2010-07-15 21:10:20 +04:00
|
|
|
|
|
|
|
if ( isset($CONFIG_BACKEND) ) {
|
|
|
|
switch( $CONFIG_BACKEND ) {
|
|
|
|
case 'mysql':
|
|
|
|
case 'sqlite':
|
2010-07-15 16:11:53 +04:00
|
|
|
require_once 'User/database.php';
|
2010-07-15 21:10:20 +04:00
|
|
|
self::classType = new OC_USER_Database();
|
|
|
|
break;
|
|
|
|
case 'ldap':
|
2010-07-15 16:11:53 +04:00
|
|
|
require_once 'User/ldap.php';
|
2010-07-15 21:10:20 +04:00
|
|
|
self::classType = new OC_USER_LDAP();
|
|
|
|
break;
|
2010-07-15 16:11:53 +04:00
|
|
|
default:
|
|
|
|
require_once 'User/database.php';
|
2010-07-15 21:10:20 +04:00
|
|
|
self::classType = new OC_USER_Database();
|
|
|
|
break;
|
2010-04-23 02:05:04 +04:00
|
|
|
}
|
2010-07-15 21:10:20 +04:00
|
|
|
} else {
|
2010-07-15 16:11:53 +04:00
|
|
|
require_once 'User/database.php';
|
2010-07-15 21:10:20 +04:00
|
|
|
self::classType = new OC_USER_Database();
|
2010-07-15 16:11:53 +04:00
|
|
|
}
|
2010-04-22 21:03:54 +04:00
|
|
|
}
|
2010-07-15 21:10:20 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-07-15 16:11:53 +04:00
|
|
|
set_OC_USER();
|