Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

95 lines
2.4KB

  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. /**
  11. * UserController implements the CRUD actions for User model.
  12. */
  13. class UserController extends Controller
  14. {
  15. public function behaviors()
  16. {
  17. return [
  18. 'verbs' => [
  19. 'class' => VerbFilter::className(),
  20. 'actions' => [
  21. ],
  22. ],
  23. 'access' => [
  24. 'class' => AccessControl::className(),
  25. 'rules' => [
  26. [
  27. 'allow' => true,
  28. 'roles' => ['@'],
  29. /*'matchCallback' => function ($rule, $action) {
  30. return Yii::$app->user->identity->status == USER::STATUS_ADMIN ;
  31. }*/
  32. ]
  33. ],
  34. ],
  35. ];
  36. }
  37. /**
  38. * Updates an existing User model.
  39. * If update is successful, the browser will be redirected to the 'view' page.
  40. * @param integer $id
  41. * @return mixed
  42. */
  43. public function actionUpdate()
  44. {
  45. $model = $this->findModel(Yii::$app->user->identity->id);
  46. if ($model->load(Yii::$app->request->post())) {
  47. // l'utilisateur ne peut pas changer d'adresse email
  48. $old_model = $this->findModel(Yii::$app->user->identity->id) ;
  49. $model->email = $old_model->email ;
  50. $model->save() ;
  51. return $this->render('update', [
  52. 'model' => $model,
  53. 'edit_ok' => true
  54. ]);
  55. } else {
  56. return $this->render('update', [
  57. 'model' => $model,
  58. ]);
  59. }
  60. }
  61. public function actionCredit()
  62. {
  63. return $this->render('credit', [
  64. ]);
  65. }
  66. /**
  67. * Finds the User model based on its primary key value.
  68. * If the model is not found, a 404 HTTP exception will be thrown.
  69. * @param integer $id
  70. * @return User the loaded model
  71. * @throws NotFoundHttpException if the model cannot be found
  72. */
  73. protected function findModel($id)
  74. {
  75. if (($model = User::findOne($id)) !== null) {
  76. return $model;
  77. } else {
  78. throw new NotFoundHttpException('The requested page does not exist.');
  79. }
  80. }
  81. }