|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** Auth controller */ |
|
11
|
|
|
namespace Auth\Controller; |
|
12
|
|
|
|
|
13
|
|
|
use Zend\Mvc\Controller\AbstractActionController; |
|
14
|
|
|
use Zend\Session\Container; |
|
15
|
|
|
use Zend\View\Model\ViewModel; |
|
16
|
|
|
use Zend\View\Model\JsonModel; |
|
17
|
|
|
use Auth\Repository\User as UserRepository; |
|
18
|
|
|
use Core\Form\SummaryFormInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* List registered users |
|
22
|
|
|
* |
|
23
|
|
|
* @method \Core\Controller\Plugin\CreatePaginator pagination() |
|
24
|
|
|
*/ |
|
25
|
|
|
class UsersController extends AbstractActionController |
|
26
|
|
|
{ |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var UserRepository |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $userRepository; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param UserRepository $userRepository |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct(UserRepository $userRepository) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->userRepository = $userRepository; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* List users |
|
43
|
|
|
* |
|
44
|
|
|
* @return \Zend\Http\Response|ViewModel |
|
|
|
|
|
|
45
|
|
|
*/ |
|
46
|
|
View Code Duplication |
public function listAction() |
|
|
|
|
|
|
47
|
|
|
{ |
|
48
|
|
|
return $this->pagination([ |
|
|
|
|
|
|
49
|
|
|
'paginator' => ['Auth/User', 'as' => 'users'], |
|
50
|
|
|
'form' => [ |
|
51
|
|
|
'Core/Search', |
|
52
|
|
|
[ |
|
53
|
|
|
'text_name' => 'text', |
|
54
|
|
|
'text_placeholder' => /*@translate*/ 'Type name, email address, role, or login name', |
|
55
|
|
|
'button_element' => 'text', |
|
56
|
|
|
], |
|
57
|
|
|
'as' => 'form' |
|
58
|
|
|
], |
|
59
|
|
|
]); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Edit user |
|
64
|
|
|
* |
|
65
|
|
|
* @return \Zend\Http\Response|ViewModel |
|
|
|
|
|
|
66
|
|
|
*/ |
|
67
|
|
|
public function editAction() |
|
68
|
|
|
{ |
|
69
|
|
|
/* @var $user \Auth\Entity\User */ |
|
70
|
|
|
$user = $this->userRepository->find($this->params('id'), \Doctrine\ODM\MongoDB\LockMode::NONE, null, ['allowDeactivated' => true]); |
|
71
|
|
|
|
|
72
|
|
|
// check if user is not found |
|
73
|
|
|
if (!$user) { |
|
74
|
|
|
return $this->notFoundAction(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$params = $this->params(); |
|
78
|
|
|
$serviceLocator = $this->serviceLocator; |
|
79
|
|
|
$forms = $serviceLocator->get('forms'); |
|
80
|
|
|
/* @var $infoContainer \Auth\Form\UserProfileContainer */ |
|
81
|
|
|
$infoContainer = $forms->get('Auth/userprofilecontainer'); |
|
82
|
|
|
$infoContainer->setEntity($user); |
|
83
|
|
|
$statusContainer = $forms->get('Auth/UserStatusContainer'); |
|
84
|
|
|
$statusContainer->setEntity($user); |
|
85
|
|
|
|
|
86
|
|
|
// set selected user to image strategy |
|
87
|
|
|
$imageStrategy = $infoContainer->getForm('info.image') |
|
|
|
|
|
|
88
|
|
|
->getHydrator() |
|
89
|
|
|
->getStrategy('image'); |
|
90
|
|
|
$fileEntity = $imageStrategy->getFileEntity(); |
|
91
|
|
|
$fileEntity->setUser($user); |
|
92
|
|
|
$imageStrategy->setFileEntity($fileEntity); |
|
93
|
|
|
|
|
94
|
|
|
if ($this->request->isPost()) { |
|
|
|
|
|
|
95
|
|
|
$formName = $params->fromQuery('form'); |
|
96
|
|
|
$container = $formName === 'status' ? $statusContainer : $infoContainer; |
|
97
|
|
|
$form = $container->getForm($formName); |
|
98
|
|
|
|
|
99
|
|
|
if ($form) { |
|
100
|
|
|
$postData = $form->getOption('use_post_array') ? $params->fromPost() : []; |
|
101
|
|
|
$filesData = $form->getOption('use_files_array') ? $params->fromFiles() : []; |
|
102
|
|
|
$form->setData(array_merge($postData, $filesData)); |
|
103
|
|
|
|
|
104
|
|
|
if (!$form->isValid()) { |
|
105
|
|
|
return new JsonModel( |
|
106
|
|
|
array( |
|
107
|
|
|
'valid' => false, |
|
108
|
|
|
'errors' => $form->getMessages(), |
|
109
|
|
|
) |
|
110
|
|
|
); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
$serviceLocator->get('repositories')->store($user); |
|
114
|
|
|
|
|
115
|
|
View Code Duplication |
if ('file-uri' === $params->fromPost('return')) { |
|
|
|
|
|
|
116
|
|
|
$content = $form->getHydrator()->getLastUploadedFile()->getUri(); |
|
117
|
|
|
} else { |
|
118
|
|
|
if ($form instanceof SummaryFormInterface) { |
|
119
|
|
|
$form->setRenderMode(SummaryFormInterface::RENDER_SUMMARY); |
|
120
|
|
|
$viewHelper = 'summaryform'; |
|
121
|
|
|
} else { |
|
122
|
|
|
$viewHelper = 'form'; |
|
123
|
|
|
} |
|
124
|
|
|
$content = $serviceLocator->get('ViewHelperManager')->get($viewHelper)->__invoke($form); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
return new JsonModel( |
|
128
|
|
|
array( |
|
129
|
|
|
'valid' => $form->isValid(), |
|
130
|
|
|
'content' => $content, |
|
131
|
|
|
) |
|
132
|
|
|
); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
return [ |
|
137
|
|
|
'infoContainer' => $infoContainer, |
|
138
|
|
|
'statusContainer' => $statusContainer |
|
139
|
|
|
]; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
public function switchAction() |
|
143
|
|
|
{ |
|
144
|
|
|
/* @var \Auth\Controller\Plugin\UserSwitcher $switcher */ |
|
145
|
|
|
$do = $this->params()->fromQuery('do'); |
|
146
|
|
|
if ('clear' == $do) { |
|
147
|
|
|
$switcher = $this->plugin('Auth/User/Switcher'); |
|
148
|
|
|
$success = $switcher(); |
|
149
|
|
|
|
|
150
|
|
|
return new JsonModel(['success' => $success]); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
$this->acl('Auth/Users', 'admin-access'); |
|
|
|
|
|
|
154
|
|
|
|
|
155
|
|
|
if ('list' == $do) { |
|
156
|
|
|
/* @var \Auth\Entity\User $user */ |
|
157
|
|
|
/* @var \Zend\Paginator\Paginator $paginator */ |
|
158
|
|
|
$paginator = $this->paginator('Auth/User', ['page' => 1]); |
|
|
|
|
|
|
159
|
|
|
$result = []; |
|
160
|
|
|
|
|
161
|
|
|
foreach ($paginator as $user) { |
|
162
|
|
|
$result[] = [ |
|
163
|
|
|
'id' => $user->getId(), |
|
164
|
|
|
'name' => $user->getInfo()->getDisplayName(false), |
|
165
|
|
|
'email' => $user->getInfo()->getEmail(), |
|
166
|
|
|
'login' => $user->getLogin() |
|
167
|
|
|
]; |
|
168
|
|
|
} |
|
169
|
|
|
return new JsonModel([ |
|
170
|
|
|
'items' => $result, |
|
171
|
|
|
'total' => $paginator->getTotalItemCount(), |
|
172
|
|
|
]); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
$switcher = $this->plugin('Auth/User/Switcher'); |
|
176
|
|
|
$success = $switcher($this->params()->fromQuery('id')); |
|
|
|
|
|
|
177
|
|
|
|
|
178
|
|
|
return new JsonModel(['success' => true]); |
|
179
|
|
|
} |
|
180
|
|
|
} |
|
181
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.