streams/Zotlabs/Lib/Verify.php

63 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace Zotlabs\Lib;
class Verify {
2021-03-10 00:08:04 +00:00
static function create($type,$channel_id,$token,$meta) {
return q("insert into verify ( vtype, channel, token, meta, created ) values ( '%s', %d, '%s', '%s', '%s' )",
dbesc($type),
intval($channel_id),
dbesc($token),
dbesc($meta),
dbesc(datetime_convert())
);
}
2021-03-10 00:08:04 +00:00
static function match($type,$channel_id,$token,$meta) {
$r = q("select id from verify where vtype = '%s' and channel = %d and token = '%s' and meta = '%s' limit 1",
dbesc($type),
intval($channel_id),
dbesc($token),
dbesc($meta)
);
if($r) {
q("delete from verify where id = %d",
intval($r[0]['id'])
);
return true;
}
return false;
}
2021-03-10 00:08:04 +00:00
static function get_meta($type,$channel_id,$token) {
2017-09-08 01:52:18 +00:00
$r = q("select id, meta from verify where vtype = '%s' and channel = %d and token = '%s' limit 1",
2017-09-08 00:56:02 +00:00
dbesc($type),
intval($channel_id),
dbesc($token)
);
if($r) {
q("delete from verify where id = %d",
intval($r[0]['id'])
);
return $r[0]['meta'];
2017-09-08 00:56:02 +00:00
}
return false;
}
/**
* @brief Purge entries of a verify-type older than interval.
*
* @param string $type Verify type
* @param string $interval SQL compatible time interval
*/
2021-03-10 00:08:04 +00:00
static function purge($type, $interval) {
2020-01-29 05:20:22 +00:00
q("delete from verify where vtype = '%s' and created < ( %s - INTERVAL %s )",
dbesc($type),
db_utcnow(),
db_quoteinterval($interval)
);
}
}