GoogleController::connectAction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 4
cp 0
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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