Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

173 rindas
4.3KB

  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. }*/
  34. ]
  35. ],
  36. ],
  37. ];
  38. }
  39. /**
  40. * Lists all User models.
  41. * @return mixed
  42. */
  43. public function actionIndex()
  44. {
  45. $dataProvider = new ActiveDataProvider([
  46. 'query' => User::find(),
  47. ]);
  48. return $this->render('index', [
  49. 'dataProvider' => $dataProvider,
  50. ]);
  51. }
  52. /**
  53. * Displays a single User model.
  54. * @param integer $id
  55. * @return mixed
  56. */
  57. public function actionView($id)
  58. {
  59. return $this->render('view', [
  60. 'model' => $this->findModel($id),
  61. ]);
  62. }
  63. /**
  64. * Creates a new User model.
  65. * If creation is successful, the browser will be redirected to the 'view' page.
  66. * @return mixed
  67. */
  68. public function actionCreate()
  69. {
  70. $model = new User();
  71. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  72. return $this->redirect(['view', 'id' => $model->id]);
  73. } else {
  74. return $this->render('create', [
  75. 'model' => $model,
  76. ]);
  77. }
  78. }
  79. /**
  80. * Updates an existing User model.
  81. * If update is successful, the browser will be redirected to the 'view' page.
  82. * @param integer $id
  83. * @return mixed
  84. */
  85. public function actionUpdate($id)
  86. {
  87. $model = $this->findModel($id);
  88. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  89. return $this->redirect(['view', 'id' => $model->id]);
  90. } else {
  91. return $this->render('update', [
  92. 'model' => $model,
  93. ]);
  94. }
  95. }
  96. /**
  97. * Deletes an existing User model.
  98. * If deletion is successful, the browser will be redirected to the 'index' page.
  99. * @param integer $id
  100. * @return mixed
  101. */
  102. public function actionDelete($id)
  103. {
  104. $this->findModel($id)->delete();
  105. return $this->redirect(['index']);
  106. }
  107. public function actionMail() {
  108. /*$model = new MailForm() ;
  109. $model->subject = '[Le Chat des Noisettes] ' ;
  110. $model->body =
  111. "Bonjour,
  112. PS : Si vous ne souhaitez plus recevoir ces emails, rendez-vous dans votre compte sur www.lechatdesnoisettes.com." ;
  113. if ($model->load(Yii::$app->request->post()) && $model->validate()) {
  114. $id_user = Yii::$app->request->post('id_user') ;
  115. $user = User::findIdentity($id_user) ;
  116. if($user)
  117. {
  118. $model->sendEmail($user->email) ;
  119. }
  120. }*/
  121. $users = User::find()->all() ;
  122. $arr_users = [] ;
  123. foreach($users as $u)
  124. $arr_users[] = $u->email ;
  125. return $this->render('liste_mails', [
  126. //'model' => $model,
  127. 'users' => $arr_users
  128. ]);
  129. }
  130. /**
  131. * Finds the User model based on its primary key value.
  132. * If the model is not found, a 404 HTTP exception will be thrown.
  133. * @param integer $id
  134. * @return User the loaded model
  135. * @throws NotFoundHttpException if the model cannot be found
  136. */
  137. protected function findModel($id)
  138. {
  139. if (($model = User::findOne($id)) !== null) {
  140. return $model;
  141. } else {
  142. throw new NotFoundHttpException('The requested page does not exist.');
  143. }
  144. }
  145. }