Completed
Push — master ( c32c59...cc0442 )
by Marc
11s
created

VigLinkController::keyAction()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 38
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 38
rs 8.5806
cc 4
eloc 23
nc 5
nop 1
1
<?php
2
3
namespace AppBundle\Controller;
4
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
5
use Symfony\Component\HttpFoundation\Response;
6
use Symfony\Component\HttpFoundation\Request;
7
8
class VigLinkController extends Controller
9
{
10
	public function keyAction(Request $request)
11
	{
12
		$siteId = $request->query->get('siteid');
13
		$uuid = $request->query->get('uuid');
14
		$apiKey = $request->query->get('key');
15
		$siteDomain = $request->query->get('domain');
16
17
		if (!isset($siteId, $uuid, $apiKey, $siteDomain))
18
		{
19
			throw new Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
20
		}
21
22
		$subId = md5($siteId . $uuid);
23
		$expiration = strtotime("+1 year");
24
		$key = $this->container->hasParameter('viglink_api_key') ? $this->getParameter('viglink_api_key') : $apiKey;
25
26
		if (!$this->container->hasParameter('viglink_secret_key')) {
27
			throw new Exception('Viglink is not enabled');
28
		}
29
30
		$secretKey = $this->getParameter('viglink_secret_key');
31
32
		$url = ("https://www.viglink.com/users/convertAccount?key=" . $key . "&subId=" . $subId);
33
		$signature = hash_hmac('md5', ($url . "-" . $expiration), $secretKey);
34
35
		$queryParams = http_build_query(
36
			['key' => $key,
37
			'subId' => $subId,
38
			'expiration' => $expiration,
39
			'signature' => $signature,]
40
		);
41
42
		$url = ('https://www.viglink.com/users/convertAccount?' . $queryParams);
43
44
		$response = new Response($url);
45
46
		return $response;
47
	}
48
}
49