2010-04-22 21:03:54 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2011-04-15 19:14:02 +04:00
|
|
|
* 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 Affero General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2010-04-24 14:40:20 +04:00
|
|
|
|
2011-04-15 19:14:02 +04:00
|
|
|
if( !$CONFIG_INSTALLED ){
|
|
|
|
$_SESSION['user_id'] = '';
|
2010-06-22 03:27:44 +04:00
|
|
|
}
|
|
|
|
|
2010-04-22 21:03:54 +04:00
|
|
|
/**
|
2011-04-15 19:14:02 +04:00
|
|
|
* This class provides all methods for user management.
|
2010-04-22 21:03:54 +04:00
|
|
|
*/
|
2010-07-21 19:53:51 +04:00
|
|
|
class OC_USER {
|
|
|
|
// The backend used for user management
|
2011-04-15 19:14:02 +04:00
|
|
|
private static $_backend = null;
|
|
|
|
|
|
|
|
// Backends available (except database)
|
|
|
|
private static $_backends = array();
|
2010-07-21 19:53:51 +04:00
|
|
|
|
|
|
|
/**
|
2011-04-15 19:14:02 +04:00
|
|
|
* @brief registers backend
|
|
|
|
* @param $name name of the backend
|
|
|
|
* @returns true/false
|
2010-07-23 01:42:18 +04:00
|
|
|
*
|
2011-04-15 19:14:02 +04:00
|
|
|
* Makes a list of backends that can be used by other modules
|
2010-07-23 01:42:18 +04:00
|
|
|
*/
|
2011-04-15 19:14:02 +04:00
|
|
|
public static function registerBackend( $name ){
|
|
|
|
self::$_backends[] = $name;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief gets available backends
|
|
|
|
* @returns array of backends
|
|
|
|
*
|
|
|
|
* Returns the names of all backends.
|
|
|
|
*/
|
|
|
|
public static function getBackends(){
|
|
|
|
return self::$_backends;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sets the backend
|
|
|
|
* @param $backend default: database The backend to use for user managment
|
|
|
|
* @returns true/false
|
|
|
|
*
|
|
|
|
* Set the User Authentication Module
|
|
|
|
*/
|
|
|
|
public static function setBackend( $backend = 'database' ){
|
|
|
|
// You'll never know what happens
|
|
|
|
if( null === $backend OR !is_string( $backend )){
|
2010-07-21 19:53:51 +04:00
|
|
|
$backend = 'database';
|
|
|
|
}
|
|
|
|
|
2011-04-15 19:14:02 +04:00
|
|
|
// Load backend
|
|
|
|
switch( $backend ){
|
2010-07-23 02:48:45 +04:00
|
|
|
case 'database':
|
2010-07-21 19:53:51 +04:00
|
|
|
case 'mysql':
|
|
|
|
case 'sqlite':
|
2011-04-16 12:12:53 +04:00
|
|
|
require_once('User/database.php');
|
2010-07-21 19:53:51 +04:00
|
|
|
self::$_backend = new OC_USER_DATABASE();
|
|
|
|
break;
|
|
|
|
default:
|
2010-07-23 02:48:45 +04:00
|
|
|
$className = 'OC_USER_' . strToUpper($backend);
|
|
|
|
self::$_backend = new $className();
|
2010-07-21 19:53:51 +04:00
|
|
|
break;
|
|
|
|
}
|
2010-07-19 20:52:49 +04:00
|
|
|
|
2011-04-15 19:14:02 +04:00
|
|
|
true;
|
2010-07-21 19:53:51 +04:00
|
|
|
}
|
2010-07-19 20:52:49 +04:00
|
|
|
|
2010-04-22 21:03:54 +04:00
|
|
|
/**
|
2011-04-15 19:14:02 +04:00
|
|
|
* @brief Creates a new user
|
|
|
|
* @param $username The username of the user to create
|
|
|
|
* @param $password The password of the new user
|
2010-07-23 01:42:18 +04:00
|
|
|
*/
|
2011-04-15 19:14:02 +04:00
|
|
|
public static function createUser( $username, $password ){
|
|
|
|
return self::$_backend->createUser( $username, $password );
|
2010-07-21 19:53:51 +04:00
|
|
|
}
|
2010-07-19 20:52:49 +04:00
|
|
|
|
2010-04-22 21:03:54 +04:00
|
|
|
/**
|
2011-04-15 19:14:02 +04:00
|
|
|
* @brief try to login a user
|
|
|
|
* @param $username The username of the user to log in
|
|
|
|
* @param $password The password of the user
|
2010-07-23 01:42:18 +04:00
|
|
|
*/
|
2011-04-15 19:14:02 +04:00
|
|
|
public static function login( $username, $password ){
|
|
|
|
return self::$_backend->login( $username, $password );
|
2010-07-21 19:53:51 +04:00
|
|
|
}
|
2010-07-19 20:52:49 +04:00
|
|
|
|
2011-03-02 01:20:16 +03:00
|
|
|
/**
|
2011-04-15 19:14:02 +04:00
|
|
|
* @brief Kick the user
|
2011-03-02 01:20:16 +03:00
|
|
|
*/
|
2011-04-15 19:14:02 +04:00
|
|
|
public static function logout(){
|
2011-03-02 01:20:16 +03:00
|
|
|
return self::$_backend->logout();
|
|
|
|
}
|
|
|
|
|
2010-04-22 21:03:54 +04:00
|
|
|
/**
|
2011-04-15 19:14:02 +04:00
|
|
|
* @brief Check if the user is logged in
|
2010-07-23 01:42:18 +04:00
|
|
|
*/
|
2011-04-15 19:14:02 +04:00
|
|
|
public static function isLoggedIn(){
|
2010-07-21 19:53:51 +04:00
|
|
|
return self::$_backend->isLoggedIn();
|
|
|
|
}
|
2010-07-19 20:52:49 +04:00
|
|
|
|
2010-04-22 21:03:54 +04:00
|
|
|
/**
|
2011-04-15 19:14:02 +04:00
|
|
|
* @brief Generate a random password
|
2010-07-23 01:42:18 +04:00
|
|
|
*/
|
2011-04-15 19:14:02 +04:00
|
|
|
public static function generatePassword(){
|
|
|
|
return substr( md5( uniqId().time()), 0, 10 );
|
2010-07-21 19:53:51 +04:00
|
|
|
}
|
2010-07-19 20:52:49 +04:00
|
|
|
|
2010-04-22 21:03:54 +04:00
|
|
|
/**
|
2011-04-15 19:14:02 +04:00
|
|
|
* @brief Set the password of a user
|
|
|
|
* @param $username User whose password will be changed
|
|
|
|
* @param $password The new password for the user
|
2010-07-23 01:42:18 +04:00
|
|
|
*/
|
2011-04-15 19:14:02 +04:00
|
|
|
public static function setPassword( $username, $password ){
|
|
|
|
return self::$_backend->setPassword( $username, $password );
|
2010-07-21 19:53:51 +04:00
|
|
|
}
|
2010-07-19 20:52:49 +04:00
|
|
|
|
2010-04-22 21:03:54 +04:00
|
|
|
/**
|
2011-04-15 19:14:02 +04:00
|
|
|
* @brief Check if the password of the user is correct
|
2010-07-23 01:42:18 +04:00
|
|
|
* @param string $username Name of the user
|
|
|
|
* @param string $password Password of the user
|
|
|
|
*/
|
2011-04-15 19:14:02 +04:00
|
|
|
public static function checkPassword( $username, $password ){
|
|
|
|
return self::$_backend->checkPassword( $username, $password );
|
2010-07-21 19:53:51 +04:00
|
|
|
}
|
2010-07-15 21:10:20 +04:00
|
|
|
|
2010-09-15 20:24:14 +04:00
|
|
|
/**
|
2011-04-15 19:14:02 +04:00
|
|
|
* @brief get a list of all users
|
|
|
|
* @returns array with uids
|
2010-09-15 20:24:14 +04:00
|
|
|
*/
|
2011-04-15 19:14:02 +04:00
|
|
|
public static function getUsers(){
|
2010-09-15 20:24:14 +04:00
|
|
|
return self::$_backend->getUsers();
|
|
|
|
}
|
2010-04-22 21:03:54 +04:00
|
|
|
}
|