3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Model;
24 use Friendica\Database\DBA;
25 use Friendica\Util\DateTimeFormat;
28 * Methods to deal with entries of the 'openwebauth-token' table.
30 class OpenWebAuthToken
33 * Create an entry in the 'openwebauth-token' table.
35 * @param string $type Verify type.
36 * @param int $uid The user ID.
37 * @param string $token
43 public static function create($type, $uid, $token, $meta)
50 "created" => DateTimeFormat::utcNow()
52 return DBA::insert("openwebauth-token", $fields);
56 * Get the "meta" field of an entry in the openwebauth-token table.
58 * @param string $type Verify type.
59 * @param int $uid The user ID.
60 * @param string $token
62 * @return string|boolean The meta enry or false if not found.
65 public static function getMeta($type, $uid, $token)
67 $condition = ["type" => $type, "uid" => $uid, "token" => $token];
69 $entry = DBA::selectFirst("openwebauth-token", ["id", "meta"], $condition);
70 if (DBA::isResult($entry)) {
71 DBA::delete("openwebauth-token", ["id" => $entry["id"]]);
73 return $entry["meta"];
79 * Purge entries of a verify-type older than interval.
81 * @param string $type Verify type.
82 * @param string $interval SQL compatible time interval
85 public static function purge($type, $interval)
87 $condition = ["`type` = ? AND `created` < ?", $type, DateTimeFormat::utcNow() . " - INTERVAL " . $interval];
88 DBA::delete("openwebauth-token", $condition);