[ 'class' => VerbFilter::class, 'actions' => [ ], ], 'access' => [ 'class' => AccessControl::class, 'rules' => [ [ 'allow' => true, 'roles' => ['@'], ] ], ], ]; } /** * Updates an existing User model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate() { $idUser = GlobalParam::getCurrentUserId(); $model = $this->findModel($idUser); if ($model->load($this->getRequest()->post()) && $model->validate()) { // l'utilisateur ne peut pas changer d'adresse email $oldModel = $this->findModel($idUser); $model->email = $oldModel->email; // modification du mot de passe if (strlen($model->password_new)) { $model->password_hash = \Yii::$app->security->generatePasswordHash($model->password_new); $model->password_old = ''; $model->password_new = ''; $model->password_new_confirm = ''; } $model->save(); $this->setFlash('success', 'Votre profil a bien été modifié.'); return $this->render('update', [ 'model' => $model, ]); } else { if (!$model->validate()) { $this->setFlash('error', 'Le formulaire comporte des erreurs.'); } return $this->render('update', [ 'model' => $model, ]); } } /** * Finds the User model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return User the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { $userRepository = $this->getUserManager(); if (($model = $userRepository->findOneUserById($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } }