4 * @file src/Model/OpenWebAuthToken.php
6 namespace Friendica\Model;
8 use Friendica\Database\DBA;
9 use Friendica\Util\DateTimeFormat;
12 * Methods to deal with entries of the 'openwebauth-token' table.
14 class OpenWebAuthToken
17 * Create an entry in the 'openwebauth-token' table.
19 * @param string $type Verify type.
20 * @param int $uid The user ID.
21 * @param string $token
26 public static function create($type, $uid, $token, $meta)
33 "created" => DateTimeFormat::utcNow()
35 return DBA::insert("openwebauth-token", $fields);
39 * Get the "meta" field of an entry in the openwebauth-token table.
41 * @param string $type Verify type.
42 * @param int $uid The user ID.
43 * @param string $token
45 * @return string|boolean The meta enry or false if not found.
47 public static function getMeta($type, $uid, $token)
49 $condition = ["type" => $type, "uid" => $uid, "token" => $token];
51 $entry = DBA::selectFirst("openwebauth-token", ["id", "meta"], $condition);
52 if (DBA::isResult($entry)) {
53 DBA::delete("openwebauth-token", ["id" => $entry["id"]]);
55 return $entry["meta"];
61 * Purge entries of a verify-type older than interval.
63 * @param string $type Verify type.
64 * @param string $interval SQL compatible time interval
66 public static function purge($type, $interval)
68 $condition = ["`type` = ? AND `created` < ?", $type, DateTimeFormat::utcNow() . " - INTERVAL " . $interval];
69 DBA::delete("openwebauth-token", $condition);