Projekt

Obecné

Profil

Stáhnout (2.15 KB) Statistiky
| Větev: | Tag: | Revize:
1
<?php
2

    
3
namespace App\FrontModule\Presenters;
4

    
5
use App\FrontModule\Components\IUserSettingsFormFactory;
6
use App\FrontModule\Components\ILoginFormFactory;
7
use App\Enum\EFlashMessage;
8
use App\Model\Repository\SettingsRepository;
9
use Nette;
10

    
11

    
12
final class HomepagePresenter extends Nette\Application\UI\Presenter
13
{
14
    /** @var ILoginFormFactory */
15
    private $loginFormFactory;
16

    
17
    /** @var IUserSettingsFormFactory */
18
    private $userSettingsFormFactory;
19
    /**
20
     * @var SettingsRepository
21
     */
22
    private $settingsRepository;
23

    
24
    public function __construct(ILoginFormFactory $loginFormFactory,
25
                                IUserSettingsFormFactory $userSettingsFormFactory,
26
                                SettingsRepository $settingsRepository
27
    )
28
    {
29
        parent::__construct();
30

    
31
        $this->loginFormFactory = $loginFormFactory;
32
        $this->userSettingsFormFactory = $userSettingsFormFactory;
33
        $this->settingsRepository = $settingsRepository;
34
    }
35

    
36
    public function actionDefault()
37
    {
38
        $settings = $this->settingsRepository->getHomepageSettings();
39
        $this->template->settings = $settings;
40
    }
41

    
42
    public function actionUserSettings()
43
    {
44
        if (!$this->getUser()->isLoggedIn())
45
        {
46
            $this->redirect('Homepage:default');
47
        }
48
    }
49

    
50
    public function actionLogin()
51
    {
52
        if ($this->user->isLoggedIn())
53
        {
54
            $this->redirect('Homepage:default');
55
        }
56
    }
57

    
58
    public function actionLogout()
59
    {
60
        if ($this->getUser()->isLoggedIn())
61
        {
62
            $this->user->logout(true);
63

    
64
            $this->flashMessage('Odhlášení bylo úspěšné.', EFlashMessage::SUCCESS);
65
            $this->redirect('Homepage:default');
66
        }
67
    }
68

    
69
    /**
70
     * Komponenta přihlašovacího formuláře
71
     *
72
     * @return \App\FrontModule\Components\LoginForm
73
     */
74
    public function createComponentLoginForm()
75
    {
76
        return $this->loginFormFactory->create();
77
    }
78

    
79
    /**
80
     * @return \App\FrontModule\Components\UserSettingsForm
81
     */
82
    public function createComponentUserSettingsForm(){
83
        return $this->userSettingsFormFactory->create();
84
    }
85
}
(5-5/6)