From 841bcac241bac980d5e943793ffda3372d7f8f82 Mon Sep 17 00:00:00 2001 From: Christoph Burschka Date: Thu, 16 Jan 2014 19:34:39 +0100 Subject: Big multiple-plugins patch (fixes #2). --- plugins/session/BridgeSession.php | 17 ----------------- plugins/session/config.sample.php | 17 +++++++++++++++++ plugins/session/main.php | 21 +++++++++++---------- plugins/session/session.module | 9 +++++---- 4 files changed, 33 insertions(+), 31 deletions(-) create mode 100644 plugins/session/config.sample.php (limited to 'plugins/session') diff --git a/plugins/session/BridgeSession.php b/plugins/session/BridgeSession.php index 58e2208..d9c3afc 100644 --- a/plugins/session/BridgeSession.php +++ b/plugins/session/BridgeSession.php @@ -11,11 +11,6 @@ class BridgeSession extends EjabberdAuthBridge { $this->_isuser = $this->db->prepare(sprintf('SELECT COUNT(*) FROM `%s` WHERE `username` = :user AND `created` >= :limit;', $this->table)); $this->_auth = $this->db->prepare(sprintf('DELETE FROM `%s` WHERE `username` = :user AND `secret` = :secret AND `created` >= :limit;', $this->table)); $this->_prune = $this->db->prepare(sprintf('DELETE COUNT(*) FROM `%s` WHERE `created` < :limit;', $this->table)); - $this->_create = $this->db->prepare(sprintf('INSERT INTO `%s` (`username`, `secret`, `created`) VALUES (:user, :secret, :time);', $this->table)); - } - - function create($entry) { - $this->_create->execute([':user' => $entry['user'], ':secret' => $entry['secret'], ':time' => $entry['time']]); } function prune() { @@ -33,16 +28,4 @@ class BridgeSession extends EjabberdAuthBridge { $this->_auth->execute([':user' => $username, ':secret' => $password, ':limit' => time() - $this->timeout]); return $this->_auth->rowCount() > 0; } - - function setpass($username, $server, $password) { - return FALSE; - } - - function tryregister($username, $server, $password) { - return FALSE; - } - - function removeuser($username, $server) { - return FALSE; - } } diff --git a/plugins/session/config.sample.php b/plugins/session/config.sample.php new file mode 100644 index 0000000..8677cf3 --- /dev/null +++ b/plugins/session/config.sample.php @@ -0,0 +1,17 @@ + '' + 'config' => ['root_path' => '/path/to/site'], + 'mysql' => [ + 'dsn' => 'mysql:host=localhost;dbname=DATABASE;charset=utf8', + 'username' => 'USER', + 'password' => 'PASSWORD', + 'table' => 'TABLE', + ], + ], +]; diff --git a/plugins/session/main.php b/plugins/session/main.php index 8bd6f74..18bacd8 100644 --- a/plugins/session/main.php +++ b/plugins/session/main.php @@ -1,21 +1,22 @@ $username, 'secret' => sha1($salt . time() . mt_rand()), 'time' => time()]; - $bridge->create($entry); + $query = $db->prepare(sprintf('INSERT INTO `%s` (`username`, `secret`, `created`) VALUES (:user, :secret, :time);', $config['mysql']['tablename'])); + $query->execute([':user' => $entry['user'], ':secret' => $entry['secret'], ':time' => $entry['time']]); return $entry; } return FALSE; diff --git a/plugins/session/session.module b/plugins/session/session.module index ed1771c..c979a8a 100644 --- a/plugins/session/session.module +++ b/plugins/session/session.module @@ -1,10 +1,11 @@ 'SET NAMES utf8']; - $pdo = new PDO($v['dsn'], $v['username'], $v['password'], $options); + return new PDO($mysql['dsn'], $mysql['username'], $mysql['password'], $options); +} +function session_init($config) { require_once __DIR__ . '/BridgeSession.php'; - return new BridgeSession($pdo, $config); + return new BridgeSession(session_db($config['mysql']), $config); } -- cgit v1.1