|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AppBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
6
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
7
|
|
|
use AppBundle\Entity\Customer; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
9
|
|
|
|
|
10
|
|
|
class CustomerController extends Controller |
|
11
|
|
|
{ |
|
12
|
|
|
public function customerLoginAction(Request $request) |
|
13
|
|
|
{ |
|
14
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
15
|
|
|
$apiKeyHead = $request->headers->get('API-Key-Token'); |
|
16
|
|
|
$facebookToken = $request->request->get('social_token'); |
|
17
|
|
|
$apiKey = uniqid('token_'); |
|
18
|
|
|
$firstNameHead = $request->request->get('first_name'); |
|
19
|
|
|
$lastNameHead = $request->request->get('last_name'); |
|
20
|
|
|
$emailHead = $request->request->get('email'); |
|
21
|
|
|
|
|
22
|
|
|
$ValidatorResult = $this->get('service_customers_login_validator') |
|
23
|
|
|
->resultOptions($this->getUser(), $apiKeyHead, $facebookToken, $firstNameHead, $lastNameHead, $emailHead); |
|
24
|
|
|
|
|
25
|
|
|
switch ($ValidatorResult) { |
|
26
|
|
|
case 'social token true': |
|
27
|
|
|
$UserFacebook = $this->get('service_facebook_sdk') |
|
28
|
|
|
->getUserFacebook($facebookToken); |
|
29
|
|
|
$userFindApiKey = $em->getRepository('AppBundle:Customer') |
|
30
|
|
|
->findUsernameByApiKey($apiKeyHead); |
|
31
|
|
|
$userFindApiKey->setEmail($UserFacebook->getEmail()); |
|
32
|
|
|
$userFindApiKey->setFacebookID($UserFacebook->getId()); |
|
33
|
|
|
$userFindApiKey->setFirstname($UserFacebook->getFirstName()); |
|
34
|
|
|
$userFindApiKey->setLastname($UserFacebook->getLastName()); |
|
35
|
|
|
$userFindApiKey->setApiKey($apiKey); |
|
36
|
|
|
$em->flush(); |
|
37
|
|
|
|
|
38
|
|
|
return new JsonResponse('costumer'); |
|
39
|
|
|
|
|
40
|
|
|
break; |
|
|
|
|
|
|
41
|
|
|
case 'Invalid email/first_name/last_name': |
|
42
|
|
|
return new JsonResponse('401'); |
|
43
|
|
|
break; |
|
|
|
|
|
|
44
|
|
|
case 'customer input of the form': |
|
45
|
|
|
$userFindApiKey = $em->getRepository('AppBundle:Customer') |
|
46
|
|
|
->findUsernameByApiKey($apiKeyHead); |
|
47
|
|
|
$userFindApiKey->setFirstname($firstNameHead); |
|
48
|
|
|
$userFindApiKey->setLastname($lastNameHead); |
|
49
|
|
|
$userFindApiKey->setEmail($emailHead); |
|
50
|
|
|
$em->flush(); |
|
51
|
|
|
|
|
52
|
|
|
return new JsonResponse('customer'); |
|
53
|
|
|
break; |
|
|
|
|
|
|
54
|
|
|
case 'not valid apiKey': |
|
55
|
|
|
return new JsonResponse('403'); |
|
56
|
|
|
break; |
|
|
|
|
|
|
57
|
|
|
case 'new costomer': |
|
58
|
|
|
$costumer = new Customer(); |
|
59
|
|
|
$costumer->setUsername('customer'); |
|
60
|
|
|
$costumer->setApiKey($apiKey); |
|
61
|
|
|
$em->persist($costumer); |
|
62
|
|
|
$em->flush(); |
|
63
|
|
|
|
|
64
|
|
|
return new JsonResponse('customer'); |
|
65
|
|
|
break; |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.