VigLinkController::keyAction()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 9.312
c 0
b 0
f 0
cc 4
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
	public function enabledAction(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
	{
51
		$response = new Response('1');
52
		// Set to '0' to disable viglink
53
54
		return $response;
55
	}
56
}
57