4 * @file src/Model/OpenWebAuthToken.php
6 namespace Friendica\Model;
8 use Friendica\Database\DBA;
9 use Friendica\Database\DBM;
10 use Friendica\Util\DateTimeFormat;
13 * Methods to deal with entries of the 'openwebauth-token' table.
15 class OpenWebAuthToken
18 * Create an entry in the 'openwebauth-token' table.
20 * @param string $type Verify type.
21 * @param int $uid The user ID.
22 * @param string $token
27 public static function create($type, $uid, $token, $meta)
34 "created" => DateTimeFormat::utcNow()
36 return DBA::insert("openwebauth-token", $fields);
40 * Get the "meta" field of an entry in the openwebauth-token table.
42 * @param string $type Verify type.
43 * @param int $uid The user ID.
44 * @param string $token
46 * @return string|boolean The meta enry or false if not found.
48 public static function getMeta($type, $uid, $token)
50 $condition = ["type" => $type, "uid" => $uid, "token" => $token];
52 $entry = DBA::selectFirst("openwebauth-token", ["id", "meta"], $condition);
53 if (DBM::is_result($entry)) {
54 DBA::delete("openwebauth-token", ["id" => $entry["id"]]);
56 return $entry["meta"];
62 * Purge entries of a verify-type older than interval.
64 * @param string $type Verify type.
65 * @param string $interval SQL compatible time interval
67 public static function purge($type, $interval)
69 $condition = ["`type` = ? AND `created` < ?", $type, DateTimeFormat::utcNow() . " - INTERVAL " . $interval];
70 DBA::delete("openwebauth-token", $condition);