|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* AdminUserController |
|
5
|
|
|
* @copyright Copyright (c) 2011 - 2014 Aleksandr Torosh (http://wezoom.com.ua) |
|
6
|
|
|
* @author Aleksandr Torosh <[email protected]> |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Admin\Controller; |
|
10
|
|
|
|
|
11
|
|
|
use Application\Mvc\Controller; |
|
12
|
|
|
use Admin\Model\AdminUser; |
|
13
|
|
|
use Admin\Form\LoginForm; |
|
14
|
|
|
use Michelf\Markdown; |
|
15
|
|
|
use Phalcon\Mvc\View; |
|
16
|
|
|
|
|
17
|
|
|
class IndexController extends Controller |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
public function indexAction() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->setAdminEnvironment(); |
|
23
|
|
|
$this->view->languages_disabled = true; |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
$auth = $this->session->get('auth'); |
|
26
|
|
|
if (!$auth || !isset($auth->admin_session) || !$auth->admin_session) { |
|
27
|
|
|
$this->flash->notice($this->helper->at('Log in please')); |
|
28
|
|
|
$this->redirect($this->url->get() . 'admin/index/login'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
// Проверка пользователя yona |
|
32
|
|
|
$yona = AdminUser::findFirst("login = 'yona'"); |
|
|
|
|
|
|
33
|
|
|
if ($yona) { |
|
34
|
|
|
$this->flash->warning($this->helper->at('Warning. Found admin user with name yona')); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
if ($this->registry->cms['DISPLAY_CHANGELOG']) { |
|
|
|
|
|
|
38
|
|
|
$changelog = file_get_contents(APPLICATION_PATH . '/../CHANGELOG.md'); |
|
39
|
|
|
$changelog_html = Markdown::defaultTransform($changelog); |
|
40
|
|
|
$this->view->changelog = $changelog_html; |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$this->helper->title($this->helper->at('YonaCms Admin Panel'), true); |
|
44
|
|
|
|
|
45
|
|
|
$this->helper->activeMenu()->setActive('admin-home'); |
|
46
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function loginAction() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); |
|
52
|
|
|
|
|
53
|
|
|
$form = new LoginForm(); |
|
54
|
|
|
|
|
55
|
|
|
if ($this->request->isPost()) { |
|
56
|
|
|
if ($this->security->checkToken()) { |
|
57
|
|
|
if ($form->isValid($this->request->getPost())) { |
|
58
|
|
|
$login = $this->request->getPost('login', 'string'); |
|
59
|
|
|
$password = $this->request->getPost('password', 'string'); |
|
60
|
|
|
$user = AdminUser::findFirst("login='$login'"); |
|
|
|
|
|
|
61
|
|
|
if ($user) { |
|
62
|
|
|
if ($user->checkPassword($password)) { |
|
63
|
|
|
if ($user->isActive()) { |
|
64
|
|
|
$this->session->set('auth', $user->getAuthData()); |
|
65
|
|
|
$this->flash->success($this->helper->translate("Welcome to the administrative control panel!")); |
|
66
|
|
|
return $this->redirect($this->url->get() . 'admin'); |
|
67
|
|
|
} else { |
|
68
|
|
|
$this->flash->error($this->helper->translate("User is not activated yet")); |
|
69
|
|
|
} |
|
70
|
|
|
} else { |
|
71
|
|
|
$this->flash->error($this->helper->translate("Incorrect login or password")); |
|
72
|
|
|
} |
|
73
|
|
|
} else { |
|
74
|
|
|
$this->flash->error($this->helper->translate("Incorrect login or password")); |
|
75
|
|
|
} |
|
76
|
|
|
} else { |
|
77
|
|
|
foreach ($form->getMessages() as $message) { |
|
|
|
|
|
|
78
|
|
|
$this->flash->error($message); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
} else { |
|
82
|
|
|
$this->flash->error($this->helper->translate("Security errors")); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$this->view->form = $form; |
|
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function logoutAction() |
|
91
|
|
|
{ |
|
92
|
|
|
if ($this->request->isPost()) { |
|
93
|
|
|
if ($this->security->checkToken()) { |
|
94
|
|
|
$this->session->remove('auth'); |
|
95
|
|
|
} else { |
|
96
|
|
|
$this->flash->error("Security errors"); |
|
97
|
|
|
} |
|
98
|
|
|
} else { |
|
99
|
|
|
$this->flash->error("Security errors"); |
|
100
|
|
|
} |
|
101
|
|
|
$this->redirect($this->url->get()); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: