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
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.
49 public static function getMeta($type, $uid, $token)
51 $condition = ["type" => $type, "uid" => $uid, "token" => $token];
53 $entry = DBA::selectFirst("openwebauth-token", ["id", "meta"], $condition);
54 if (DBA::isResult($entry)) {
55 DBA::delete("openwebauth-token", ["id" => $entry["id"]]);
57 return $entry["meta"];
63 * Purge entries of a verify-type older than interval.
65 * @param string $type Verify type.
66 * @param string $interval SQL compatible time interval
69 public static function purge($type, $interval)
71 $condition = ["`type` = ? AND `created` < ?", $type, DateTimeFormat::utcNow() . " - INTERVAL " . $interval];
72 DBA::delete("openwebauth-token", $condition);