diff options
Diffstat (limited to 'lib/user.php')
-rw-r--r-- | lib/user.php | 104 |
1 files changed, 52 insertions, 52 deletions
diff --git a/lib/user.php b/lib/user.php index 236478e9e5c..89dab9f9647 100644 --- a/lib/user.php +++ b/lib/user.php @@ -52,7 +52,7 @@ class OC_User { * * Makes a list of backends that can be used by other modules */ - public static function registerBackend( $backend ){ + public static function registerBackend( $backend ) { self::$_backends[] = $backend; return true; } @@ -63,7 +63,7 @@ class OC_User { * * Returns the names of all backends. */ - public static function getBackends(){ + public static function getBackends() { return self::$_backends; } @@ -73,7 +73,7 @@ class OC_User { * * Returns the names of all used backends. */ - public static function getUsedBackends(){ + public static function getUsedBackends() { return array_keys(self::$_usedBackends); } @@ -84,17 +84,17 @@ class OC_User { * * Set the User Authentication Module */ - public static function useBackend( $backend = 'database' ){ - if($backend instanceof OC_User_Interface){ + public static function useBackend( $backend = 'database' ) { + if($backend instanceof OC_User_Interface) { self::$_usedBackends[get_class($backend)]=$backend; }else{ // You'll never know what happens - if( null === $backend OR !is_string( $backend )){ + if( null === $backend OR !is_string( $backend )) { $backend = 'database'; } // Load backend - switch( $backend ){ + switch( $backend ) { case 'database': case 'mysql': case 'sqlite': @@ -112,19 +112,19 @@ class OC_User { /** * remove all used backends */ - public static function clearBackends(){ + public static function clearBackends() { self::$_usedBackends=array(); } /** * setup the configured backends in config.php */ - public static function setupBackends(){ + public static function setupBackends() { $backends=OC_Config::getValue('user_backends',array()); - foreach($backends as $i=>$config){ + foreach($backends as $i=>$config) { $class=$config['class']; $arguments=$config['arguments']; - if(class_exists($class) and array_search($i,self::$_setupedBackends)===false){ + if(class_exists($class) and array_search($i,self::$_setupedBackends)===false) { // make a reflection object $reflectionObj = new ReflectionClass($class); @@ -149,23 +149,23 @@ class OC_User { * * Allowed characters in the username are: "a-z", "A-Z", "0-9" and "_.@-" */ - public static function createUser( $uid, $password ){ + public static function createUser( $uid, $password ) { // Check the name for bad characters // Allowed are: "a-z", "A-Z", "0-9" and "_.@-" - if( preg_match( '/[^a-zA-Z0-9 _\.@\-]/', $uid )){ + if( preg_match( '/[^a-zA-Z0-9 _\.@\-]/', $uid )) { throw new Exception('Only the following characters are allowed in a username: "a-z", "A-Z", "0-9", and "_.@-"'); } // No empty username - if(trim($uid) == ''){ + if(trim($uid) == '') { throw new Exception('A valid username must be provided'); } // No empty password - if(trim($password) == ''){ + if(trim($password) == '') { throw new Exception('A valid password must be provided'); } // Check if user already exists - if( self::userExists($uid) ){ + if( self::userExists($uid) ) { throw new Exception('The username is already being used'); } @@ -173,9 +173,9 @@ class OC_User { $run = true; OC_Hook::emit( "OC_User", "pre_createUser", array( "run" => &$run, "uid" => $uid, "password" => $password )); - if( $run ){ + if( $run ) { //create the user in the first backend that supports creating users - foreach(self::$_usedBackends as $backend){ + foreach(self::$_usedBackends as $backend) { if(!$backend->implementsActions(OC_USER_BACKEND_CREATE_USER)) continue; @@ -195,17 +195,17 @@ class OC_User { * * Deletes a user */ - public static function deleteUser( $uid ){ + public static function deleteUser( $uid ) { $run = true; OC_Hook::emit( "OC_User", "pre_deleteUser", array( "run" => &$run, "uid" => $uid )); - if( $run ){ + if( $run ) { //delete the user from all backends - foreach(self::$_usedBackends as $backend){ + foreach(self::$_usedBackends as $backend) { $backend->deleteUser($uid); } // We have to delete the user from all groups - foreach( OC_Group::getUserGroups( $uid ) as $i ){ + foreach( OC_Group::getUserGroups( $uid ) as $i ) { OC_Group::removeFromGroup( $uid, $i ); } // Delete the user's keys in preferences @@ -227,14 +227,14 @@ class OC_User { * * Log in a user and regenerate a new session - if the password is ok */ - public static function login( $uid, $password ){ + public static function login( $uid, $password ) { $run = true; OC_Hook::emit( "OC_User", "pre_login", array( "run" => &$run, "uid" => $uid )); - if( $run ){ + if( $run ) { $uid = self::checkPassword( $uid, $password ); $enabled = self::isEnabled($uid); - if($uid && $enabled){ + if($uid && $enabled) { session_regenerate_id(true); self::setUserId($uid); OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid, 'password'=>$password )); @@ -260,7 +260,7 @@ class OC_User { * * Logout, destroys session */ - public static function logout(){ + public static function logout() { OC_Hook::emit( "OC_User", "logout", array()); session_unset(); session_destroy(); @@ -274,11 +274,11 @@ class OC_User { * * Checks if the user is logged in */ - public static function isLoggedIn(){ + public static function isLoggedIn() { if( isset($_SESSION['user_id']) AND $_SESSION['user_id']) { OC_App::loadApps(array('authentication')); self::setupBackends(); - if (self::userExists($_SESSION['user_id']) ){ + if (self::userExists($_SESSION['user_id']) ) { return true; } } @@ -289,8 +289,8 @@ class OC_User { * @brief get the user id of the user currently logged in. * @return string uid or false */ - public static function getUser(){ - if( isset($_SESSION['user_id']) AND $_SESSION['user_id'] ){ + public static function getUser() { + if( isset($_SESSION['user_id']) AND $_SESSION['user_id'] ) { return $_SESSION['user_id']; } else{ @@ -304,7 +304,7 @@ class OC_User { * * generates a password */ - public static function generatePassword(){ + public static function generatePassword() { return uniqId(); } @@ -316,15 +316,15 @@ class OC_User { * * Change the password of a user */ - public static function setPassword( $uid, $password ){ + public static function setPassword( $uid, $password ) { $run = true; OC_Hook::emit( "OC_User", "pre_setPassword", array( "run" => &$run, "uid" => $uid, "password" => $password )); - if( $run ){ + if( $run ) { $success = false; - foreach(self::$_usedBackends as $backend){ - if($backend->implementsActions(OC_USER_BACKEND_SET_PASSWORD)){ - if($backend->userExists($uid)){ + foreach(self::$_usedBackends as $backend) { + if($backend->implementsActions(OC_USER_BACKEND_SET_PASSWORD)) { + if($backend->userExists($uid)) { $success |= $backend->setPassword($uid,$password); } } @@ -346,11 +346,11 @@ class OC_User { * Check if the password is correct without logging in the user * returns the user id or false */ - public static function checkPassword( $uid, $password ){ - foreach(self::$_usedBackends as $backend){ - if($backend->implementsActions(OC_USER_BACKEND_CHECK_PASSWORD)){ + public static function checkPassword( $uid, $password ) { + foreach(self::$_usedBackends as $backend) { + if($backend->implementsActions(OC_USER_BACKEND_CHECK_PASSWORD)) { $result=$backend->checkPassword( $uid, $password ); - if($result){ + if($result) { return $result; } } @@ -366,11 +366,11 @@ class OC_User { * Check if the password is correct without logging in the user * returns the user id or false */ - public static function getHome($uid){ - foreach(self::$_usedBackends as $backend){ - if($backend->implementsActions(OC_USER_BACKEND_GET_HOME)){ + public static function getHome($uid) { + foreach(self::$_usedBackends as $backend) { + if($backend->implementsActions(OC_USER_BACKEND_GET_HOME)) { $result=$backend->getHome($uid); - if($result){ + if($result) { return $result; } } @@ -401,10 +401,10 @@ class OC_User { * @param string $uid the username * @return boolean */ - public static function userExists($uid){ - foreach(self::$_usedBackends as $backend){ + public static function userExists($uid) { + foreach(self::$_usedBackends as $backend) { $result=$backend->userExists($uid); - if($result===true){ + if($result===true) { return true; } } @@ -415,7 +415,7 @@ class OC_User { * disables a user * @param string $userid the user to disable */ - public static function disableUser($userid){ + public static function disableUser($userid) { $query = "INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, `configkey`, `configvalue`) VALUES(?, ?, ?, ?)"; $query = OC_DB::prepare($query); $query->execute(array($userid, 'core', 'enabled', 'false')); @@ -425,7 +425,7 @@ class OC_User { * enable a user * @param string $userid */ - public static function enableUser($userid){ + public static function enableUser($userid) { $query = "DELETE FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ? AND `configvalue` = ?"; $query = OC_DB::prepare($query); $query->execute(array($userid, 'core', 'enabled', 'false')); @@ -436,7 +436,7 @@ class OC_User { * @param string $userid * @return bool */ - public static function isEnabled($userid){ + public static function isEnabled($userid) { $query = "SELECT `userid` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ? AND `configvalue` = ?"; $query = OC_DB::prepare($query); $results = $query->execute(array($userid, 'core', 'enabled', 'false')); @@ -447,7 +447,7 @@ class OC_User { * @brief Set cookie value to use in next page load * @param string $username username to be set */ - public static function setMagicInCookie($username, $token){ + public static function setMagicInCookie($username, $token) { $secure_cookie = OC_Config::getValue("forcessl", false); setcookie("oc_username", $username, time()+60*60*24*15, '', '', $secure_cookie); setcookie("oc_token", $token, time()+60*60*24*15, '', '', $secure_cookie); @@ -457,7 +457,7 @@ class OC_User { /** * @brief Remove cookie for "remember username" */ - public static function unsetMagicInCookie(){ + public static function unsetMagicInCookie() { unset($_COOKIE["oc_username"]); unset($_COOKIE["oc_token"]); unset($_COOKIE["oc_remember_login"]); |