|
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
|
|
|
/** |
|
13
|
|
|
* @param Request $request |
|
14
|
|
|
* @return bool|JsonResponse |
|
15
|
|
|
*/ |
|
16
|
|
|
public function loginAction(Request $request) |
|
17
|
|
|
{ |
|
18
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
19
|
|
|
$apiKeyFromRequest = $request->headers->get('API-Key-Token'); |
|
20
|
|
|
$socialNetwork = $request->request->get('social_network'); |
|
21
|
|
|
$socialToken = $request->request->get('social_token'); |
|
22
|
|
|
$apiKey = uniqid('token_'); |
|
23
|
|
|
$firstName = $request->request->get('first_name'); |
|
24
|
|
|
$lastName = $request->request->get('last_name'); |
|
25
|
|
|
$email = $request->request->get('email'); |
|
26
|
|
|
|
|
27
|
|
|
$validatorResult = $this->get('service_customers_login_validator') |
|
28
|
|
|
->resultOptions($this->getUser(), $apiKeyFromRequest, $socialNetwork, $firstName, $lastName, $email); |
|
29
|
|
|
|
|
30
|
|
|
switch ($validatorResult) { |
|
31
|
|
|
case 'social network true': |
|
32
|
|
|
$UserFacebook = $this->get('service_facebook_sdk') |
|
33
|
|
|
->getUserFacebook($socialToken); |
|
34
|
|
|
$userFindApiKey = $em->getRepository('AppBundle:Customer') |
|
|
|
|
|
|
35
|
|
|
->findOneByApiKey($apiKeyFromRequest); |
|
36
|
|
|
$userFindApiKey->setEmail($UserFacebook->getEmail()); |
|
37
|
|
|
$userFindApiKey->setFacebookId($UserFacebook->getId()); |
|
38
|
|
|
$userFindApiKey->setFirstName($UserFacebook->getFirstName()); |
|
39
|
|
|
$userFindApiKey->setLastName($UserFacebook->getLastName()); |
|
40
|
|
|
$userFindApiKey->setApiKey($apiKey); |
|
41
|
|
|
$em->flush(); |
|
42
|
|
|
|
|
43
|
|
|
return new JsonResponse('customer'); |
|
44
|
|
|
break; |
|
|
|
|
|
|
45
|
|
|
case 'Invalid email/first_name/last_name': |
|
46
|
|
|
return new JsonResponse('401'); |
|
47
|
|
|
break; |
|
|
|
|
|
|
48
|
|
|
case 'customer input of the form': |
|
49
|
|
|
$userFindApiKey = $em->getRepository('AppBundle:Customer') |
|
|
|
|
|
|
50
|
|
|
->findOneByApiKey($apiKeyFromRequest); |
|
51
|
|
|
$userFindApiKey->setFirstName($firstName); |
|
52
|
|
|
$userFindApiKey->setLastName($lastName); |
|
53
|
|
|
$userFindApiKey->setEmail($email); |
|
54
|
|
|
$em->flush(); |
|
55
|
|
|
|
|
56
|
|
|
return new JsonResponse('customer'); |
|
57
|
|
|
break; |
|
|
|
|
|
|
58
|
|
|
case 'not valid apiKey': |
|
59
|
|
|
return new JsonResponse('403'); |
|
60
|
|
|
break; |
|
|
|
|
|
|
61
|
|
|
case 'new customer': |
|
62
|
|
|
$customer = new Customer(); |
|
63
|
|
|
$customer->setUsername('customer'); |
|
64
|
|
|
$customer->setApiKey($apiKey); |
|
65
|
|
|
$em->persist($customer); |
|
66
|
|
|
$em->flush(); |
|
67
|
|
|
|
|
68
|
|
|
return new JsonResponse('customer'); |
|
69
|
|
|
break; |
|
|
|
|
|
|
70
|
|
|
default: |
|
71
|
|
|
return new JsonResponse('default'); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.