nextcloud/inc/lib_user.php

201 lines
4.1 KiB
PHP
Raw Normal View History

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/>.
*
*/
if ( !$CONFIG_INSTALLED ) {
$_SESSION['user_id'] = false;
$_SESSION['username'] = '';
$_SESSION['username_clean'] = '';
}
// 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 21:03:54 +04:00
/**
* Class for user management
2010-04-22 21:03:54 +04:00
*
*/
class OC_USER {
public static $classType;
2010-04-22 21:03:54 +04:00
/**
* Check if the login button is pressed and logg the user in
*
*/
public static function loginLisener() {
return self::$classType->loginLisener();
2010-04-22 21:03:54 +04:00
}
2010-04-22 21:03:54 +04:00
/**
* Try to create a new user
*
*/
public static function createUser($username, $password) {
return self::$classType->createUser($username, $password);
2010-04-22 21:03:54 +04:00
}
2010-04-22 21:03:54 +04:00
/**
* Try to login a user
*
*/
public static function login($username, $password) {
return self::$classType->login($username, $password);
2010-04-22 21:03:54 +04:00
}
2010-04-22 21:03:54 +04:00
/**
* Check if the logout button is pressed and logout the user
*
*/
public static function logoutLisener() {
return self::$classType->logoutLisener();
2010-04-22 21:03:54 +04:00
}
2010-04-22 21:03:54 +04:00
/**
* Check if a user is logged in
*
*/
public static function isLoggedIn() {
return self::$classType->isLoggedIn();
2010-04-22 21:03:54 +04:00
}
2010-04-22 21:03:54 +04:00
/**
* Try to create a new group
*
*/
public static function createGroup($groupName) {
return self::$classType->createGroup($groupName);
2010-04-22 21:03:54 +04:00
}
2010-04-22 21:03:54 +04:00
/**
* Get the ID of a user
*
*/
public static function getUserId($username, $noCache=false) {
return self::$classType->getUserId($username, $noCache);
2010-04-22 21:03:54 +04:00
}
2010-04-22 21:03:54 +04:00
/**
* Get the ID of a group
*
*/
public static function getGroupId($groupName, $noCache=false) {
return self::$classType->getGroupId($groupName, $noCache);
2010-04-22 21:03:54 +04:00
}
/**
* Get the name of a group
*
*/
public static function getGroupName($groupId, $noCache=false) {
return self::$classType->getGroupName($groupId, $noCache);
}
2010-04-22 21:03:54 +04:00
/**
* Check if a user belongs to a group
*
*/
public static function inGroup($username, $groupName) {
return self::$classType->inGroup($username, $groupName);
2010-04-22 21:03:54 +04:00
}
2010-04-22 21:03:54 +04:00
/**
* Add a user to a group
*
*/
public static function addToGroup($username, $groupName) {
return self::$classType->addToGroup($username, $groupName);
2010-04-22 21:03:54 +04:00
}
public static function generatePassword() {
return uniqId();
2010-04-22 22:08:38 +04:00
}
/**
* Get all groups the user belongs to
*
*/
public static function getUserGroups($username) {
return self::$classType->getUserGroups($username);
}
/**
* Set the password of a user
*
*/
public static function setPassword($username, $password) {
return self::$classType->setPassword($username, $password);
}
/**
* Check the password of a user
*
*/
public static function checkPassword($username, $password) {
return self::$classType->checkPassword($username, $password);
2010-07-15 16:11:53 +04:00
}
2010-07-15 16:11:53 +04:00
}
/**
2010-07-15 16:11:53 +04:00
* Funtion to set the User Authentication Module
*/
function set_OC_USER() {
global $CONFIG_BACKEND;
if ( isset($CONFIG_BACKEND) ) {
switch ( $CONFIG_BACKEND ) {
case 'mysql':
case 'sqlite':
2010-07-15 16:11:53 +04:00
require_once 'User/database.php';
OC_USER::$classType = new OC_USER_Database();
break;
case 'ldap':
2010-07-15 16:11:53 +04:00
require_once 'User/ldap.php';
OC_USER::$classType = new OC_USER_LDAP();
break;
2010-07-15 16:11:53 +04:00
default:
require_once 'User/database.php';
OC_USER::$classType = new OC_USER_Database();
break;
}
} else {
2010-07-15 16:11:53 +04:00
require_once 'User/database.php';
OC_USER::$classType = new OC_USER_Database();
2010-07-15 16:11:53 +04:00
}
2010-04-22 21:03:54 +04:00
}
2010-07-15 16:11:53 +04:00
set_OC_USER();