aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Zot/Verify.php
blob: 06bd3188cdaa4be47cb361d1dfd1243f8625f040 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php

namespace Zotlabs\Zot;


class Verify {

	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())
		);
	}

	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;
	}

	function purge($type,$interval) {
		q("delete from verify where vtype = '%s' and created < %s - INTERVAL %s",
			dbesc($type),
			db_utcnow(),
			db_quoteinterval($interval)
		);
	}

}