Completed
Pull Request — master (#92)
by Michael
03:41
created

VigLinkController::keyAction()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 32
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

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