diff options
-rw-r--r-- | core/templates/installation.php | 26 | ||||
-rw-r--r-- | core/templates/login.php | 8 | ||||
-rw-r--r-- | lib/private/preferences.php | 123 | ||||
-rw-r--r-- | settings/templates/personal.php | 14 | ||||
-rw-r--r-- | tests/lib/preferences.php | 52 |
5 files changed, 118 insertions, 105 deletions
diff --git a/core/templates/installation.php b/core/templates/installation.php index 9670a5e9ee5..d3adb34f412 100644 --- a/core/templates/installation.php +++ b/core/templates/installation.php @@ -48,13 +48,15 @@ <legend><?php print_unescaped($l->t( 'Create an <strong>admin account</strong>' )); ?></legend> <p class="infield grouptop"> <input type="text" name="adminlogin" id="adminlogin" placeholder="" - value="<?php p($_['adminlogin']); ?>" autocomplete="off" autofocus required /> + value="<?php p($_['adminlogin']); ?>" + autocomplete="off" autocapitalize="off" autocorrect="off" autofocus required /> <label for="adminlogin" class="infield"><?php p($l->t( 'Username' )); ?></label> <img class="svg" src="<?php p(image_path('', 'actions/user.svg')); ?>" alt="" /> </p> <p class="infield groupbottom"> <input type="password" name="adminpass" data-typetoggle="#show" id="adminpass" placeholder="" - value="<?php p($_['adminpass']); ?>" required /> + value="<?php p($_['adminpass']); ?>" + autocomplete="off" autocapitalize="off" autocorrect="off" required /> <label for="adminpass" class="infield"><?php p($l->t( 'Password' )); ?></label> <img class="svg" id="adminpass-icon" src="<?php print_unescaped(image_path('', 'actions/password.svg')); ?>" alt="" /> <input type="checkbox" id="show" name="show" /> @@ -74,8 +76,9 @@ <div id="datadirContent"> <label for="directory"><?php p($l->t( 'Data folder' )); ?></label> <input type="text" name="directory" id="directory" - placeholder="<?php p(OC::$SERVERROOT."/data"); ?>" - value="<?php p($_['directory']); ?>" /> + placeholder="<?php p(OC::$SERVERROOT.'/data'); ?>" + value="<?php p($_['directory']); ?>" + autocomplete="off" autocapitalize="off" autocorrect="off" /> </div> </fieldset> <?php endif; ?> @@ -103,11 +106,13 @@ <p class="infield grouptop"> <label for="dbuser" class="infield"><?php p($l->t( 'Database user' )); ?></label> <input type="text" name="dbuser" id="dbuser" placeholder="" - value="<?php p($_['dbuser']); ?>" autocomplete="off" /> + value="<?php p($_['dbuser']); ?>" + autocomplete="off" autocapitalize="off" autocorrect="off" /> </p> <p class="infield groupmiddle"> <input type="password" name="dbpass" id="dbpass" placeholder="" data-typetoggle="#dbpassword" - value="<?php p($_['dbpass']); ?>" /> + value="<?php p($_['dbpass']); ?>" + autocomplete="off" autocapitalize="off" autocorrect="off" /> <label for="dbpass" class="infield"><?php p($l->t( 'Database password' )); ?></label> <input type="checkbox" id="dbpassword" name="dbpassword" /> <label for="dbpassword"></label> @@ -116,21 +121,24 @@ <label for="dbname" class="infield"><?php p($l->t( 'Database name' )); ?></label> <input type="text" name="dbname" id="dbname" placeholder="" value="<?php p($_['dbname']); ?>" - autocomplete="off" pattern="[0-9a-zA-Z$_-]+" /> + autocomplete="off" autocapitalize="off" autocorrect="off" + pattern="[0-9a-zA-Z$_-]+" /> </p> <?php if($_['hasOracle']): ?> <div id="use_oracle_db"> <p class="infield groupmiddle"> <label for="dbtablespace" class="infield"><?php p($l->t( 'Database tablespace' )); ?></label> <input type="text" name="dbtablespace" id="dbtablespace" placeholder="" - value="<?php p($_['dbtablespace']); ?>" autocomplete="off" /> + value="<?php p($_['dbtablespace']); ?>" + autocomplete="off" autocapitalize="off" autocorrect="off" /> </p> </div> <?php endif; ?> <p class="infield groupbottom"> <label for="dbhost" class="infield"><?php p($l->t( 'Database host' )); ?></label> <input type="text" name="dbhost" id="dbhost" placeholder="" - value="<?php p($_['dbhost']); ?>" /> + value="<?php p($_['dbhost']); ?>" + autocomplete="off" autocapitalize="off" autocorrect="off" /> </p> </div> <?php endif; ?> diff --git a/core/templates/login.php b/core/templates/login.php index e697ebe5326..b534e1edea5 100644 --- a/core/templates/login.php +++ b/core/templates/login.php @@ -26,15 +26,17 @@ </p> <p class="infield grouptop"> <input type="text" name="user" id="user" placeholder="" - value="<?php p($_['username']); ?>"<?php p($_['user_autofocus'] ? ' autofocus' : ''); ?> - autocomplete="on" required/> + value="<?php p($_['username']); ?>" + <?php p($_['user_autofocus'] ? 'autofocus' : ''); ?> + autocomplete="on" autocapitalize="off" autocorrect="off" required /> <label for="user" class="infield"><?php p($l->t('Username')); ?></label> <img class="svg" src="<?php print_unescaped(image_path('', 'actions/user.svg')); ?>" alt=""/> </p> <p class="infield groupbottom"> <input type="password" name="password" id="password" value="" placeholder="" - required<?php p($_['user_autofocus'] ? '' : ' autofocus'); ?> /> + <?php p($_['user_autofocus'] ? '' : 'autofocus'); ?> + autocomplete="on" autocapitalize="off" autocorrect="off" required /> <label for="password" class="infield"><?php p($l->t('Password')); ?></label> <img class="svg" id="password-icon" src="<?php print_unescaped(image_path('', 'actions/password.svg')); ?>" alt=""/> </p> diff --git a/lib/private/preferences.php b/lib/private/preferences.php index 359d9a83589..7ebbf7aa970 100644 --- a/lib/private/preferences.php +++ b/lib/private/preferences.php @@ -43,8 +43,26 @@ use \OC\DB\Connection; * This class provides an easy way for storing user preferences. */ class Preferences { + /** + * @var \OC\DB\Connection + */ protected $conn; + /** + * 3 dimensional array with the following structure: + * [ $userId => + * [ $appId => + * [ $key => $value ] + * ] + * ] + * + * @var array $cache + */ + protected $cache = array(); + + /** + * @param \OC\DB\Connection $conn + */ public function __construct(Connection $conn) { $this->conn = $conn; } @@ -58,10 +76,10 @@ class Preferences { */ public function getUsers() { $query = 'SELECT DISTINCT `userid` FROM `*PREFIX*preferences`'; - $result = $this->conn->executeQuery( $query ); + $result = $this->conn->executeQuery($query); $users = array(); - while( $userid = $result->fetchColumn()) { + while ($userid = $result->fetchColumn()) { $users[] = $userid; } @@ -69,6 +87,28 @@ class Preferences { } /** + * @param string $user + * @return array[] + */ + protected function getUserValues($user) { + if (isset($this->cache[$user])) { + return $this->cache[$user]; + } + $data = array(); + $query = 'SELECT `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?'; + $result = $this->conn->executeQuery($query, array($user)); + while ($row = $result->fetch()) { + $app = $row['appid']; + if (!isset($data[$app])) { + $data[$app] = array(); + } + $data[$app][$row['configkey']] = $row['configvalue']; + } + $this->cache[$user] = $data; + return $data; + } + + /** * @brief Get all apps of an user * @param string $user user * @return array with app ids @@ -76,16 +116,9 @@ class Preferences { * This function returns a list of all apps of the user that have at least * one entry in the preferences table. */ - public function getApps( $user ) { - $query = 'SELECT DISTINCT `appid` FROM `*PREFIX*preferences` WHERE `userid` = ?'; - $result = $this->conn->executeQuery( $query, array( $user ) ); - - $apps = array(); - while( $appid = $result->fetchColumn()) { - $apps[] = $appid; - } - - return $apps; + public function getApps($user) { + $data = $this->getUserValues($user); + return array_keys($data); } /** @@ -97,16 +130,13 @@ class Preferences { * This function gets all keys of an app of an user. Please note that the * values are not returned. */ - public function getKeys( $user, $app ) { - $query = 'SELECT `configkey` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ?'; - $result = $this->conn->executeQuery( $query, array( $user, $app )); - - $keys = array(); - while( $key = $result->fetchColumn()) { - $keys[] = $key; + public function getKeys($user, $app) { + $data = $this->getUserValues($user); + if (isset($data[$app])) { + return array_keys($data[$app]); + } else { + return array(); } - - return $keys; } /** @@ -120,13 +150,10 @@ class Preferences { * This function gets a value from the preferences table. If the key does * not exist the default value will be returned */ - public function getValue( $user, $app, $key, $default = null ) { - // Try to fetch the value, return default if not exists. - $query = 'SELECT `configvalue` FROM `*PREFIX*preferences`' - .' WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'; - $row = $this->conn->fetchAssoc( $query, array( $user, $app, $key )); - if($row) { - return $row["configvalue"]; + public function getValue($user, $app, $key, $default = null) { + $data = $this->getUserValues($user); + if (isset($data[$app]) and isset($data[$app][$key])) { + return $data[$app][$key]; } else { return $default; } @@ -142,14 +169,14 @@ class Preferences { * Adds a value to the preferences. If the key did not exist before, it * will be added automagically. */ - public function setValue( $user, $app, $key, $value ) { + public function setValue($user, $app, $key, $value) { // Check if the key does exist $query = 'SELECT COUNT(*) FROM `*PREFIX*preferences`' - .' WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'; - $count = $this->conn->fetchColumn( $query, array( $user, $app, $key )); + . ' WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'; + $count = $this->conn->fetchColumn($query, array($user, $app, $key)); $exists = $count > 0; - if( !$exists ) { + if (!$exists) { $data = array( 'userid' => $user, 'appid' => $app, @@ -168,6 +195,14 @@ class Preferences { ); $this->conn->update('*PREFIX*preferences', $data, $where); } + + // only add to the cache if we already loaded data for the user + if (isset($this->cache[$user])) { + if (!isset($this->cache[$user][$app])) { + $this->cache[$user][$app] = array(); + } + $this->cache[$user][$app][$key] = $value; + } } /** @@ -178,13 +213,17 @@ class Preferences { * * Deletes a key. */ - public function deleteKey( $user, $app, $key ) { + public function deleteKey($user, $app, $key) { $where = array( 'userid' => $user, 'appid' => $app, 'configkey' => $key, ); $this->conn->delete('*PREFIX*preferences', $where); + + if (isset($this->cache[$user]) and isset($this->cache[$user][$app])) { + unset($this->cache[$user][$app][$key]); + } } /** @@ -194,12 +233,16 @@ class Preferences { * * Removes all keys in preferences belonging to the app and the user. */ - public function deleteApp( $user, $app ) { + public function deleteApp($user, $app) { $where = array( 'userid' => $user, 'appid' => $app, ); $this->conn->delete('*PREFIX*preferences', $where); + + if (isset($this->cache[$user])) { + unset($this->cache[$user][$app]); + } } /** @@ -208,11 +251,13 @@ class Preferences { * * Removes all keys in preferences belonging to the user. */ - public function deleteUser( $user ) { + public function deleteUser($user) { $where = array( 'userid' => $user, ); $this->conn->delete('*PREFIX*preferences', $where); + + unset($this->cache[$user]); } /** @@ -221,12 +266,16 @@ class Preferences { * * Removes all keys in preferences belonging to the app. */ - public function deleteAppFromAllUsers( $app ) { + public function deleteAppFromAllUsers($app) { $where = array( 'appid' => $app, ); $this->conn->delete('*PREFIX*preferences', $where); + + foreach ($this->cache as &$userCache) { + unset($userCache[$app]); + } } } -require_once __DIR__.'/legacy/'.basename(__FILE__); +require_once __DIR__ . '/legacy/' . basename(__FILE__); diff --git a/settings/templates/personal.php b/settings/templates/personal.php index 31ae3a991b6..188ff75f96b 100644 --- a/settings/templates/personal.php +++ b/settings/templates/personal.php @@ -40,10 +40,12 @@ if($_['passwordChangeSupported']) { <div id="passwordchanged"><?php echo $l->t('Your password was changed');?></div> <div id="passworderror"><?php echo $l->t('Unable to change your password');?></div> <input type="password" id="pass1" name="oldpassword" - placeholder="<?php echo $l->t('Current password');?>" autocomplete="off" /> + placeholder="<?php echo $l->t('Current password');?>" + autocomplete="off" autocapitalize="off" autocorrect="off" /> <input type="password" id="pass2" name="personal-password" placeholder="<?php echo $l->t('New password');?>" - data-typetoggle="#personal-show" autocomplete="off" /> + data-typetoggle="#personal-show" + autocomplete="off" autocapitalize="off" autocorrect="off" /> <input type="checkbox" id="personal-show" name="show" /><label for="personal-show"></label> <input id="passwordbutton" type="submit" value="<?php echo $l->t('Change password');?>" /> <br/> @@ -60,7 +62,9 @@ if($_['displayNameChangeSupported']) { <form id="displaynameform"> <fieldset class="personalblock"> <h2><?php echo $l->t('Full Name');?></h2> - <input type="text" id="displayName" name="displayName" value="<?php p($_['displayName'])?>" /> + <input type="text" id="displayName" name="displayName" + value="<?php p($_['displayName'])?>" + autocomplete="on" autocapitalize="off" autocorrect="off" /> <span class="msg"></span> <input type="hidden" id="oldDisplayName" name="oldDisplayName" value="<?php p($_['displayName'])?>" /> </fieldset> @@ -76,7 +80,9 @@ if($_['passwordChangeSupported']) { <fieldset class="personalblock"> <h2><?php p($l->t('Email'));?></h2> <input type="text" name="email" id="email" value="<?php p($_['email']); ?>" - placeholder="<?php p($l->t('Your email address'));?>" /><span class="msg"></span><br /> + placeholder="<?php p($l->t('Your email address'));?>" + autocomplete="on" autocapitalize="off" autocorrect="off" /> + <span class="msg"></span><br /> <em><?php p($l->t('Fill in an email address to enable password recovery'));?></em> </fieldset> </form> diff --git a/tests/lib/preferences.php b/tests/lib/preferences.php index a8236909ded..f1f6ed08003 100644 --- a/tests/lib/preferences.php +++ b/tests/lib/preferences.php @@ -144,58 +144,6 @@ class Test_Preferences_Object extends PHPUnit_Framework_TestCase { $this->assertEquals(array('foo'), $apps); } - public function testGetApps() - { - $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false); - $statementMock->expects($this->exactly(2)) - ->method('fetchColumn') - ->will($this->onConsecutiveCalls('foo', false)); - $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); - $connectionMock->expects($this->once()) - ->method('executeQuery') - ->with($this->equalTo('SELECT DISTINCT `appid` FROM `*PREFIX*preferences` WHERE `userid` = ?'), - $this->equalTo(array('bar'))) - ->will($this->returnValue($statementMock)); - - $preferences = new OC\Preferences($connectionMock); - $apps = $preferences->getApps('bar'); - $this->assertEquals(array('foo'), $apps); - } - - public function testGetKeys() - { - $statementMock = $this->getMock('\Doctrine\DBAL\Statement', array(), array(), '', false); - $statementMock->expects($this->exactly(2)) - ->method('fetchColumn') - ->will($this->onConsecutiveCalls('foo', false)); - $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); - $connectionMock->expects($this->once()) - ->method('executeQuery') - ->with($this->equalTo('SELECT `configkey` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ?'), - $this->equalTo(array('bar', 'moo'))) - ->will($this->returnValue($statementMock)); - - $preferences = new OC\Preferences($connectionMock); - $keys = $preferences->getKeys('bar', 'moo'); - $this->assertEquals(array('foo'), $keys); - } - - public function testGetValue() - { - $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); - $connectionMock->expects($this->exactly(2)) - ->method('fetchAssoc') - ->with($this->equalTo('SELECT `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?'), - $this->equalTo(array('grg', 'bar', 'red'))) - ->will($this->onConsecutiveCalls(array('configvalue'=>'foo'), null)); - - $preferences = new OC\Preferences($connectionMock); - $value = $preferences->getValue('grg', 'bar', 'red'); - $this->assertEquals('foo', $value); - $value = $preferences->getValue('grg', 'bar', 'red', 'def'); - $this->assertEquals('def', $value); - } - public function testSetValue() { $connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false); |