From: rabuzarus Date: Wed, 20 Jun 2018 17:24:02 +0000 (+0200) Subject: port hubzillas OpenWebAuth - rename Verify class to OpenWebAuthToken X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=149142b4bc7cfd9a40bfa04d767d3e7149a69b22;p=friendica.git port hubzillas OpenWebAuth - rename Verify class to OpenWebAuthToken --- diff --git a/src/Model/OpenWebAuthToken.php b/src/Model/OpenWebAuthToken.php new file mode 100644 index 0000000000..f295fc3703 --- /dev/null +++ b/src/Model/OpenWebAuthToken.php @@ -0,0 +1,73 @@ + $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); + } + +} diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 8d2045221f..0bb18e1463 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -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 index 18fbb2eb5b..0000000000 --- a/src/Model/Verify.php +++ /dev/null @@ -1,73 +0,0 @@ - $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); - } - -} diff --git a/src/Module/Owa.php b/src/Module/Owa.php index 13594a3ea0..c1948f3b64 100644 --- a/src/Module/Owa.php +++ b/src/Module/Owa.php @@ -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 = ''; diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index 1ed0e1e8a7..a91b6b37e3 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -1,7 +1,7 @@