diff options
author | Florian Reinhard <florian.reinhard@googlemail.com> | 2012-04-08 19:30:53 +0400 |
---|---|---|
committer | Florian Reinhard <florian.reinhard@googlemail.com> | 2012-04-08 19:30:53 +0400 |
commit | c905ff4f8a316eb3a5d435e5932538b5cf9aa62c (patch) | |
tree | 6c68b26221020eead129a1035d5eec35ae5eb1bd /django_auth | |
parent | da5b1c8bf768ebfb1a9bc8b62e4859b14a6ff945 (diff) |
Code Cleanup
Brackets for oneline-IFs
Rename DJANGO_AUTH to Django
Rename class names to camlelCase
Spaces2Tabs
Diffstat (limited to 'django_auth')
-rw-r--r-- | django_auth/appinfo/app.php | 14 | ||||
-rw-r--r-- | django_auth/lib/group.php | 120 | ||||
-rw-r--r-- | django_auth/lib/user.php | 118 | ||||
-rw-r--r-- | django_auth/settings.php | 2 |
4 files changed, 133 insertions, 121 deletions
diff --git a/django_auth/appinfo/app.php b/django_auth/appinfo/app.php index 50d04d29a..187ec0a0d 100644 --- a/django_auth/appinfo/app.php +++ b/django_auth/appinfo/app.php @@ -4,18 +4,18 @@ * ownCloud - Django Authentification Backend * * @author Florian Reinhard - * @copyright 2011 Florian Reinhard <florian.reinhard@googlemail.com> + * @copyright 2012 Florian Reinhard <florian.reinhard@googlemail.com> * * 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/>. * @@ -29,9 +29,9 @@ define('OC_GROUP_BACKEND_DJANGO_SUPERUSER_IS_ADMIN', true); OC_APP::registerAdmin('django_auth','settings'); -OC_User::registerBackend('DJANGO_AUTH'); -OC_User::useBackend( 'DJANGO_AUTH' ); +OC_User::registerBackend('Django'); +OC_User::useBackend( 'Django' ); -OC_Group::registerBackend('DJANGO_AUTH'); -OC_Group::setBackend( 'DJANGO_AUTH' ); +OC_Group::registerBackend('Django'); +OC_Group::setBackend( 'Django' ); ?>
\ No newline at end of file diff --git a/django_auth/lib/group.php b/django_auth/lib/group.php index 2ff10fe77..8d0fd448f 100644 --- a/django_auth/lib/group.php +++ b/django_auth/lib/group.php @@ -22,13 +22,13 @@ */ /** - * @brief Class providing django groups to ownCloud - * @see http://www.djangoproject.com - * - * Authentification backend to authenticate agains a django webapplication using - * django.contrib.auth. - */ -class OC_GROUP_DJANGO_AUTH extends OC_Group_Backend { +* @brief Class providing django groups to ownCloud +* @see http://www.djangoproject.com +* +* Authentification backend to authenticate agains a django webapplication using +* django.contrib.auth. +*/ +class OC_Group_Django extends OC_Group_Backend { static $staff_is_admin; static $superuser_is_admin; @@ -39,38 +39,38 @@ class OC_GROUP_DJANGO_AUTH extends OC_Group_Backend { static private $userGroupCache=array(); /** - * @brief Try to create a new group - * @param $gid The name of the group to create - * @returns true/false - * - * Trys to create a new group. If the group name already exists, false will - * be returned. - */ + * @brief Try to create a new group + * @param $gid The name of the group to create + * @returns true/false + * + * Trys to create a new group. If the group name already exists, false will + * be returned. + */ public static function createGroup( $gid ) { - OC_Log::write('OC_GROUP_DJANGO_AUTH', 'Use the django webinterface to create groups',3); + OC_Log::write('OC_Group_Django', 'Use the django webinterface to create groups',3); return OC_USER_BACKEND_NOT_IMPLEMENTED; } /** - * @brief delete a group - * @param $gid gid of the group to delete - * @returns true/false - * - * Deletes a group and removes it from the group_user-table - */ + * @brief delete a group + * @param $gid gid of the group to delete + * @returns true/false + * + * Deletes a group and removes it from the group_user-table + */ public static function deleteGroup( $gid ) { - OC_Log::write('OC_GROUP_DJANGO_AUTH', 'Use the django webinterface to delete groups',3); + OC_Log::write('OC_Group_Django', 'Use the django webinterface to delete groups',3); return OC_USER_BACKEND_NOT_IMPLEMENTED; } /** - * @brief is user in group? - * @param $uid uid of the user - * @param $gid gid of the group - * @returns true/false - * - * Checks whether the user is member of a group or not. - */ + * @brief is user in group? + * @param $uid uid of the user + * @param $gid gid of the group + * @returns true/false + * + * Checks whether the user is member of a group or not. + */ public static function inGroup( $uid, $gid ) { // Special case for the admin group if ($gid =='admin') { @@ -112,39 +112,39 @@ class OC_GROUP_DJANGO_AUTH extends OC_Group_Backend { } /** - * @brief Add a user to a group - * @param $uid Name of the user to add to group - * @param $gid Name of the group in which add the user - * @returns true/false - * - * Adds a user to a group. - */ + * @brief Add a user to a group + * @param $uid Name of the user to add to group + * @param $gid Name of the group in which add the user + * @returns true/false + * + * Adds a user to a group. + */ public static function addToGroup( $uid, $gid ){ - OC_Log::write('OC_GROUP_DJANGO_AUTH', 'Use the django webinterface to add users to groups',3); + OC_Log::write('OC_Group_Django', 'Use the django webinterface to add users to groups',3); return OC_USER_BACKEND_NOT_IMPLEMENTED; } /** - * @brief Removes a user from a group - * @param $uid Name of the user to remove from group - * @param $gid Name of the group from which remove the user - * @returns true/false - * - * removes the user from a group. - */ + * @brief Removes a user from a group + * @param $uid Name of the user to remove from group + * @param $gid Name of the group from which remove the user + * @returns true/false + * + * removes the user from a group. + */ public static function removeFromGroup( $uid, $gid ){ - OC_Log::write('OC_GROUP_DJANGO_AUTH', 'Use the django webinterface to remove users from groups',3); + OC_Log::write('OC_Group_Django', 'Use the django webinterface to remove users from groups',3); return OC_USER_BACKEND_NOT_IMPLEMENTED; } /** - * @brief Get all groups a user belongs to - * @param $uid Name of the user - * @returns array with group names - * - * This function fetches all groups a user belongs to. It does not check - * if the user exists at all. - */ + * @brief Get all groups a user belongs to + * @param $uid Name of the user + * @returns array with group names + * + * This function fetches all groups a user belongs to. It does not check + * if the user exists at all. + */ public static function getUserGroups( $uid ){ $query = OC_DB::prepare( 'SELECT `auth_group`.`name` FROM `auth_group` @@ -161,11 +161,11 @@ INNER JOIN `auth_user` ON ( `auth_user`.`id` = `auth_user_groups`.`use } /** - * @brief get a list of all groups - * @returns array with group names - * - * Returns a list with all groups - */ + * @brief get a list of all groups + * @returns array with group names + * + * Returns a list with all groups + */ public static function getGroups(){ $query = OC_DB::prepare( "SELECT id, name FROM auth_group ORDER BY name" ); $result = $query->execute(); @@ -178,9 +178,9 @@ INNER JOIN `auth_user` ON ( `auth_user`.`id` = `auth_user_groups`.`use } /** - * @brief get a list of all users in a group - * @returns array with user ids - */ + * @brief get a list of all users in a group + * @returns array with user ids + */ public static function usersInGroup($gid) { $query = OC_DB::prepare('SELECT `auth_user`.`username` FROM `auth_user` diff --git a/django_auth/lib/user.php b/django_auth/lib/user.php index 977165758..6d977be25 100644 --- a/django_auth/lib/user.php +++ b/django_auth/lib/user.php @@ -4,7 +4,7 @@ * ownCloud - Django Authentification Backend * * @author Florian Reinhard - * @copyright 2011 Florian Reinhard <florian.reinhard@googlemail.com> + * @copyright 2012 Florian Reinhard <florian.reinhard@googlemail.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE @@ -24,63 +24,70 @@ require_once('phpsec.crypt.php'); /** - * @brief Class providing django users to ownCloud - * @see http://www.djangoproject.com - * - * Authentification backend to authenticate agains a django webapplication using - * django.contrib.auth. - */ -class OC_USER_DJANGO_AUTH extends OC_User_Backend { +* @brief Class providing django users to ownCloud +* @see http://www.djangoproject.com +* +* Authentification backend to authenticate agains a django webapplication using +* django.contrib.auth. +*/ +class OC_User_Django extends OC_User_Backend { /** - * @brief Create a new user - * @param $uid The username of the user to create - * @param $password The password of the new user - * @returns true/false - * - * Creates a new user. Basic checking of username is done in OC_User - * itself, not in its subclasses. - */ + * @brief Create a new user + * @param $uid The username of the user to create + * @param $password The password of the new user + * @returns true/false + * + * Creates a new user. Basic checking of username is done in OC_User + * itself, not in its subclasses. + */ public function createUser($uid, $password){ - OC_Log::write('OC_USER_DJANGO_AUTH', 'Use the django webinterface to create users',3); + OC_Log::write('OC_User_Django', 'Use the django webinterface to create users',3); return OC_USER_BACKEND_NOT_IMPLEMENTED; } /** - * @brief delete a user - * @param $uid The username of the user to delete - * @returns true/false - * - * Deletes a user - */ + * @brief delete a user + * @param $uid The username of the user to delete + * @returns true/false + * + * Deletes a user + */ public function deleteUser( $uid ){ - OC_Log::write('OC_USER_DJANGO_AUTH', 'Use the django webinterface to delete users',3); + OC_Log::write('OC_User_Django', 'Use the django webinterface to delete users',3); return OC_USER_BACKEND_NOT_IMPLEMENTED; } /** - * @brief Set password - * @param $uid The username - * @param $password The new password - * @returns true/false - * - * Change the password of a user - */ + * @brief Set password + * @param $uid The username + * @param $password The new password + * @returns true/false + * + * Change the password of a user + */ public function setPassword($uid, $password){ - OC_Log::write('OC_USER_DJANGO_AUTH', 'Use the django webinterface to change passwords',3); + OC_Log::write('OC_User_Django', 'Use the django webinterface to change passwords',3); return OC_USER_BACKEND_NOT_IMPLEMENTED; } /** - * @brief Check if the password is correct - * @param $uid The username - * @param $password The password - * @returns true/false - * - * Check if the password is correct without logging in the user - */ + * @brief Helper function for checkPassword + * @param $str The String to be searched + * @param $sub The String to be found + * @returns true/false + */ private function beginsWith($str,$sub){ return ( substr( $str, 0, strlen( $sub ) ) === $sub ); } + + /** + * @brief Check if the password is correct + * @param $uid The username + * @param $password The password + * @returns true/false + * + * Check if the password is correct without logging in the user + */ public function checkPassword($uid, $password){ $query = OC_DB::prepare( 'SELECT username, password FROM auth_user WHERE username = ?' ); $result = $query->execute( array( $uid)); @@ -104,17 +111,22 @@ class OC_USER_DJANGO_AUTH extends OC_User_Backend { $salt = $chunks[2]; $hash = $chunks[3]; - if ($algorithm === 'sha1') + if ($algorithm === 'sha1') { $digest_size = 20; - elseif ($algorithm === 'sha256') + } + elseif ($algorithm === 'sha256') { $digest_size = 32; - else + } + else { return false; + } - if (base64_encode (phpsecCrypt::pbkdf2($password, $salt, $iter, $digest_size, $algorithm)) === $hash) + if (base64_encode (phpsecCrypt::pbkdf2($password, $salt, $iter, $digest_size, $algorithm)) === $hash) { return $uid; - else + } + else { return false; + } } } else { @@ -123,11 +135,11 @@ class OC_USER_DJANGO_AUTH extends OC_User_Backend { } /** - * @brief Get a list of all users - * @returns array with all active usernames - * - * Get a list of all users. - */ + * @brief Get a list of all users + * @returns array with all active usernames + * + * Get a list of all users. + */ public function getUsers(){ $query = OC_DB::prepare( 'SELECT id, username, is_active FROM `auth_user` WHERE is_active=1 ORDER BY username' ); $result = $query->execute(); @@ -139,10 +151,10 @@ class OC_USER_DJANGO_AUTH extends OC_User_Backend { } /** - * @brief check if a user exists - * @param string $uid the username - * @return boolean - */ + * @brief check if a user exists + * @param string $uid the username + * @return boolean + */ public function userExists($uid){ $query = OC_DB::prepare( 'SELECT username FROM `auth_user` WHERE username = ? AND is_active=1' ); $result = $query->execute( array( $uid )); diff --git a/django_auth/settings.php b/django_auth/settings.php index 36656f5ce..8b0a841ef 100644 --- a/django_auth/settings.php +++ b/django_auth/settings.php @@ -3,7 +3,7 @@ * ownCloud - Django Authentification Backend * * @author Florian Reinhard - * @copyright 2011 Florian Reinhard <florian.reinhard@googlemail.com> + * @copyright 2012 Florian Reinhard <florian.reinhard@googlemail.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE |