2016-04-15 01:51:06 +00:00
|
|
|
<?php
|
|
|
|
|
2018-02-22 04:59:30 +00:00
|
|
|
namespace Zotlabs\Lib;
|
2016-04-15 01:51:06 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
class Verify
|
|
|
|
{
|
|
|
|
|
|
|
|
public static function create($type, $channel_id, $token, $meta)
|
|
|
|
{
|
2021-12-03 03:01:39 +00:00
|
|
|
return q(
|
|
|
|
"insert into verify ( vtype, channel, token, meta, created ) values ( '%s', %d, '%s', '%s', '%s' )",
|
2021-12-02 23:02:31 +00:00
|
|
|
dbesc($type),
|
|
|
|
intval($channel_id),
|
|
|
|
dbesc($token),
|
|
|
|
dbesc($meta),
|
|
|
|
dbesc(datetime_convert())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function match($type, $channel_id, $token, $meta)
|
|
|
|
{
|
2021-12-03 03:01:39 +00:00
|
|
|
$r = q(
|
|
|
|
"select id from verify where vtype = '%s' and channel = %d and token = '%s' and meta = '%s' limit 1",
|
2021-12-02 23:02:31 +00:00
|
|
|
dbesc($type),
|
|
|
|
intval($channel_id),
|
|
|
|
dbesc($token),
|
|
|
|
dbesc($meta)
|
|
|
|
);
|
|
|
|
if ($r) {
|
2021-12-03 03:01:39 +00:00
|
|
|
q(
|
|
|
|
"delete from verify where id = %d",
|
2021-12-02 23:02:31 +00:00
|
|
|
intval($r[0]['id'])
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function get_meta($type, $channel_id, $token)
|
|
|
|
{
|
2021-12-03 03:01:39 +00:00
|
|
|
$r = q(
|
|
|
|
"select id, meta from verify where vtype = '%s' and channel = %d and token = '%s' limit 1",
|
2021-12-02 23:02:31 +00:00
|
|
|
dbesc($type),
|
|
|
|
intval($channel_id),
|
|
|
|
dbesc($token)
|
|
|
|
);
|
|
|
|
if ($r) {
|
2021-12-03 03:01:39 +00:00
|
|
|
q(
|
|
|
|
"delete from verify where id = %d",
|
2021-12-02 23:02:31 +00:00
|
|
|
intval($r[0]['id'])
|
|
|
|
);
|
|
|
|
return $r[0]['meta'];
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Purge entries of a verify-type older than interval.
|
|
|
|
*
|
|
|
|
* @param string $type Verify type
|
|
|
|
* @param string $interval SQL compatible time interval
|
|
|
|
*/
|
|
|
|
public static function purge($type, $interval)
|
|
|
|
{
|
2021-12-03 03:01:39 +00:00
|
|
|
q(
|
|
|
|
"delete from verify where vtype = '%s' and created < ( %s - INTERVAL %s )",
|
2021-12-02 23:02:31 +00:00
|
|
|
dbesc($type),
|
|
|
|
db_utcnow(),
|
|
|
|
db_quoteinterval($interval)
|
|
|
|
);
|
|
|
|
}
|
2021-12-03 03:01:39 +00:00
|
|
|
}
|