diff options
author | adrien <adrien.waksberg@believedigital.com> | 2014-03-06 22:34:43 +0100 |
---|---|---|
committer | adrien <adrien.waksberg@believedigital.com> | 2014-03-06 22:34:43 +0100 |
commit | 5cdfc56867d0fe8dc5be9e2112c53e3ddf212104 (patch) | |
tree | db331a3c76d78c221caa001145616f95da6ec7c2 /lib | |
parent | dde4f2f91720a5eb4ad7db4fdb15dfc115f0e8c0 (diff) | |
download | nextcloud-server-5cdfc56867d0fe8dc5be9e2112c53e3ddf212104.tar.gz nextcloud-server-5cdfc56867d0fe8dc5be9e2112c53e3ddf212104.zip |
update the cache when add user
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/user/database.php | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/lib/private/user/database.php b/lib/private/user/database.php index 1e3d457eb50..bbd72fc65e7 100644 --- a/lib/private/user/database.php +++ b/lib/private/user/database.php @@ -39,15 +39,14 @@ require_once 'phpass/PasswordHash.php'; * Class for user management in a SQL Database (e.g. MySQL, SQLite) */ class OC_User_Database extends OC_User_Backend { - - protected static $cache = array(); - protected static $cache_complete = true; - /** * @var PasswordHash */ private static $hasher = null; + protected static $cache = array(); + protected static $cache_complete = false; + private function getHasher() { if (!self::$hasher) { //we don't want to use DES based crypt(), since it doesn't return a hash with a recognisable prefix @@ -68,16 +67,19 @@ class OC_User_Database extends OC_User_Backend { * itself, not in its subclasses. */ public function createUser($uid, $password) { - if ($this->userExists($uid)) { - return false; - } else { + if (!$this->userExists($uid)) { $hasher = $this->getHasher(); $hash = $hasher->HashPassword($password . OC_Config::getValue('passwordsalt', '')); $query = OC_DB::prepare('INSERT INTO `*PREFIX*users` ( `uid`, `password` ) VALUES( ?, ? )'); $result = $query->execute(array($uid, $hash)); - - return $result ? true : false; + + if ($result) { + self::$cache[$uid]['uid'] = $uid; + return true; + } } + + return false; } /** @@ -127,10 +129,11 @@ class OC_User_Database extends OC_User_Backend { if ($this->userExists($uid)) { $query = OC_DB::prepare('UPDATE `*PREFIX*users` SET `displayname` = ? WHERE LOWER(`uid`) = ?'); $query->execute(array($displayName, $uid)); + self::$cache[$uid]['displayname'] = $displayName; return true; - } else { - return false; } + + return false; } /** @@ -140,8 +143,8 @@ class OC_User_Database extends OC_User_Backend { */ public function getDisplayName($uid) { $this->loadUser($uid); - if (!empty(self::$cache['uid']['displayname'])) { - return self::$cache['uid']['displayname']; + if (!empty(self::$cache[$uid]['displayname'])) { + return self::$cache[$uid]['displayname']; } else { return $uid; } |