|
- <?php
-
-
-
- namespace frontend\controllers;
-
- use common\helpers\GlobalParam;
- use domain\User\User\User;
- use yii\filters\AccessControl;
- use yii\filters\VerbFilter;
- use yii\web\NotFoundHttpException;
-
-
- class UserController extends FrontendController
- {
-
- public function behaviors()
- {
- return [
- 'verbs' => [
- 'class' => VerbFilter::class,
- 'actions' => [
- ],
- ],
- 'access' => [
- 'class' => AccessControl::class,
- 'rules' => [
- [
- 'allow' => true,
- 'roles' => ['@'],
- ]
- ],
- ],
- ];
- }
-
-
-
- public function actionUpdate()
- {
- $idUser = GlobalParam::getCurrentUserId();
- $model = $this->findModel($idUser);
-
- if ($model->load($this->getRequest()->post())
- && $model->validate()) {
-
-
- 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,
- ]);
- }
- }
-
-
-
- protected function findModel($id)
- {
- $userRepository = $this->getUserModule();
-
- if (($model = $userRepository->findOneUserById($id)) !== null) {
- return $model;
- }
- else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- }
|