AuthController::logoutAction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace SkautisBundle\Controller;
4
5
use SkautisBundle\EventDispatcher\Event\SkautisLoginAttemptEvent;
6
use SkautisBundle\EventDispatcher\Event\SkautisLoginSuccessEvent;
7
use SkautisBundle\EventDispatcher\Event\SkautisLogoutAttemptEvent;
8
use SkautisBundle\EventDispatcher\Event\SkautisLogoutSuccessEvent;
9
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
10
use Symfony\Component\HttpFoundation\Request;
11
12
/**
13
 * Trida pro authentikaci uzivatele pomoci is.skaut.cz
14
 * Uzivatele neuklada do lokalni databaze
15
 */
16
class AuthController extends Controller
17
{
18
    /**
19
     * Presmeruje uzivatele na is.skaut.cz login
20
     */
21
    public function loginAction()
22
    {
23
        $event = new SkautisLoginAttemptEvent();
24
        $this->get("event_dispatcher")->dispatch(SkautisLoginAttemptEvent::EVENT_NAME, $event);
25
26
        $loginUrl = $this->get('skautis')->getLoginUrl();
27
        return $this->redirect($loginUrl);
28
    }
29
30
    /**
31
     * Overi prihlaseni uzivatele. Skautis presmeruje sem po uspesnem prihlaseni.
32
     */
33
    public function loginConfirmAction(Request $request)
34
    {
35
36
        $skautis = $this->get('skautis');
37
        $skautis->setLoginData($request->request->all());
38
39
        if (!$skautis->getUser()->isLoggedIn(true)) {
40
            $skautis->getUser()->resetLoginData();
41
            return $this->redirect($skautis->getLoginUrl());
42
        }
43
44
        $event = new SkautisLoginSuccessEvent();
45
        $this->get("event_dispatcher")->dispatch(SkautisLoginSuccessEvent::EVENT_NAME, $event);
46
47
        $this->addFlash('notice', 'Byl/a jste prihlasena');
48
49
        $redirectRoute = $this->container->getParameter('skautis.after_login_redirect');
50
        return $this->redirectToRoute($redirectRoute);
51
    }
52
53
    /**
54
     * Odhlasi uzivatele z is.skaut.cz
55
     */
56
    public function logoutAction()
57
    {
58
59
        $event = new SkautisLogoutAttemptEvent();
60
        $this->get("event_dispatcher")->dispatch(SkautisLogoutAttemptEvent::EVENT_NAME, $event);
61
62
        $logoutUrl = $this->get('skautis')->getLogoutUrl();
63
        return $this->redirect($logoutUrl);
64
    }
65
66
    /**
67
     * Odhlasi uzivatele z is.skaut.cz
68
     */
69
    public function logoutConfirmAction()
70
    {
71
        $this->get('session')->invalidate();
72
        $this->addFlash('notice', 'Byl/a jste odhlasena');
73
74
        $event = new SkautisLogoutSuccessEvent();
75
        $this->get("event_dispatcher")->dispatch(SkautisLogoutSuccessEvent::EVENT_NAME, $event);
76
77
        $redirectRoute = $this->container->getParameter('skautis.after_logout_redirect');
78
        return $this->redirectToRoute($redirectRoute);
79
    }
80
81
    /**
82
     * Presmeruje uzivatele na registracni furmalr na is.skaut.cz
83
     */
84
    public function registerAction()
85
    {
86
87
        $registerUrl = $this->get('skautis')->getRegisterUrl();
88
        return $this->redirect($registerUrl);
89
    }
90
91
}
92