mirror of
https://github.com/moparisthebest/user_sql
synced 2024-08-13 16:53:48 -04:00
Merge branch oc5 and improve OC7 compatibility
This commit is contained in:
commit
e2773e06ae
39
ajax/settings.php
Normal file
39
ajax/settings.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// Init owncloud
|
||||||
|
|
||||||
|
// Check if we are a user
|
||||||
|
OCP\User::checkAdminUser();
|
||||||
|
OCP\JSON::checkAppEnabled('user_sql');
|
||||||
|
|
||||||
|
// CSRF checks
|
||||||
|
OCP\JSON::callCheck();
|
||||||
|
|
||||||
|
$l = new OC_L10N('use_sql');
|
||||||
|
|
||||||
|
$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');
|
||||||
|
|
||||||
|
if (isset($_POST['appname']) && $_POST['appname'] == "user_sql") {
|
||||||
|
foreach ($params as $param) {
|
||||||
|
if (isset($_POST[$param])) {
|
||||||
|
if ($param === 'strip_domain') {
|
||||||
|
OCP\Config::setAppValue('user_sql', 'strip_domain', true);
|
||||||
|
} else {
|
||||||
|
OCP\Config::setAppValue('user_sql', $param, $_POST[$param]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($param === 'strip_domain') {
|
||||||
|
OCP\Config::setAppValue('user_sql', 'strip_domain', false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
OC_JSON::error(array("data" => 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;
|
@ -6,7 +6,7 @@
|
|||||||
<licence>AGPL</licence>
|
<licence>AGPL</licence>
|
||||||
<author>Andreas Boehler <andreas (at) aboehler
|
<author>Andreas Boehler <andreas (at) aboehler
|
||||||
(dot) at ></author>
|
(dot) at ></author>
|
||||||
<require>4.9</require>
|
<require>5.0</require>
|
||||||
<shipped>false</shipped>
|
<shipped>false</shipped>
|
||||||
<types>
|
<types>
|
||||||
<authentication/>
|
<authentication/>
|
||||||
|
@ -1 +1 @@
|
|||||||
0.8.0
|
0.9.1
|
||||||
|
14
css/settings.css
Normal file
14
css/settings.css
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
.statusmessage {
|
||||||
|
background-color: #DDDDFF;
|
||||||
|
}
|
||||||
|
.errormessage {
|
||||||
|
background-color: #FFDDDD;
|
||||||
|
}
|
||||||
|
.successmessage {
|
||||||
|
background-color: #DDFFDD;
|
||||||
|
}
|
||||||
|
.statusmessage,.errormessage,.successmessage{
|
||||||
|
display:none;
|
||||||
|
padding: 1;
|
||||||
|
}
|
||||||
|
|
@ -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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
16
settings.php
16
settings.php
@ -20,11 +20,16 @@
|
|||||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
$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();
|
OCP\User::checkAdminUser();
|
||||||
|
|
||||||
|
/*
|
||||||
if ($_POST) {
|
if ($_POST) {
|
||||||
OCP\JSON::callCheck();
|
OCP\JSON::callCheck();
|
||||||
foreach($params as $param){
|
foreach($params as $param){
|
||||||
@ -38,6 +43,7 @@ if ($_POST) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// fill template
|
// fill template
|
||||||
$tmpl = new OCP\Template( 'user_sql', 'settings');
|
$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( 'strip_domain', OCP\Config::getAppValue( 'user_sql', 'strip_domain', 0));
|
||||||
$tmpl->assign( 'default_domain', OCP\Config::getAppValue( 'user_sql', 'default_domain', ''));
|
$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( '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();
|
return $tmpl->fetchPage();
|
||||||
|
@ -1,9 +1,24 @@
|
|||||||
<form id="sql" action="#" method="post">
|
<?php
|
||||||
<fieldset class="personalblock">
|
$ocVersion = $_['ocVersion'];
|
||||||
<legend><?php echo $l->t('SQL'); ?></legend>
|
$cfgClass = $ocVersion >= 7 ? 'section' : 'personalblock';
|
||||||
<p><label for="sql_type"><?php echo $l->t('SQL Driver');?></label>
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
<form id="sqlForm" action="#" method="post" class="<?php echo $cfgClass; ?>">
|
||||||
|
|
||||||
|
<div id="sql" class="<?php echo $cfgClass; ?>">
|
||||||
|
<legend><strong><?php echo $l->t('SQL'); ?></strong></legend>
|
||||||
|
<ul>
|
||||||
|
<li><a id="sqlBasicSettings" href="#sql-1"><?php echo $l -> t('Database Settings'); ?></a></li>
|
||||||
|
<li><a id="sqlAdvSettings" href="#sql-2"><?php echo $l->t('Advanced Settings'); ?></a></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<fieldset id="sql-1">
|
||||||
|
<table>
|
||||||
|
<tr><td><label for="sql_type"><?php echo $l->t('SQL Driver');?></label></td>
|
||||||
<?php $db_driver = array('mysql' => 'MySQL', 'pgsql' => 'PostgreSQL');?>
|
<?php $db_driver = array('mysql' => 'MySQL', 'pgsql' => 'PostgreSQL');?>
|
||||||
<select id="sql_type" name="sql_type">
|
<td><select id="sql_type" name="sql_type">
|
||||||
<?php
|
<?php
|
||||||
foreach ($db_driver as $driver => $name):
|
foreach ($db_driver as $driver => $name):
|
||||||
echo $_['sql_type'];
|
echo $_['sql_type'];
|
||||||
@ -13,19 +28,24 @@
|
|||||||
<option value="<?php echo $driver; ?>"><?php echo $name; ?></option>
|
<option value="<?php echo $driver; ?>"><?php echo $name; ?></option>
|
||||||
<?php endif;
|
<?php endif;
|
||||||
endforeach; ?>
|
endforeach; ?>
|
||||||
</select>
|
</select></td>
|
||||||
</p>
|
</tr>
|
||||||
|
|
||||||
<p><label for="sql_host"><?php echo $l->t('Host');?></label><input type="text" id="sql_host" name="sql_host" value="<?php echo $_['sql_host']; ?>"></p>
|
<tr><td><label for="sql_host"><?php echo $l->t('Host');?></label></td><td><input type="text" id="sql_host" name="sql_host" value="<?php echo $_['sql_host']; ?>"></td></tr>
|
||||||
<p><label for="sql_user"><?php echo $l->t('Username');?></label><input type="text" id="sql_user" name="sql_user" value="<?php echo $_['sql_user']; ?>" /></p>
|
<tr><td><label for="sql_user"><?php echo $l->t('Username');?></label></td><td><input type="text" id="sql_user" name="sql_user" value="<?php echo $_['sql_user']; ?>" /></td></tr>
|
||||||
<p><label for="sql_database"><?php echo $l->t('Database');?></label><input type="text" id="sql_database" name="sql_database" value="<?php echo $_['sql_database']; ?>" /></p>
|
<tr><td><label for="sql_database"><?php echo $l->t('Database');?></label></td><td><input type="text" id="sql_database" name="sql_database" value="<?php echo $_['sql_database']; ?>" /></td></tr>
|
||||||
<p><label for="sql_password"><?php echo $l->t('Password');?></label><input type="password" id="sql_password" name="sql_password" value="<?php echo $_['sql_password']; ?>" /></p>
|
<tr><td><label for="sql_password"><?php echo $l->t('Password');?></label></td><td><input type="password" id="sql_password" name="sql_password" value="<?php echo $_['sql_password']; ?>" /></td></tr>
|
||||||
<p><label for="sql_table"><?php echo $l->t('Table');?></label><input type="text" id="sql_table" name="sql_table" value="<?php echo $_['sql_table']; ?>" /></p>
|
<tr><td><label for="sql_table"><?php echo $l->t('Table');?></label></td><td><input type="text" id="sql_table" name="sql_table" value="<?php echo $_['sql_table']; ?>" /></td></tr>
|
||||||
<p><label for="sql_column_username"><?php echo $l->t('Username Column');?></label><input type="text" id="sql_column_username" name="sql_column_username" value="<?php echo $_['sql_column_username']; ?>" /></p>
|
</table>
|
||||||
<p><label for="sql_column_password"><?php echo $l->t('Password Column');?></label><input type="text" id="sql_column_password" name="sql_column_password" value="<?php echo $_['sql_column_password']; ?>" /></p>
|
</fieldset>
|
||||||
<p><label for="crypt_type"><?php echo $l->t('Encryption Type');?></label>
|
<fieldset id="sql-2">
|
||||||
|
<table>
|
||||||
|
<tr><td><label for="sql_column_username"><?php echo $l->t('Username Column');?></label></td><td><input type="text" id="sql_column_username" name="sql_column_username" value="<?php echo $_['sql_column_username']; ?>" /></td></tr>
|
||||||
|
<tr><td><label for="sql_column_password"><?php echo $l->t('Password Column');?></label></td><td><input type="text" id="sql_column_password" name="sql_column_password" value="<?php echo $_['sql_column_password']; ?>" /></td></tr>
|
||||||
|
<tr><td><label for="sql_column_displayname"><?php echo $l->t('Real Name Column');?></label></td><td><input type="text" id="sql_column_displayname" name="sql_column_displayname" value="<?php echo $_['sql_column_displayname']; ?>" /></td></tr>
|
||||||
|
<tr><td><label for="crypt_type"><?php echo $l->t('Encryption Type');?></label></td>
|
||||||
<?php $crypt_types = array('md5' => 'MD5', 'md5crypt' => 'MD5 Crypt', 'cleartext' => 'Cleartext', 'mysql_encrypt' => 'mySQL ENCRYPT()', 'system' => 'System (crypt)', 'mysql_password' => 'mySQL PASSWORD()', 'joomla' => 'Joomla MD5 Encryption');?>
|
<?php $crypt_types = array('md5' => 'MD5', 'md5crypt' => 'MD5 Crypt', 'cleartext' => 'Cleartext', 'mysql_encrypt' => 'mySQL ENCRYPT()', 'system' => 'System (crypt)', 'mysql_password' => 'mySQL PASSWORD()', 'joomla' => 'Joomla MD5 Encryption');?>
|
||||||
<select id="crypt_type" name="crypt_type">
|
<td><select id="crypt_type" name="crypt_type">
|
||||||
<?php
|
<?php
|
||||||
foreach ($crypt_types as $driver => $name):
|
foreach ($crypt_types as $driver => $name):
|
||||||
echo $_['crypt_type'];
|
echo $_['crypt_type'];
|
||||||
@ -35,12 +55,18 @@
|
|||||||
<option value="<?php echo $driver; ?>"><?php echo $name; ?></option>
|
<option value="<?php echo $driver; ?>"><?php echo $name; ?></option>
|
||||||
<?php endif;
|
<?php endif;
|
||||||
endforeach; ?>
|
endforeach; ?>
|
||||||
</select>
|
</select></td>
|
||||||
</p>
|
</tr>
|
||||||
<p><label for="sql_column_active"><?php echo $l->t('User Active Column');?></label><input type="text" id="sql_column_active" name="sql_column_active" value="<?php echo $_['sql_column_active']; ?>" /></p>
|
<tr><td><label for="sql_column_active"><?php echo $l->t('User Active Column');?></label></td><td><input type="text" id="sql_column_active" name="sql_column_active" value="<?php echo $_['sql_column_active']; ?>" /></td></tr>
|
||||||
<p><label for="strip_domain"><?php echo $l->t('Strip Domain Part from Username');?></label><input type="checkbox" id="strip_domain" name="strip_domain" value="1"<?php if($_['strip_domain']) echo ' checked'; ?> title="Strip Domain Part from Username when logging in and retrieving username lists"></p>
|
<tr><td><label for="strip_domain"><?php echo $l->t('Strip Domain Part from Username');?></label></td><td><input type="checkbox" id="strip_domain" name="strip_domain" value="1"<?php if($_['strip_domain']) echo ' checked'; ?> title="Strip Domain Part from Username when logging in and retrieving username lists"></td></tr>
|
||||||
<p><label for="default_domain"><?php echo $l->t('Add default domain to Usernames');?></label><input type="text" id="default_domain" name="default_domain" value="<?php echo $_['default_domain']; ?>" /></p>
|
<tr><td><label for="default_domain"><?php echo $l->t('Add default domain to Usernames');?></label></td><td><input type="text" id="default_domain" name="default_domain" value="<?php echo $_['default_domain']; ?>" /></td></tr>
|
||||||
|
</table>
|
||||||
|
</fieldset>
|
||||||
<input type="hidden" name="requesttoken" value="<?php echo $_['requesttoken'] ?>" id="requesttoken" />
|
<input type="hidden" name="requesttoken" value="<?php echo $_['requesttoken'] ?>" id="requesttoken" />
|
||||||
<input type="submit" value="<?php echo $l->t('Save'); ?>" />
|
<input type="hidden" name="appname" value="user_sql" />
|
||||||
</fieldset>
|
<input id="sqlSubmit" type="submit" value="<?php echo $l->t('Save'); ?>" />
|
||||||
|
<div id="sql_update_message" class="statusmessage"><?php echo $l->t('Saving...'); ?></div>
|
||||||
|
<div id="sql_error_message" class="errormessage"></div>
|
||||||
|
<div id="sql_success_message" class="successmessage"></div>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
82
user_sql.php
82
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_username;
|
||||||
protected $sql_column_password;
|
protected $sql_column_password;
|
||||||
protected $sql_column_active;
|
protected $sql_column_active;
|
||||||
|
protected $sql_column_displayname;
|
||||||
protected $sql_type;
|
protected $sql_type;
|
||||||
protected $db_conn;
|
protected $db_conn;
|
||||||
protected $db;
|
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_table = OCP\Config::getAppValue('user_sql', 'sql_table', '');
|
||||||
$this->sql_column_username = OCP\Config::getAppValue('user_sql', 'sql_column_username', '');
|
$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_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_column_active = OCP\Config::getAppValue('user_sql', 'sql_column_active', '');
|
||||||
$this->sql_type = OCP\Config::getAppValue('user_sql', 'sql_type', '');
|
$this->sql_type = OCP\Config::getAppValue('user_sql', 'sql_type', '');
|
||||||
$this->default_domain = OCP\Config::getAppValue('user_sql', 'default_domain', '');
|
$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)
|
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() {
|
public function createUser() {
|
||||||
@ -271,9 +277,9 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
|||||||
public function userExists($uid)
|
public function userExists($uid)
|
||||||
{
|
{
|
||||||
|
|
||||||
$cacheKey = 'sql_user_exists_' . $uid;
|
$cacheKey = 'sql_user_exists_' . $uid;
|
||||||
$cacheVal = $this->cache->get($cacheKey);
|
$cacheVal = $this->cache->get($cacheKey);
|
||||||
if(! is_null($cacheVal) ) return (bool) $cacheVal;
|
if(! is_null($cacheVal) ) return (bool) $cacheVal;
|
||||||
|
|
||||||
OC_Log::write('OC_USER_SQL', "Entering userExists() for UID: $uid", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "Entering userExists() for UID: $uid", OC_Log::DEBUG);
|
||||||
if(!$this->db_conn)
|
if(!$this->db_conn)
|
||||||
@ -287,10 +293,6 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
|||||||
}
|
}
|
||||||
$uid = strtolower($uid);
|
$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";
|
$query = "SELECT $this->sql_column_username FROM $this->sql_table WHERE $this->sql_column_username = :uid";
|
||||||
if($this->sql_column_active != '')
|
if($this->sql_column_active != '')
|
||||||
$query .= " AND $this->sql_column_active = 1";
|
$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);
|
OC_Log::write('OC_USER_SQL', "Fetching results...", OC_Log::DEBUG);
|
||||||
|
|
||||||
$exists = (bool)$result->fetch();
|
$exists = (bool)$result->fetch();
|
||||||
$this->cache->set($cacheKey, $exists, 60);
|
$this->cache->set($cacheKey, $exists, 60);
|
||||||
|
|
||||||
if(!$exists)
|
if(!$exists)
|
||||||
{
|
{
|
||||||
@ -317,12 +319,70 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
OC_Log::write('OC_USER_SQL', "User exists, return true", OC_Log::DEBUG);
|
OC_Log::write('OC_USER_SQL', "User exists, return true", OC_Log::DEBUG);
|
||||||
$cached_exists = $uid;
|
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The following functions were directly taken from PostfixAdmin and just slightly modified
|
* The following functions were directly taken from PostfixAdmin and just slightly modified
|
||||||
* to suit our needs.
|
* to suit our needs.
|
||||||
|
Loading…
Reference in New Issue
Block a user