mirror of
https://github.com/moparisthebest/user_sql
synced 2024-11-22 01:02:18 -05:00
v0.4: Add possibility to strip/add default domain to usernames
This commit is contained in:
parent
fcc0fe5c45
commit
315397fd38
@ -1 +1 @@
|
|||||||
0.3
|
0.4
|
||||||
|
19
settings.php
19
settings.php
@ -20,16 +20,21 @@
|
|||||||
* 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');
|
$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');
|
||||||
|
|
||||||
OCP\Util::addscript('user_sql', 'settings');
|
OCP\Util::addscript('user_sql', 'settings');
|
||||||
|
|
||||||
if ($_POST) {
|
if ($_POST) {
|
||||||
foreach($params as $param){
|
foreach($params as $param){
|
||||||
if(isset($_POST[$param])){
|
if(isset($_POST[$param]))
|
||||||
OCP\Config::setAppValue('user_sql', $param, $_POST[$param]);
|
{
|
||||||
}
|
OCP\Config::setAppValue('user_sql', $param, $_POST[$param]);
|
||||||
}
|
}
|
||||||
|
elseif($param == 'strip_domain')
|
||||||
|
{
|
||||||
|
OCP\Config::setAppValue('user_sql', $param, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill template
|
// fill template
|
||||||
@ -49,5 +54,7 @@ $tmpl->assign( 'sql_column_password', OCP\Config::getAppValue( 'user_sql', 'sql_
|
|||||||
$tmpl->assign( 'sql_column_username', OCP\Config::getAppValue( 'user_sql', 'sql_column_username', OC_USER_BACKEND_SQL_DEFAULT_USER_COLUMN));
|
$tmpl->assign( 'sql_column_username', OCP\Config::getAppValue( 'user_sql', 'sql_column_username', OC_USER_BACKEND_SQL_DEFAULT_USER_COLUMN));
|
||||||
$tmpl->assign( 'sql_type', OCP\Config::getAppValue( 'user_sql', 'sql_type', OC_USER_BACKEND_SQL_DEFAULT_DRIVER));
|
$tmpl->assign( 'sql_type', OCP\Config::getAppValue( 'user_sql', 'sql_type', OC_USER_BACKEND_SQL_DEFAULT_DRIVER));
|
||||||
$tmpl->assign( 'sql_column_active', OCP\Config::getAppValue( 'user_sql', 'sql_column_active', ''));
|
$tmpl->assign( 'sql_column_active', OCP\Config::getAppValue( 'user_sql', 'sql_column_active', ''));
|
||||||
|
$tmpl->assign( 'strip_domain', OCP\Config::getAppValue( 'user_sql', 'strip_domain', 0));
|
||||||
|
$tmpl->assign( 'default_domain', OCP\Config::getAppValue( 'user_sql', 'default_domain', ''));
|
||||||
|
|
||||||
return $tmpl->fetchPage();
|
return $tmpl->fetchPage();
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
<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_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_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_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>
|
<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>
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
|
||||||
<input type="submit" value="<?php echo $l->t('Save'); ?>" />
|
<input type="submit" value="<?php echo $l->t('Save'); ?>" />
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
29
user_sql.php
29
user_sql.php
@ -35,6 +35,8 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
|||||||
protected $sql_type;
|
protected $sql_type;
|
||||||
protected $db_conn;
|
protected $db_conn;
|
||||||
protected $db;
|
protected $db;
|
||||||
|
protected $default_domain;
|
||||||
|
protected $strip_domain;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@ -48,6 +50,8 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
|||||||
$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_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->strip_domain = OCP\Config::getAppValue('user_sql', 'strip_domain', 0);
|
||||||
$dsn = $this->sql_type.":host=".$this->sql_host.";dbname=".$this->sql_database;
|
$dsn = $this->sql_type.":host=".$this->sql_host.";dbname=".$this->sql_database;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -85,7 +89,10 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if($this->strip_domain)
|
||||||
|
{
|
||||||
|
$uid .= "@".$this->default_domain;
|
||||||
|
}
|
||||||
$query = "UPDATE $this->sql_table SET $this->sql_column_password = ENCRYPT('$password') WHERE $this->sql_column_username = '$uid'";
|
$query = "UPDATE $this->sql_table SET $this->sql_column_password = ENCRYPT('$password') WHERE $this->sql_column_username = '$uid'";
|
||||||
$result = $this->db->prepare($query);
|
$result = $this->db->prepare($query);
|
||||||
if(!$result->execute())
|
if(!$result->execute())
|
||||||
@ -109,8 +116,13 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$suid = $uid;
|
||||||
|
if($this->strip_domain)
|
||||||
|
{
|
||||||
|
$suid = $uid."@".$this->default_domain;
|
||||||
|
}
|
||||||
|
|
||||||
$query = "SELECT $this->sql_column_username, $this->sql_column_password FROM $this->sql_table WHERE $this->sql_column_username = '$uid'";
|
$query = "SELECT $this->sql_column_username, $this->sql_column_password FROM $this->sql_table WHERE $this->sql_column_username = '$suid'";
|
||||||
if($this->sql_column_active != '')
|
if($this->sql_column_active != '')
|
||||||
$query .= " AND $this->sql_column_active = 1";
|
$query .= " AND $this->sql_column_active = 1";
|
||||||
$result = $this->db->prepare($query);
|
$result = $this->db->prepare($query);
|
||||||
@ -169,7 +181,13 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
|||||||
}
|
}
|
||||||
while($row = $result->fetch())
|
while($row = $result->fetch())
|
||||||
{
|
{
|
||||||
$users[] = $row[$this->sql_column_username];
|
$uid = $row[$this->sql_column_username];
|
||||||
|
if($this->strip_domain)
|
||||||
|
{
|
||||||
|
$uid = explode("@", $uid);
|
||||||
|
$uid = $uid[0];
|
||||||
|
}
|
||||||
|
$users[] = $uid;
|
||||||
}
|
}
|
||||||
return $users;
|
return $users;
|
||||||
}
|
}
|
||||||
@ -187,6 +205,11 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($this->strip_domain)
|
||||||
|
{
|
||||||
|
$uid .= "@".$this->default_domain;
|
||||||
|
}
|
||||||
|
|
||||||
$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";
|
||||||
|
Loading…
Reference in New Issue
Block a user