diff --git a/ajax/settings.php b/ajax/settings.php new file mode 100644 index 0000000..08adf92 --- /dev/null +++ b/ajax/settings.php @@ -0,0 +1,39 @@ + array( "message" => $l->t("Not submitted for us.") ))); + return false; +} + +OCP\JSON::success(array('data' => array( 'message' => $l->t('Application settings successfully stored.') ))); +return true; diff --git a/appinfo/info.xml b/appinfo/info.xml index 021ef38..8bf8439 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -6,7 +6,7 @@ AGPL Andreas Boehler <andreas (at) aboehler (dot) at > - 4.9 + 5.0 false diff --git a/appinfo/version b/appinfo/version index a3df0a6..f374f66 100644 --- a/appinfo/version +++ b/appinfo/version @@ -1 +1 @@ -0.8.0 +0.9.1 diff --git a/css/settings.css b/css/settings.css new file mode 100644 index 0000000..9c45085 --- /dev/null +++ b/css/settings.css @@ -0,0 +1,14 @@ +.statusmessage { + background-color: #DDDDFF; +} +.errormessage { + background-color: #FFDDDD; +} +.successmessage { + background-color: #DDFFDD; +} +.statusmessage,.errormessage,.successmessage{ + display:none; + padding: 1; +} + diff --git a/js/settings.js b/js/settings.js index 8337712..ad8d982 100644 --- a/js/settings.js +++ b/js/settings.js @@ -1 +1,45 @@ -// +// declare namespace +var user_sql = user_sql || {}; + +/** + * init admin settings view + */ +user_sql.adminSettingsUI = function() { + + if ($('#sql').length > 0) { + // enable tabs on settings page + $('#sql').tabs(); + + $('#sqlSubmit').click(function(event) { + event.preventDefault(); + + var self = $(this); + var post = $('#sqlForm').serialize(); + $('#sql_update_message').show(); + $('#sql_success_message').hide(); + $('#sql_error_message').hide(); + // Ajax foobar + $.post(OC.filePath('user_sql', 'ajax', 'settings.php'), post, function(data) { + $('#sql_update_message').hide(); + if (data.status == 'success') { + $('#sql_success_message').html(data.data.message); + $('#sql_success_message').show(); + window.setTimeout(function() { + $('#sql_success_message').hide(); + }, 10000); + } else { + $('#sql_error_message').html(data.data.message); + $('#sql_error_message').show(); + } + }, 'json'); + return false; + }); + } +} + +$(document).ready(function() { + if ($('#sql')) { + user_sql.adminSettingsUI(); + } +}); + diff --git a/settings.php b/settings.php index f6f1ff3..c140ad9 100644 --- a/settings.php +++ b/settings.php @@ -20,11 +20,16 @@ * License along with this library. If not, see . * */ -$params = array('sql_host', 'sql_user', 'sql_database', 'sql_password', 'sql_table', 'sql_column_username', 'sql_column_password', 'sql_type', 'sql_column_active', 'strip_domain', 'default_domain', 'crypt_type'); +$params = array('sql_host', 'sql_user', 'sql_database', 'sql_password', + 'sql_table', 'sql_column_username', 'sql_column_password', + 'sql_type', 'sql_column_active', 'strip_domain', 'default_domain', + 'crypt_type', 'sql_column_displayname'); -OCP\Util::addscript('user_sql', 'settings'); +OCP\Util::addStyle('user_sql', 'settings'); +OCP\Util::addScript('user_sql', 'settings'); OCP\User::checkAdminUser(); +/* if ($_POST) { OCP\JSON::callCheck(); foreach($params as $param){ @@ -38,6 +43,7 @@ if ($_POST) { } } } +*/ // fill template $tmpl = new OCP\Template( 'user_sql', 'settings'); @@ -59,5 +65,11 @@ $tmpl->assign( 'sql_column_active', OCP\Config::getAppValue( 'user_sql', 'sql_co $tmpl->assign( 'strip_domain', OCP\Config::getAppValue( 'user_sql', 'strip_domain', 0)); $tmpl->assign( 'default_domain', OCP\Config::getAppValue( 'user_sql', 'default_domain', '')); $tmpl->assign( 'crypt_type', OCP\Config::getAppValue( 'user_sql', 'crypt_type', 'mysql_encrypt')); +$tmpl->assign( 'sql_column_displayname', OCP\Config::getAppValue( 'user_sql', 'sql_column_displayname', '')); + +// workaround to detect OC version +$ocVersion = @reset(OCP\Util::getVersion()); +$tmpl->assign('ocVersion', $ocVersion); + return $tmpl->fetchPage(); diff --git a/templates/settings.php b/templates/settings.php index 05529d9..9e0c1d1 100644 --- a/templates/settings.php +++ b/templates/settings.php @@ -1,9 +1,24 @@ -
-
- t('SQL'); ?> -

+= 7 ? 'section' : 'personalblock'; + +?> + + + + +

+ t('SQL'); ?> + + +
+ + 'MySQL', 'pgsql' => 'PostgreSQL');?> - + -

-

-

-

-

-

-

-

+

+ + + + +
-

+
+
+
+ + + + + 'MD5', 'md5crypt' => 'MD5 Crypt', 'cleartext' => 'Cleartext', 'mysql_encrypt' => 'mySQL ENCRYPT()', 'system' => 'System (crypt)', 'mysql_password' => 'mySQL PASSWORD()', 'joomla' => 'Joomla MD5 Encryption');?> - + + + + +
-

