mirror of
https://github.com/moparisthebest/user_sql
synced 2024-11-21 16:55:02 -05:00
Create branch for OC5
Added DisplayName support in OC5
This commit is contained in:
parent
a767fe07a7
commit
5c4ef2dad5
@ -6,7 +6,7 @@
|
||||
<licence>AGPL</licence>
|
||||
<author>Andreas Boehler <andreas (at) aboehler
|
||||
(dot) at ></author>
|
||||
<require>4.9</require>
|
||||
<require>5.0</require>
|
||||
<shipped>false</shipped>
|
||||
<types>
|
||||
<authentication/>
|
||||
|
@ -1 +1 @@
|
||||
0.7.1
|
||||
0.9.0
|
||||
|
@ -20,7 +20,7 @@
|
||||
* 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\User::checkAdminUser();
|
||||
@ -59,5 +59,6 @@ $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', ''));
|
||||
|
||||
return $tmpl->fetchPage();
|
||||
|
@ -23,6 +23,7 @@
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<p><label for="sql_column_displayname"><?php echo $l->t('Real Name Column');?></label><input type="text" id="sql_column_displayname" name="sql_column_displayname" value="<?php echo $_['sql_column_displayname']; ?>" /></p>
|
||||
<p><label for="crypt_type"><?php echo $l->t('Encryption Type');?></label>
|
||||
<?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">
|
||||
|
67
user_sql.php
67
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;
|
||||
@ -53,6 +54,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', '');
|
||||
@ -73,7 +75,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_BAKCNED_GET_DISPLAYNAME) & $actions);
|
||||
}
|
||||
|
||||
public function hasUserListings() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function createUser() {
|
||||
@ -313,6 +319,65 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user