1
0
mirror of https://github.com/moparisthebest/user_sql synced 2024-12-21 23:18:51 -05:00

Added User Active Column. If the value is not 1, access is denied. Leave

empty to disable this feature.
This commit is contained in:
Andreas Boehler 2012-11-27 18:08:40 +01:00
parent b84a314e11
commit f1d65bb84a
3 changed files with 13 additions and 3 deletions

View File

@ -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');
$params = array('sql_host', 'sql_user', 'sql_database', 'sql_password', 'sql_table', 'sql_column_username', 'sql_column_password', 'sql_type', 'sql_column_active');
OCP\Util::addscript('user_sql', 'settings');
@ -48,5 +48,6 @@ $tmpl->assign( 'sql_table', OCP\Config::getAppValue( 'user_sql', 'sql_table', OC
$tmpl->assign( 'sql_column_password', OCP\Config::getAppValue( 'user_sql', 'sql_column_password', OC_USER_BACKEND_SQL_DEFAULT_PW_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_column_active', OCP\Config::getAppValue( 'user_sql', 'sql_column_active', ''));
return $tmpl->fetchPage();

View File

@ -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_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>
<input type="submit" value="<?php echo $l->t('Save'); ?>" />
</fieldset>

View File

@ -31,6 +31,7 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
protected $sql_table;
protected $sql_column_username;
protected $sql_column_password;
protected $sql_column_active;
protected $sql_type;
protected $db_conn;
protected $db;
@ -44,6 +45,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_active = OCP\Config::getAppValue('user_sql', 'sql_column_active', '');
$this->sql_type = OCP\Config::getAppValue('user_sql', 'sql_type', '');
$dsn = $this->sql_type.":host=".$this->sql_host.";dbname=".$this->sql_database;
try
@ -95,7 +97,9 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
return false;
}
$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 = '$uid'";
if($this->sql_column_active != '')
$query .= " AND $this->sql_column_active = 1";
$result = $this->db->prepare($query);
if(!$result->execute())
{
@ -132,6 +136,8 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
$query = "SELECT $this->sql_column_username FROM $this->sql_table";
if($search != '')
$query .= " WHERE $this->sql_column_username LIKE '%$search%'";
if($this->sql_column_active != '')
$query .= " AND $this->sql_column_active = 1";
if($limit != null)
$query .= " LIMIT $limit";
if($offset != null)
@ -161,7 +167,9 @@ class OC_USER_SQL extends OC_User_Backend implements OC_User_Interface {
return false;
}
$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 != '')
$query .= " AND $this->sql_column_active = 1";
$result = $this->db->prepare($query);
if(!$result->execute())
{