Completed
Pull Request — master (#92)
by Michael
03:47 queued 21s
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;
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->getParameter('viglink_api_key');
24
		$secretKey = $this->getParameter('viglink_secret_key');
25
26
		$url = ("https://www.viglink.com/users/convertAccount?key=" . $key . "&subId=" . $subId);
27
		$signature = hex(hash_hmac('md5', ($url . "-" . $expiration), $secretKey));
28
29
		$queryParams = http_build_query(
30
			['key' => $key,
31
			'subId' => $subId,
32
			'expiration' => $expiration,
33
			'signature' => $signature,]
34
		);
35
36
		$url = ('https://www.viglink.com/ursers/convertaccount' . $queryParams);
37
38
		$response = new Response($url);
39
40
		return $response;
41
	}
42
}
43