1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class UserController extends Zend_Controller_Action |
|
|
|
|
4
|
|
|
{ |
5
|
3 |
|
public function init(): void |
6
|
|
|
{ |
7
|
|
|
// Initialize action controller here |
8
|
3 |
|
} |
9
|
|
|
|
10
|
1 |
|
public function indexAction(): void |
11
|
|
|
{ |
12
|
1 |
|
$this->view->users = \mQueue\Model\UserMapper::fetchAll(); |
13
|
1 |
|
} |
14
|
|
|
|
15
|
2 |
|
public function newAction() |
|
|
|
|
16
|
|
|
{ |
17
|
2 |
|
$request = $this->getRequest(); |
18
|
2 |
|
$form = new \mQueue\Form\User(); |
19
|
|
|
|
20
|
2 |
|
if ($this->getRequest()->isPost()) { |
21
|
2 |
|
if ($form->isValid($request->getPost())) { |
22
|
2 |
|
$values = $form->getValues(); |
23
|
2 |
|
$user = \mQueue\Model\UserMapper::insertUser($values); |
24
|
|
|
|
25
|
2 |
|
\mQueue\Model\User::setCurrent($user); |
26
|
|
|
|
27
|
2 |
|
$this->_helper->FlashMessenger('Subscription complete.'); |
28
|
|
|
|
29
|
2 |
|
return $this->_helper->redirector('index', 'movie'); |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
2 |
|
$this->view->form = $form; |
34
|
2 |
|
} |
35
|
|
|
|
36
|
1 |
|
public function loginAction() |
|
|
|
|
37
|
|
|
{ |
38
|
1 |
|
$request = $this->getRequest(); |
39
|
1 |
|
$form = new \mQueue\Form\Login(); |
40
|
|
|
|
41
|
1 |
|
if ($this->getRequest()->isPost()) { |
42
|
1 |
|
if ($form->isValid($request->getPost())) { |
43
|
1 |
|
$values = $form->getValues(); |
44
|
|
|
|
45
|
1 |
|
$user = \mQueue\Model\UserMapper::findEmailPassword($values['email'], $values['password']); |
46
|
1 |
|
if ($user) { |
47
|
1 |
|
Zend_Session::rememberMe(1 * 60 * 60 * 24 * 31 * 2); // Cookie for two months |
48
|
|
|
|
49
|
1 |
|
\mQueue\Model\User::setCurrent($user); |
50
|
|
|
|
51
|
1 |
|
$this->_helper->FlashMessenger('Logged in.'); |
52
|
|
|
|
53
|
1 |
|
$referrer = $values['referrer']; |
54
|
|
|
|
55
|
|
|
// If we have a valid referer to one page of ourselve (except login or logout), redirect to it |
56
|
1 |
|
if (mb_strpos($referrer, $this->view->serverUrl() . $this->view->baseUrl()) === 0 |
57
|
1 |
|
&& mb_strpos($referrer, $this->view->serverUrl() . $this->view->url(['controller' => 'user', 'action' => 'login'])) !== 0 |
58
|
1 |
|
&& mb_strpos($referrer, $this->view->serverUrl() . $this->view->url(['controller' => 'user', 'action' => 'logout'])) !== 0) { |
59
|
|
|
return $this->_redirect($values['referrer']); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
return $this->_helper->redirector('index', 'movie'); |
63
|
|
|
} |
64
|
|
|
$this->_helper->FlashMessenger(['error' => 'Login failed.']); |
65
|
|
|
} |
66
|
|
|
} else { |
67
|
|
|
$form->setDefaults([ |
68
|
|
|
'referrer' => $this->getRequest()->getServer('HTTP_REFERER'), |
69
|
|
|
]); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$this->view->form = $form; |
73
|
|
|
} |
74
|
|
|
|
75
|
1 |
|
public function logoutAction(): void |
76
|
|
|
{ |
77
|
1 |
|
\mQueue\Model\User::setCurrent(null); |
78
|
1 |
|
} |
79
|
|
|
|
80
|
|
View Code Duplication |
public function viewAction(): void |
|
|
|
|
81
|
|
|
{ |
82
|
|
|
if ($this->getRequest()->getParam('id')) { |
83
|
|
|
$this->view->user = \mQueue\Model\UserMapper::find($this->getRequest()->getParam('id')); |
84
|
|
|
} else { |
85
|
|
|
$this->view->user = \mQueue\Model\User::getCurrent(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if (!$this->view->user) { |
89
|
|
|
throw new Exception($this->view->translate('User not found')); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$this->view->userActivity = $this->_helper->createPaginator(\mQueue\Model\StatusMapper::getActivityQuery($this->view->user)); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.