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.

106 satır
2.7KB

  1. <?php
  2. namespace backend\controllers;
  3. use Yii;
  4. use yii\filters\AccessControl;
  5. use yii\web\Controller;
  6. use common\models\LoginForm;
  7. use common\models\User;
  8. use yii\filters\VerbFilter;
  9. /**
  10. * Site controller
  11. */
  12. class SiteController extends BackendController
  13. {
  14. /**
  15. * @inheritdoc
  16. */
  17. public function behaviors()
  18. {
  19. return [
  20. 'access' => [
  21. 'class' => AccessControl::className(),
  22. 'rules' => [
  23. [
  24. 'actions' => ['login', 'error'],
  25. 'allow' => true,
  26. ],
  27. [
  28. 'actions' => ['logout', 'index'],
  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. 'actions' => ['change-etablissement'],
  38. 'allow' => true,
  39. 'roles' => ['@'],
  40. 'matchCallback' => function ($rule, $action) {
  41. return Yii::$app->user->identity->status == USER::STATUS_ADMIN ;
  42. }
  43. ],
  44. ],
  45. ],
  46. 'verbs' => [
  47. 'class' => VerbFilter::className(),
  48. 'actions' => [
  49. 'logout' => ['post'],
  50. ],
  51. ],
  52. ];
  53. }
  54. /**
  55. * @inheritdoc
  56. */
  57. public function actions()
  58. {
  59. return [
  60. 'error' => [
  61. 'class' => 'yii\web\ErrorAction',
  62. ],
  63. ];
  64. }
  65. public function actionIndex()
  66. {
  67. return $this->render('index');
  68. }
  69. public function actionLogin()
  70. {
  71. if (!\Yii::$app->user->isGuest) {
  72. return $this->goHome();
  73. }
  74. $model = new LoginForm();
  75. if ($model->load(Yii::$app->request->post()) && $model->login())
  76. {
  77. return $this->goBack();
  78. }
  79. else {
  80. return $this->render('login', [
  81. 'model' => $model,
  82. ]);
  83. }
  84. }
  85. public function actionLogout()
  86. {
  87. Yii::$app->user->logout();
  88. return $this->goHome();
  89. }
  90. public function actionChangeEtablissement($id)
  91. {
  92. Yii::$app->user->identity->id_etablissement = $id ;
  93. Yii::$app->user->identity->save() ;
  94. $this->redirect(['commande/index']) ;
  95. }
  96. }