summaryrefslogtreecommitdiff
path: root/plugins/session/BridgeSession.php
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/session/BridgeSession.php')
-rw-r--r--plugins/session/BridgeSession.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/plugins/session/BridgeSession.php b/plugins/session/BridgeSession.php
new file mode 100644
index 0000000..700d545
--- /dev/null
+++ b/plugins/session/BridgeSession.php
@@ -0,0 +1,46 @@
+<?php
+
+/**
+ * Implements EjabberdAuthBridge.
+ */
+class BridgeSession extends EjabberdAuthBridge {
+ function __const($pdo, $config) {
+ $this->db = $pdo;
+ $this->timeout = $config['timeout'];
+ $this->table = mysqli::escape_string($config['mysql'['tablename']);
+ $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 COUNT(*) 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() {
+ $this->_prune->execute([':limit' => time() - $this->timeout]);
+ }
+
+ function isuser($username, $server) {
+ $this->prune();
+ return $this->_isuser->execute([':user' => $username, ':limit' => time() - $this->timeout])->fetch()[0] > 0;
+ }
+
+ function auth($username, $server, $password) {
+ $this->prune();
+ return $this->_auth->execute([[':useer' => $username, ':secret' => $password, ':limit' => time() - $this->timeout])->rowCount() > 0;
+ }
+
+ function setpass($username, $server, $password) {
+ return FALSE;
+ }
+
+ function tryregister($username, $server, $password) {
+ return FALSE;
+ }
+
+ function removeuser($username, $server) {
+ return FALSE;
+ }
+}