port hubzillas OpenWebAuth - rename Verify class to OpenWebAuthToken
authorrabuzarus <rabuzarus@t-online.de>
Wed, 20 Jun 2018 17:24:02 +0000 (19:24 +0200)
committerrabuzarus <rabuzarus@t-online.de>
Wed, 20 Jun 2018 17:24:02 +0000 (19:24 +0200)
src/Model/OpenWebAuthToken.php [new file with mode: 0644]
src/Model/Profile.php
src/Model/Verify.php [deleted file]
src/Module/Owa.php
src/Util/HTTPSignature.php

diff --git a/src/Model/OpenWebAuthToken.php b/src/Model/OpenWebAuthToken.php
new file mode 100644 (file)
index 0000000..f295fc3
--- /dev/null
@@ -0,0 +1,73 @@
+<?php
+
+/**
+ * @file src/Model/OpenWebAuthToken.php
+ */
+namespace Friendica\Model;
+
+use Friendica\Database\DBM;
+use Friendica\Util\DateTimeFormat;
+use dba;
+
+/**
+ * Methods to deal with entries of the 'openwebauth_token' table.
+ */
+class OpenWebAuthToken
+{
+       /**
+        * Create an entry in the 'openwebauth_token' table.
+        * 
+        * @param string $type   Verify type.
+        * @param int    $uid    The user ID.
+        * @param string $token
+        * @param string $meta
+        * 
+        * @return boolean
+        */
+       public static function create($type, $uid, $token, $meta)
+       {
+               $fields = [
+                       "type" => $type,
+                       "uid" => $uid,
+                       "token" => $token,
+                       "meta" => $meta,
+                       "created" => DateTimeFormat::utcNow()
+               ];
+               return dba::insert("openwebauth_token", $fields);
+       }
+
+       /**
+        * Get the "meta" field of an entry in the openwebauth_token table.
+        * 
+        * @param string $type   Verify type.
+        * @param int    $uid    The user ID.
+        * @param string $token
+        * 
+        * @return string|boolean The meta enry or false if not found.
+        */
+       public static function getMeta($type, $uid, $token)
+       {
+               $condition = ["type" => $type, "uid" => $uid, "token" => $token];
+
+               $entry = dba::selectFirst("openwebauth_token", ["id", "meta"], $condition);
+               if (DBM::is_result($entry)) {
+                       dba::delete("openwebauth_token", ["id" => $entry["id"]]);
+
+                       return $entry["meta"];
+               }
+               return false;
+       }
+
+       /**
+        * Purge entries of a verify-type older than interval.
+        * 
+        * @param string $type     Verify type.
+        * @param string $interval SQL compatible time interval
+        */
+       public static function purge($type, $interval)
+       {
+               $condition = ["`type` = ? AND `created` < ?", $type, DateTimeFormat::utcNow() . " - INTERVAL " . $interval];
+               dba::delete("openwebauth_token", $condition);
+       }
+
+}
index 8d20452..0bb18e1 100644 (file)
@@ -17,7 +17,7 @@ use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
-use Friendica\Model\Verify;
+use Friendica\Model\OpenWebAuthToken;
 use Friendica\Protocol\Diaspora;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
@@ -1056,12 +1056,12 @@ class Profile
        {
                $a = get_app();
 
-               // Clean old verify entries.
-               Verify::purge('owt', '3 MINUTE');
+               // Clean old OpenWebAuthToken entries.
+               OpenWebAuthToken::purge('owt', '3 MINUTE');
 
                // Check if the token we got is the same one
                // we have stored in the database.
-               $visitor_handle = Verify::getMeta('owt', 0, $token);
+               $visitor_handle = OpenWebAuthToken::getMeta('owt', 0, $token);
 
                if($visitor_handle === false) {
                        return;
diff --git a/src/Model/Verify.php b/src/Model/Verify.php
deleted file mode 100644 (file)
index 18fbb2e..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-<?php
-
-/**
- * @file src/Model/Verify.php
- */
-namespace Friendica\Model;
-
-use Friendica\Database\DBM;
-use Friendica\Util\DateTimeFormat;
-use dba;
-
-/**
- * Methods to deal with entries of the 'openwebauth_token' table.
- */
-class Verify
-{
-       /**
-        * Create an entry in the 'openwebauth_token' table.
-        * 
-        * @param string $type   Verify type.
-        * @param int    $uid    The user ID.
-        * @param string $token
-        * @param string $meta
-        * 
-        * @return boolean
-        */
-       public static function create($type, $uid, $token, $meta)
-       {
-               $fields = [
-                       "type" => $type,
-                       "uid" => $uid,
-                       "token" => $token,
-                       "meta" => $meta,
-                       "created" => DateTimeFormat::utcNow()
-               ];
-               return dba::insert("openwebauth_token", $fields);
-       }
-
-       /**
-        * Get the "meta" field of an entry in the openwebauth_token table.
-        * 
-        * @param string $type   Verify type.
-        * @param int    $uid    The user ID.
-        * @param string $token
-        * 
-        * @return string|boolean The meta enry or false if not found.
-        */
-       public static function getMeta($type, $uid, $token)
-       {
-               $condition = ["type" => $type, "uid" => $uid, "token" => $token];
-
-               $entry = dba::selectFirst("openwebauth_token", ["id", "meta"], $condition);
-               if (DBM::is_result($entry)) {
-                       dba::delete("openwebauth_token", ["id" => $entry["id"]]);
-
-                       return $entry["meta"];
-               }
-               return false;
-       }
-
-       /**
-        * Purge entries of a verify-type older than interval.
-        * 
-        * @param string $type     Verify type.
-        * @param string $interval SQL compatible time interval
-        */
-       public static function purge($type, $interval)
-       {
-               $condition = ["`type` = ? AND `created` < ?", $type, DateTimeFormat::utcNow() . " - INTERVAL " . $interval];
-               dba::delete("openwebauth_token", $condition);
-       }
-
-}
index 13594a3..c1948f3 100644 (file)
@@ -8,7 +8,7 @@ use Friendica\BaseModule;
 use Friendica\Core\System;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
-use Friendica\Model\Verify;
+use Friendica\Model\OpenWebAuthToken;
 use Friendica\Util\HTTPSignature;
 
 use dba;
@@ -66,7 +66,7 @@ class Owa extends BaseModule
                                                                $token = random_string(32);
 
                                                                // Store the generated token in the databe.
-                                                               Verify::create('owt', 0, $token, $contact['addr']);
+                                                               OpenWebAuthToken::create('owt', 0, $token, $contact['addr']);
 
                                                                $result = '';
 
index 1ed0e1e..a91b6b3 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * @file src/Util/HTTPSig.php
+ * @file src/Util/HTTPSignature.php
  */
 namespace Friendica\Util;