You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UserController.php 4.4KB

8 jaren geleden
8 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. namespace backend\controllers;
  3. use Yii;
  4. use common\models\User;
  5. use backend\models\MailForm;
  6. use yii\data\ActiveDataProvider;
  7. use yii\web\Controller;
  8. use yii\web\NotFoundHttpException;
  9. use yii\filters\VerbFilter;
  10. use yii\filters\AccessControl;
  11. /**
  12. * UserController implements the CRUD actions for User model.
  13. */
  14. class UserController extends Controller
  15. {
  16. public function behaviors()
  17. {
  18. return [
  19. 'verbs' => [
  20. 'class' => VerbFilter::className(),
  21. 'actions' => [
  22. 'delete' => ['post'],
  23. ],
  24. ],
  25. 'access' => [
  26. 'class' => AccessControl::className(),
  27. 'rules' => [
  28. [
  29. 'allow' => true,
  30. 'roles' => ['@'],
  31. 'matchCallback' => function ($rule, $action) {
  32. return Yii::$app->user->identity->status == USER::STATUS_ADMIN
  33. || Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
  34. }
  35. ]
  36. ],
  37. ],
  38. ];
  39. }
  40. /**
  41. * Lists all User models.
  42. * @return mixed
  43. */
  44. public function actionIndex()
  45. {
  46. $dataProvider = new ActiveDataProvider([
  47. 'query' => User::find(),
  48. ]);
  49. return $this->render('index', [
  50. 'dataProvider' => $dataProvider,
  51. ]);
  52. }
  53. /**
  54. * Displays a single User model.
  55. * @param integer $id
  56. * @return mixed
  57. */
  58. public function actionView($id)
  59. {
  60. return $this->render('view', [
  61. 'model' => $this->findModel($id),
  62. ]);
  63. }
  64. /**
  65. * Creates a new User model.
  66. * If creation is successful, the browser will be redirected to the 'view' page.
  67. * @return mixed
  68. */
  69. public function actionCreate()
  70. {
  71. $model = new User();
  72. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  73. return $this->redirect(['view', 'id' => $model->id]);
  74. } else {
  75. return $this->render('create', [
  76. 'model' => $model,
  77. ]);
  78. }
  79. }
  80. /**
  81. * Updates an existing User model.
  82. * If update is successful, the browser will be redirected to the 'view' page.
  83. * @param integer $id
  84. * @return mixed
  85. */
  86. public function actionUpdate($id)
  87. {
  88. $model = $this->findModel($id);
  89. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  90. return $this->redirect(['view', 'id' => $model->id]);
  91. } else {
  92. return $this->render('update', [
  93. 'model' => $model,
  94. ]);
  95. }
  96. }
  97. /**
  98. * Deletes an existing User model.
  99. * If deletion is successful, the browser will be redirected to the 'index' page.
  100. * @param integer $id
  101. * @return mixed
  102. */
  103. public function actionDelete($id)
  104. {
  105. $this->findModel($id)->delete();
  106. return $this->redirect(['index']);
  107. }
  108. public function actionMail() {
  109. /*$model = new MailForm() ;
  110. $model->subject = '[Le Chat des Noisettes] ' ;
  111. $model->body =
  112. "Bonjour,
  113. PS : Si vous ne souhaitez plus recevoir ces emails, rendez-vous dans votre compte sur www.lechatdesnoisettes.com." ;
  114. if ($model->load(Yii::$app->request->post()) && $model->validate()) {
  115. $id_user = Yii::$app->request->post('id_user') ;
  116. $user = User::findIdentity($id_user) ;
  117. if($user)
  118. {
  119. $model->sendEmail($user->email) ;
  120. }
  121. }*/
  122. $users = User::find()->all() ;
  123. $arr_users = [] ;
  124. foreach($users as $u)
  125. $arr_users[] = $u->email ;
  126. return $this->render('liste_mails', [
  127. //'model' => $model,
  128. 'users' => $arr_users
  129. ]);
  130. }
  131. /**
  132. * Finds the User model based on its primary key value.
  133. * If the model is not found, a 404 HTTP exception will be thrown.
  134. * @param integer $id
  135. * @return User the loaded model
  136. * @throws NotFoundHttpException if the model cannot be found
  137. */
  138. protected function findModel($id)
  139. {
  140. if (($model = User::findOne($id)) !== null) {
  141. return $model;
  142. } else {
  143. throw new NotFoundHttpException('The requested page does not exist.');
  144. }
  145. }
  146. }