преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
преди 8 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace frontend\controllers;
  3. use Yii;
  4. use common\models\User;
  5. use yii\data\ActiveDataProvider;
  6. use yii\web\Controller;
  7. use yii\web\NotFoundHttpException;
  8. use yii\filters\VerbFilter;
  9. use yii\filters\AccessControl;
  10. use frontend\controllers\FrontendController;
  11. /**
  12. * UserController implements the CRUD actions for User model.
  13. */
  14. class UserController extends FrontendController
  15. {
  16. public function behaviors()
  17. {
  18. return [
  19. 'verbs' => [
  20. 'class' => VerbFilter::className(),
  21. 'actions' => [
  22. ],
  23. ],
  24. 'access' => [
  25. 'class' => AccessControl::className(),
  26. 'rules' => [
  27. [
  28. 'allow' => true,
  29. 'roles' => ['@'],
  30. /*'matchCallback' => function ($rule, $action) {
  31. return Yii::$app->user->identity->status == USER::STATUS_ADMIN ;
  32. }*/
  33. ]
  34. ],
  35. ],
  36. ];
  37. }
  38. /**
  39. * Updates an existing User model.
  40. * If update is successful, the browser will be redirected to the 'view' page.
  41. * @param integer $id
  42. * @return mixed
  43. */
  44. public function actionUpdate()
  45. {
  46. $model = $this->findModel(Yii::$app->user->identity->id);
  47. if ($model->load(Yii::$app->request->post()) && $model->validate()) {
  48. // l'utilisateur ne peut pas changer d'adresse email
  49. $old_model = $this->findModel(Yii::$app->user->identity->id) ;
  50. $model->email = $old_model->email ;
  51. // modification du mot de passe
  52. if(strlen($model->password_new))
  53. {
  54. //$model->setPassword($model->password_new) ;
  55. $model->password_hash = Yii::$app->security->generatePasswordHash($model->password_new);
  56. $model->password_old = '' ;
  57. $model->password_new = '' ;
  58. $model->password_new_confirm = '' ;
  59. }
  60. $model->save() ;
  61. Yii::$app->session->setFlash('success','Votre profil a bien été modifié.') ;
  62. return $this->render('update', [
  63. 'model' => $model,
  64. ]);
  65. } else {
  66. if(!$model->validate())
  67. {
  68. Yii::$app->session->setFlash('error','Le formulaire comporte des erreurs.') ;
  69. }
  70. return $this->render('update', [
  71. 'model' => $model,
  72. ]);
  73. }
  74. }
  75. public function actionCredit()
  76. {
  77. return $this->render('credit', [
  78. ]);
  79. }
  80. /**
  81. * Finds the User model based on its primary key value.
  82. * If the model is not found, a 404 HTTP exception will be thrown.
  83. * @param integer $id
  84. * @return User the loaded model
  85. * @throws NotFoundHttpException if the model cannot be found
  86. */
  87. protected function findModel($id)
  88. {
  89. if (($model = User::findOne($id)) !== null) {
  90. return $model;
  91. } else {
  92. throw new NotFoundHttpException('The requested page does not exist.');
  93. }
  94. }
  95. }