aboutsummaryrefslogtreecommitdiff
path: root/mod/apiadmin/actions/generate.php
blob: ca47deb3dcb716f80c813258f3079775420c65c6 (plain)
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
<?php
	global $CONFIG;
	
	admin_gatekeeper();
	
	$ref = get_input('ref');
	
	if ($ref)
	{
		$keypair = create_api_user($CONFIG->site_id);
		
		if ($keypair)
		{
			
			$newkey = new ElggObject();
			$newkey->subtype = 'api_key';
			$newkey->access_id = 2;
			$newkey->title = $ref;
			$newkey->public = $keypair->api_key;
			
			if (!$newkey->save())
				register_error(elgg_echo('apiadmin:generationfail'));
			else
				system_message(elgg_echo('apiadmin:generated'));
		}
		else
			register_error(elgg_echo('apiadmin:generationfail'));
	}
	else
		register_error(elgg_echo('apiadmin:noreference'));


	forward($_SERVER['HTTP_REFERER']);
?>