GoogleController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 27
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A connectAction() 0 9 1
A connectCheckAction() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the zibios/sharep.
7
 *
8
 * (c) Zbigniew Ślązak
9
 */
10
11
namespace App\Controller\Oauth2;
12
13
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
14
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
15
use Symfony\Component\HttpFoundation\JsonResponse;
16
use Symfony\Component\HttpFoundation\RedirectResponse;
17
use Symfony\Component\HttpFoundation\Response;
18
use Symfony\Component\Routing\Annotation\Route;
19
20
/**
21
 * @Route("/oauth2/google", name="oauth2_google")
22
 */
23
class GoogleController extends AbstractController
24
{
25
    /**
26
     * @Route("/connect", name="_connect")
27
     */
28
    public function connectAction(ClientRegistry $clientRegistry): RedirectResponse
29
    {
30
        return $clientRegistry
31
            ->getClient('google')
32
            ->redirect([
33
                'https://www.googleapis.com/auth/userinfo.profile',
34
                'https://www.googleapis.com/auth/userinfo.email',
35
            ]);
36
    }
37
38
    /**
39
     * @Route("/check", name="_check")
40
     */
41
    public function connectCheckAction(): Response
42
    {
43
        if (!$this->getUser()) {
44
            return new JsonResponse(['status' => false, 'message' => 'User not found!'], JsonResponse::HTTP_UNAUTHORIZED);
45
        }
46
47
        return $this->redirectToRoute('site_page_contact');
48
    }
49
}
50