2010-04-22 17:03:54 +00: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-04-24 10:40:20 +00:00
|
|
|
if(!$CONFIG_INSTALLED){
|
|
|
|
$_SESSION['user_id']=false;
|
|
|
|
$_SESSION['username']='';
|
|
|
|
$_SESSION['username_clean']='';
|
|
|
|
}
|
|
|
|
|
2010-06-21 23:27:44 +00:00
|
|
|
//cache the userid's an groupid's
|
|
|
|
if(!isset($_SESSION['user_id_cache'])){
|
|
|
|
$_SESSION['user_id_cache']=array();
|
|
|
|
}
|
|
|
|
if(!isset($_SESSION['group_id_cache'])){
|
|
|
|
$_SESSION['group_id_cache']=array();
|
|
|
|
}
|
|
|
|
|
2010-04-22 17:03:54 +00:00
|
|
|
/**
|
|
|
|
* Class for usermanagement
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class OC_USER {
|
|
|
|
|
2010-07-15 12:11:53 +00:00
|
|
|
public static $class_type;
|
|
|
|
|
2010-04-22 17:03:54 +00:00
|
|
|
/**
|
|
|
|
* check if the login button is pressed and logg the user in
|
|
|
|
*
|
|
|
|
*/
|
2010-07-10 18:00:27 +00:00
|
|
|
public static function loginLisener(){
|
2010-07-15 12:11:53 +00:00
|
|
|
return self::$class_type->loginLisener();
|
2010-04-22 17:03:54 +00:00
|
|
|
}
|
|
|
|
|
2010-04-22 18:08:38 +00:00
|
|
|
|
2010-04-22 17:03:54 +00:00
|
|
|
/**
|
|
|
|
* try to create a new user
|
|
|
|
*
|
|
|
|
*/
|
2010-07-10 18:00:27 +00:00
|
|
|
public static function createUser($username,$password){
|
2010-07-15 12:11:53 +00:00
|
|
|
return self::$class_type->createUser($username,$password);
|
2010-04-22 17:03:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* try to login a user
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function login($username,$password){
|
2010-07-15 12:11:53 +00:00
|
|
|
return self::$class_type->login($username,$password);
|
2010-04-22 17:03:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* check if the logout button is pressed and logout the user
|
|
|
|
*
|
|
|
|
*/
|
2010-07-10 18:00:27 +00:00
|
|
|
public static function logoutLisener(){
|
2010-07-15 12:11:53 +00:00
|
|
|
return self::$class_type->logoutLisener();
|
2010-04-22 17:03:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* check if a user is logged in
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function isLoggedIn(){
|
2010-07-15 12:11:53 +00:00
|
|
|
return self::$class_type->isLoggedIn();
|
2010-04-22 17:03:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* try to create a new group
|
|
|
|
*
|
|
|
|
*/
|
2010-07-10 18:00:27 +00:00
|
|
|
public static function createGroup($groupname){
|
2010-07-15 12:11:53 +00:00
|
|
|
return self::$class_type->createGroup($groupname);
|
2010-04-22 17:03:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the id of a user
|
|
|
|
*
|
|
|
|
*/
|
2010-07-10 18:00:27 +00:00
|
|
|
public static function getUserId($username,$nocache=false){
|
2010-07-15 12:11:53 +00:00
|
|
|
return self::$class_type->getUserId($username,$nocache=false);
|
2010-04-22 17:03:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the id of a group
|
|
|
|
*
|
|
|
|
*/
|
2010-07-10 18:00:27 +00:00
|
|
|
public static function getGroupId($groupname,$nocache=false){
|
2010-07-15 12:11:53 +00:00
|
|
|
return self::$class_type->getGroupId($groupname,$nocache=false);
|
2010-04-22 17:03:54 +00:00
|
|
|
}
|
|
|
|
|
2010-04-22 22:05:04 +00:00
|
|
|
/**
|
|
|
|
* get the name of a group
|
|
|
|
*
|
|
|
|
*/
|
2010-07-10 18:00:27 +00:00
|
|
|
public static function getGroupName($groupid,$nocache=false){
|
2010-07-15 12:11:53 +00:00
|
|
|
return self::$class_type->getGroupName($groupid,$nocache=false);
|
2010-04-22 22:05:04 +00:00
|
|
|
}
|
|
|
|
|
2010-04-22 17:03:54 +00:00
|
|
|
/**
|
|
|
|
* check if a user belongs to a group
|
|
|
|
*
|
|
|
|
*/
|
2010-07-10 18:00:27 +00:00
|
|
|
public static function inGroup($username,$groupname){
|
2010-07-15 12:11:53 +00:00
|
|
|
return self::$class_type->inGroup($username,$groupname);
|
2010-04-22 17:03:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* add a user to a group
|
|
|
|
*
|
|
|
|
*/
|
2010-07-10 18:00:27 +00:00
|
|
|
public static function addToGroup($username,$groupname){
|
2010-07-15 12:11:53 +00:00
|
|
|
return self::$class_type->addToGroup($username,$groupname);
|
2010-04-22 17:03:54 +00:00
|
|
|
}
|
2010-04-22 18:08:38 +00:00
|
|
|
|
2010-07-10 18:00:27 +00:00
|
|
|
public static function generatePassword(){
|
2010-04-22 18:08:38 +00:00
|
|
|
return uniqid();
|
|
|
|
}
|
2010-04-22 22:05:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get all groups the user belongs to
|
|
|
|
*
|
|
|
|
*/
|
2010-07-10 18:00:27 +00:00
|
|
|
public static function getUserGroups($username){
|
2010-07-15 12:11:53 +00:00
|
|
|
return self::$class_type->getUserGroups($username);
|
2010-04-22 22:05:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set the password of a user
|
|
|
|
*
|
|
|
|
*/
|
2010-07-10 18:00:27 +00:00
|
|
|
public static function setPassword($username,$password){
|
2010-07-15 12:11:53 +00:00
|
|
|
return self::$class_type->setPassword($username,$password);
|
2010-04-22 22:05:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* check the password of a user
|
|
|
|
*
|
|
|
|
*/
|
2010-07-10 18:00:27 +00:00
|
|
|
public static function checkPassword($username,$password){
|
2010-07-15 12:11:53 +00:00
|
|
|
return self::$class_type->checkPassword($username,$password);
|
|
|
|
}
|
|
|
|
}
|
2010-07-03 17:38:31 +00:00
|
|
|
|
2010-07-15 12:11:53 +00:00
|
|
|
/*
|
|
|
|
* Funtion to set the User Authentication Module
|
|
|
|
*/
|
|
|
|
function set_OC_USER() {
|
|
|
|
global $CONFIG_BACKEND;
|
|
|
|
if (isset($CONFIG_BACKEND)) {
|
|
|
|
switch($CONFIG_BACKEND) {
|
|
|
|
case "mysql":
|
|
|
|
require_once 'User/database.php';
|
|
|
|
OC_USER::$class_type = new OC_USER_Database();
|
|
|
|
break;
|
|
|
|
case "sqlite":
|
|
|
|
require_once 'User/database.php';
|
|
|
|
OC_USER::$class_type = new OC_USER_Database();
|
|
|
|
break;
|
|
|
|
case "ldap":
|
|
|
|
require_once 'User/ldap.php';
|
|
|
|
OC_USER::$class_type = new OC_USER_LDAP();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
require_once 'User/database.php';
|
|
|
|
OC_USER::$class_type = new OC_USER_Database();
|
|
|
|
break;
|
2010-04-22 22:05:04 +00:00
|
|
|
}
|
|
|
|
}
|
2010-07-15 12:11:53 +00:00
|
|
|
else {
|
|
|
|
require_once 'User/database.php';
|
|
|
|
OC_USER::$class_type = new OC_USER_Database();
|
|
|
|
}
|
2010-04-22 17:03:54 +00:00
|
|
|
}
|
2010-07-15 12:11:53 +00:00
|
|
|
set_OC_USER();
|
2010-04-22 17:03:54 +00:00
|
|
|
?>
|