-

-

title="Strip Domain Part from Username when logging in and retrieving username lists">

-

+
title="Strip Domain Part from Username when logging in and retrieving username lists">
+
- -
+ + +
t('Saving...'); ?>
+
+
+
diff --git a/user_sql.php b/user_sql.php index 2a58067..b720c26 100644 --- a/user_sql.php +++ b/user_sql.php @@ -36,6 +36,7 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface { protected $sql_column_username; protected $sql_column_password; protected $sql_column_active; + protected $sql_column_displayname; protected $sql_type; protected $db_conn; protected $db; @@ -54,6 +55,7 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface { $this->sql_table = OCP\Config::getAppValue('user_sql', 'sql_table', ''); $this->sql_column_username = OCP\Config::getAppValue('user_sql', 'sql_column_username', ''); $this->sql_column_password = OCP\Config::getAppValue('user_sql', 'sql_column_password', ''); + $this->sql_column_displayname = OCP\Config::getAppValue('user_sql', 'sql_column_displayname', ''); $this->sql_column_active = OCP\Config::getAppValue('user_sql', 'sql_column_active', ''); $this->sql_type = OCP\Config::getAppValue('user_sql', 'sql_type', ''); $this->default_domain = OCP\Config::getAppValue('user_sql', 'default_domain', ''); @@ -74,7 +76,11 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface { public function implementsAction($actions) { - return (bool)((OC_USER_BACKEND_CHECK_PASSWORD) & $actions); + return (bool)((OC_USER_BACKEND_CHECK_PASSWORD | OC_USER_BACKEND_GET_DISPLAYNAME) & $actions); + } + + public function hasUserListings() { + return true; } public function createUser() { @@ -271,9 +277,9 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface { public function userExists($uid) { - $cacheKey = 'sql_user_exists_' . $uid; - $cacheVal = $this->cache->get($cacheKey); - if(! is_null($cacheVal) ) return (bool) $cacheVal; + $cacheKey = 'sql_user_exists_' . $uid; + $cacheVal = $this->cache->get($cacheKey); + if(! is_null($cacheVal) ) return (bool) $cacheVal; OC_Log::write('OC_USER_SQL', "Entering userExists() for UID: $uid", OC_Log::DEBUG); if(!$this->db_conn) @@ -287,10 +293,6 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface { } $uid = strtolower($uid); - if ($uid === $cached_exists) { - OC_Log::write('OC_USER_SQL', "User exists (using cache), return true", OC_Log::DEBUG); - return true; - } $query = "SELECT $this->sql_column_username FROM $this->sql_table WHERE $this->sql_column_username = :uid"; if($this->sql_column_active != '') $query .= " AND $this->sql_column_active = 1"; @@ -306,8 +308,8 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface { } OC_Log::write('OC_USER_SQL', "Fetching results...", OC_Log::DEBUG); - $exists = (bool)$result->fetch(); - $this->cache->set($cacheKey, $exists, 60); + $exists = (bool)$result->fetch(); + $this->cache->set($cacheKey, $exists, 60); if(!$exists) { @@ -317,10 +319,68 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface { else { OC_Log::write('OC_USER_SQL', "User exists, return true", OC_Log::DEBUG); - $cached_exists = $uid; return true; } + } + + public function getDisplayName($uid) + { + OC_Log::write('OC_USER_SQL', "Entering getDisplayName() for UID: $uid", OC_Log::DEBUG); + if(!$this->db_conn) + { + return false; + } + $uid = trim($uid); + if($this->default_domain && (strpos($uid, '@') === false)) + { + $uid .= "@".$this->default_domain; + } + $uid = strtolower($uid); + + if(!$this->userExists($uid)) + { + return false; + } + + $query = "SELECT $this->sql_column_displayname FROM $this->sql_table WHERE $this->sql_column_username = :uid"; + if($this->sql_column_active != '') + $query .= " AND $this->sql_column_active = 1"; + OC_Log::write('OC_USER_SQL', "Preparing query: $query", OC_Log::DEBUG); + $result = $this->db->prepare($query); + $result->bindParam(":uid", $uid); + OC_Log::write('OC_USER_SQL', "Executing query...", OC_Log::DEBUG); + if(!$result->execute()) + { + $err = $result->errorInfo(); + OC_Log::write('OC_USER_SQL', "Query failed: ".$err[2], OC_Log::DEBUG); + return false; + } + OC_Log::write('OC_USER_SQL', "Fetching results...", OC_Log::DEBUG); + $row = $result->fetch(); + if(!$row) + { + OC_Log::write('OC_USER_SQL', "Empty row, user has no display name or does not exist, return false", OC_Log::DEBUG); + return false; + } + else + { + OC_Log::write('OC_USER_SQL', "User exists, return true", OC_Log::DEBUG); + $displayName = utf8_encode($row[$this->sql_column_displayname]); + return $displayName;; + } + return false; + } + + public function getDisplayNames($search = '', $limit = null, $offset = null) + { + $uids = $this->getUsers($search, $limit, $offset); + $displayNames = array(); + foreach($uids as $uid) + { + $displayNames[$uid] = $this->getDisplayName($uid); + } + return $displayNames; } /**