Completed
Pull Request — master (#92)
by Michael
01:52
created

VigLinkController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
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 40
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B keyAction() 0 37 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
		$sitename = $request->query->get('sitename');
13
		$siteId = $request->query->get('uuid');
14
		$apiKey = $request->query->get('key');
15
16
		if (!isset($sitename, $siteId, $apiKey))
17
		{
18
			throw new Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
19
		}
20
21
		$subId = md5($sitename . $siteId);
22
		$expiration = strtotime("+1 year");
23
		$key = $this->container->hasParameter('viglink_api_key') ? $this->getParameter('viglink_api_key') : $apiKey;
24
25
		if (!$this->container->hasParameter('viglink_secret_key')) {
26
			throw new Exception('Viglink is not enabled');
27
		}
28
29
		$secretKey = $this->getParameter('viglink_secret_key');
30
31
		$url = ("https://www.viglink.com/users/convertAccount?key=" . $key . "&subId=" . $subId);
32
		$signature = hash_hmac('md5', ($url . "-" . $expiration), $secretKey);
33
34
		$queryParams = http_build_query(
35
			['key' => $key,
36
			'subId' => $subId,
37
			'expiration' => $expiration,
38
			'signature' => $signature,]
39
		);
40
41
		$url = ('https://www.viglink.com/users/convertAccount?' . $queryParams);
42
43
		$response = new Response($url);
44
45
		return $response;
46
	}
47
}
48