1 | <?php |
||
38 | class AdminController extends Controller |
||
39 | { |
||
40 | use ContainerAwareTrait; |
||
41 | use ModuleAwareTrait; |
||
42 | |||
43 | /** |
||
44 | * @var UserQuery |
||
45 | */ |
||
46 | protected $userQuery; |
||
47 | |||
48 | /** |
||
49 | * AdminController constructor. |
||
50 | * |
||
51 | * @param string $id |
||
52 | * @param Module $module |
||
53 | * @param UserQuery $userQuery |
||
54 | * @param array $config |
||
55 | */ |
||
56 | 2 | public function __construct($id, Module $module, UserQuery $userQuery, array $config = []) |
|
57 | { |
||
58 | 2 | $this->userQuery = $userQuery; |
|
59 | 2 | parent::__construct($id, $module, $config); |
|
60 | 2 | } |
|
61 | |||
62 | /** |
||
63 | * @param \yii\base\Action $action |
||
64 | * |
||
65 | * @return bool |
||
66 | */ |
||
67 | 2 | public function beforeAction($action) |
|
68 | { |
||
69 | 2 | if (in_array($action->id, ['index', 'update', 'update-profile', 'info', 'assignments'], true)) { |
|
70 | 1 | Url::remember('', 'actions-redirect'); |
|
71 | } |
||
72 | |||
73 | 2 | return parent::beforeAction($action); |
|
74 | } |
||
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | */ |
||
79 | 2 | public function behaviors() |
|
80 | { |
||
81 | return [ |
||
82 | 2 | 'verbs' => [ |
|
83 | 'class' => VerbFilter::class, |
||
84 | 'actions' => [ |
||
85 | 'delete' => ['post'], |
||
86 | 'confirm' => ['post'], |
||
87 | 'block' => ['post'], |
||
88 | 'switch-identity' => ['post'], |
||
89 | 'password-reset' => ['post'], |
||
90 | 'force-password-change' => ['post'], |
||
91 | ], |
||
92 | ], |
||
93 | 'access' => [ |
||
94 | 'class' => AccessControl::class, |
||
95 | 'ruleConfig' => [ |
||
96 | 'class' => AccessRuleFilter::class, |
||
97 | ], |
||
98 | 'rules' => [ |
||
99 | [ |
||
100 | 'allow' => true, |
||
101 | 'actions' => ['switch-identity'], |
||
102 | 'roles' => ['@'], |
||
103 | ], |
||
104 | [ |
||
105 | 'allow' => true, |
||
106 | 'roles' => ['admin'], |
||
107 | ], |
||
108 | ], |
||
109 | ], |
||
110 | ]; |
||
111 | } |
||
112 | |||
113 | public function actionIndex() |
||
114 | { |
||
115 | $searchModel = $this->make(UserSearch::class); |
||
116 | $dataProvider = $searchModel->search(Yii::$app->request->get()); |
||
117 | |||
118 | return $this->render( |
||
119 | 'index', |
||
120 | [ |
||
121 | 'dataProvider' => $dataProvider, |
||
122 | 'searchModel' => $searchModel, |
||
123 | ] |
||
124 | ); |
||
125 | } |
||
126 | |||
127 | 1 | public function actionCreate() |
|
128 | { |
||
129 | /** @var User $user */ |
||
130 | 1 | $user = $this->make(User::class, [], ['scenario' => 'create']); |
|
131 | |||
132 | /** @var UserEvent $event */ |
||
133 | 1 | $event = $this->make(UserEvent::class, [$user]); |
|
134 | |||
135 | 1 | $this->make(AjaxRequestModelValidator::class, [$user])->validate(); |
|
136 | |||
137 | 1 | if ($user->load(Yii::$app->request->post()) && $user->validate()) { |
|
138 | 1 | $this->trigger(UserEvent::EVENT_BEFORE_CREATE, $event); |
|
139 | |||
140 | 1 | $mailService = MailFactory::makeWelcomeMailerService($user); |
|
141 | |||
142 | 1 | if ($this->make(UserCreateService::class, [$user, $mailService])->run()) { |
|
143 | Yii::$app->getSession()->setFlash('success', Yii::t('usuario', 'User has been created')); |
||
|
|||
144 | $this->trigger(UserEvent::EVENT_AFTER_CREATE, $event); |
||
145 | return $this->redirect(['update', 'id' => $user->id]); |
||
146 | } |
||
147 | 1 | Yii::$app->session->setFlash('danger', Yii::t('usuario', 'User account could not be created.')); |
|
148 | } |
||
149 | |||
150 | 1 | return $this->render('create', ['user' => $user]); |
|
151 | } |
||
152 | |||
153 | 1 | public function actionUpdate($id) |
|
154 | { |
||
155 | 1 | $user = $this->userQuery->where(['id' => $id])->one(); |
|
156 | 1 | $user->setScenario('update'); |
|
157 | /** @var UserEvent $event */ |
||
158 | 1 | $event = $this->make(UserEvent::class, [$user]); |
|
159 | |||
160 | 1 | $this->make(AjaxRequestModelValidator::class, [$user])->validate(); |
|
161 | |||
162 | 1 | if ($user->load(Yii::$app->request->post())) { |
|
163 | 1 | $this->trigger(UserEvent::EVENT_BEFORE_ACCOUNT_UPDATE, $event); |
|
164 | |||
165 | 1 | if ($user->save()) { |
|
166 | 1 | Yii::$app->getSession()->setFlash('success', Yii::t('usuario', 'Account details have been updated')); |
|
167 | 1 | $this->trigger(UserEvent::EVENT_AFTER_ACCOUNT_UPDATE, $event); |
|
168 | |||
169 | 1 | return $this->refresh(); |
|
170 | } |
||
171 | } |
||
172 | |||
173 | 1 | return $this->render('_account', ['user' => $user]); |
|
174 | } |
||
175 | |||
176 | public function actionUpdateProfile($id) |
||
177 | { |
||
178 | /** @var User $user */ |
||
179 | $user = $this->userQuery->where(['id' => $id])->one(); |
||
180 | /** @var Profile $profile */ |
||
181 | $profile = $user->profile; |
||
182 | if ($profile === null) { |
||
183 | $profile = $this->make(Profile::class); |
||
184 | $profile->link('user', $user); |
||
185 | } |
||
186 | /** @var UserEvent $event */ |
||
187 | $event = $this->make(UserEvent::class, [$user]); |
||
188 | |||
189 | $this->make(AjaxRequestModelValidator::class, [$profile])->validate(); |
||
190 | |||
191 | if ($profile->load(Yii::$app->request->post())) { |
||
192 | if ($profile->save()) { |
||
193 | $this->trigger(UserEvent::EVENT_BEFORE_PROFILE_UPDATE, $event); |
||
194 | Yii::$app->getSession()->setFlash('success', Yii::t('usuario', 'Profile details have been updated')); |
||
195 | $this->trigger(UserEvent::EVENT_AFTER_PROFILE_UPDATE, $event); |
||
196 | |||
197 | return $this->refresh(); |
||
198 | } |
||
199 | } |
||
200 | |||
201 | return $this->render( |
||
202 | '_profile', |
||
203 | [ |
||
204 | 'user' => $user, |
||
205 | 'profile' => $profile, |
||
206 | ] |
||
207 | ); |
||
208 | } |
||
209 | |||
210 | public function actionInfo($id) |
||
211 | { |
||
212 | /** @var User $user */ |
||
213 | $user = $this->userQuery->where(['id' => $id])->one(); |
||
214 | |||
215 | return $this->render( |
||
216 | '_info', |
||
217 | [ |
||
218 | 'user' => $user, |
||
219 | ] |
||
220 | ); |
||
221 | } |
||
222 | |||
223 | public function actionAssignments($id) |
||
224 | { |
||
225 | /** @var User $user */ |
||
226 | $user = $this->userQuery->where(['id' => $id])->one(); |
||
227 | |||
228 | return $this->render( |
||
229 | '_assignments', |
||
230 | [ |
||
231 | 'user' => $user, |
||
232 | 'params' => Yii::$app->request->post(), |
||
233 | ] |
||
234 | ); |
||
235 | } |
||
236 | |||
237 | public function actionConfirm($id) |
||
258 | |||
259 | public function actionDelete($id) |
||
283 | |||
284 | public function actionBlock($id) |
||
303 | |||
304 | public function actionSwitchIdentity($id = null) |
||
305 | { |
||
306 | if (false === $this->module->enableSwitchIdentities) { |
||
307 | Yii::$app->getSession()->setFlash('danger', Yii::t('usuario', 'Switch identities is disabled.')); |
||
308 | |||
309 | return $this->redirect(['index']); |
||
310 | } |
||
311 | |||
316 | |||
317 | public function actionPasswordReset($id) |
||
333 | |||
334 | /** |
||
335 | * Forces the user to change password at next login |
||
336 | * @param integer $id |
||
337 | */ |
||
338 | public function actionForcePasswordChange($id) |
||
349 | } |
||
350 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: