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

VigLinkController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
c 3
b 0
f 0
lcom 0
cbo 5
dl 0
loc 41
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B keyAction() 0 38 4
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