|
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\View\Model\ViewModel; |
|
15
|
|
|
use Zend\View\Model\JsonModel; |
|
16
|
|
|
use Auth\Repository\User as UserRepository; |
|
17
|
|
|
use Core\Form\SummaryFormInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* List registered users |
|
21
|
|
|
*/ |
|
22
|
|
|
class UsersController extends AbstractActionController |
|
23
|
|
|
{ |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var UserRepository |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $userRepository; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param UserRepository $userRepository |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct(UserRepository $userRepository) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->userRepository = $userRepository; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Login with username and password |
|
40
|
|
|
* |
|
41
|
|
|
* @return \Zend\Http\Response|ViewModel |
|
|
|
|
|
|
42
|
|
|
*/ |
|
43
|
|
|
public function listAction() |
|
44
|
|
|
{ |
|
45
|
|
|
/* @var \Zend\Http\Request $request */ |
|
46
|
|
|
$request = $this->getRequest(); |
|
47
|
|
|
$params = $request->getQuery(); |
|
48
|
|
|
|
|
49
|
|
|
$paginator = $this->paginator('Auth/User', $params); |
|
|
|
|
|
|
50
|
|
|
$form = $this->getServiceLocator()->get('forms') |
|
51
|
|
|
->get('Core/TextSearch', [ |
|
52
|
|
|
'placeholder' => /*@translate*/ 'Type name, email address, role, or login name', |
|
53
|
|
|
'button_element' => 'text' |
|
54
|
|
|
]); |
|
55
|
|
|
|
|
56
|
|
|
$return = array( |
|
57
|
|
|
'by' => $params['by'], |
|
58
|
|
|
'users' => $paginator, |
|
59
|
|
|
'form' => $form, |
|
60
|
|
|
); |
|
61
|
|
|
|
|
62
|
|
|
return $return; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Edit user |
|
67
|
|
|
* |
|
68
|
|
|
* @return \Zend\Http\Response|ViewModel |
|
|
|
|
|
|
69
|
|
|
*/ |
|
70
|
|
|
public function editAction() |
|
71
|
|
|
{ |
|
72
|
|
|
/* @var $user \Auth\Entity\User */ |
|
73
|
|
|
$user = $this->userRepository->find($this->params('id'), \Doctrine\ODM\MongoDB\LockMode::NONE, null, ['allowDeactivated' => true]); |
|
74
|
|
|
|
|
75
|
|
|
// check if user is not found |
|
76
|
|
|
if (!$user) { |
|
77
|
|
|
return $this->notFoundAction(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
$params = $this->params(); |
|
81
|
|
|
$serviceLocator = $this->getServiceLocator(); |
|
82
|
|
|
$forms = $serviceLocator->get('forms'); |
|
83
|
|
|
/* @var $infoContainer \Auth\Form\UserProfileContainer */ |
|
84
|
|
|
$infoContainer = $forms->get('Auth/userprofilecontainer'); |
|
85
|
|
|
$infoContainer->setEntity($user); |
|
86
|
|
|
$statusContainer = $forms->get('Auth/UserStatusContainer'); |
|
87
|
|
|
$statusContainer->setEntity($user); |
|
88
|
|
|
|
|
89
|
|
|
// set selected user to image strategy |
|
90
|
|
|
$imageStrategy = $infoContainer->getForm('info.image') |
|
|
|
|
|
|
91
|
|
|
->getHydrator() |
|
92
|
|
|
->getStrategy('image'); |
|
93
|
|
|
$fileEntity = $imageStrategy->getFileEntity(); |
|
94
|
|
|
$fileEntity->setUser($user); |
|
95
|
|
|
$imageStrategy->setFileEntity($fileEntity); |
|
96
|
|
|
|
|
97
|
|
|
if ($this->request->isPost()) { |
|
|
|
|
|
|
98
|
|
|
$formName = $params->fromQuery('form'); |
|
99
|
|
|
$container = $formName === 'status' ? $statusContainer : $infoContainer; |
|
100
|
|
|
$form = $container->getForm($formName); |
|
101
|
|
|
|
|
102
|
|
|
if ($form) { |
|
103
|
|
|
$postData = $form->getOption('use_post_array') ? $params->fromPost() : []; |
|
104
|
|
|
$filesData = $form->getOption('use_files_array') ? $params->fromFiles() : []; |
|
105
|
|
|
$form->setData(array_merge($postData, $filesData)); |
|
106
|
|
|
|
|
107
|
|
|
if (!$form->isValid()) { |
|
108
|
|
|
return new JsonModel( |
|
109
|
|
|
array( |
|
110
|
|
|
'valid' => false, |
|
111
|
|
|
'errors' => $form->getMessages(), |
|
112
|
|
|
) |
|
113
|
|
|
); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
$serviceLocator->get('repositories')->store($user); |
|
117
|
|
|
|
|
118
|
|
View Code Duplication |
if ('file-uri' === $params->fromPost('return')) { |
|
|
|
|
|
|
119
|
|
|
$content = $form->getHydrator()->getLastUploadedFile()->getUri(); |
|
120
|
|
|
} else { |
|
121
|
|
|
if ($form instanceof SummaryFormInterface) { |
|
122
|
|
|
$form->setRenderMode(SummaryFormInterface::RENDER_SUMMARY); |
|
123
|
|
|
$viewHelper = 'summaryform'; |
|
124
|
|
|
} else { |
|
125
|
|
|
$viewHelper = 'form'; |
|
126
|
|
|
} |
|
127
|
|
|
$content = $serviceLocator->get('ViewHelperManager')->get($viewHelper)->__invoke($form); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
return new JsonModel( |
|
131
|
|
|
array( |
|
132
|
|
|
'valid' => $form->isValid(), |
|
133
|
|
|
'content' => $content, |
|
134
|
|
|
) |
|
135
|
|
|
); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
return [ |
|
140
|
|
|
'infoContainer' => $infoContainer, |
|
141
|
|
|
'statusContainer' => $statusContainer |
|
142
|
|
|
]; |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|
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.