]> gitweb.erp-flowers.ru Git - yii-erp24/.git/commitdiff
fix set actual code from erp
authorAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Fri, 15 Mar 2024 10:41:04 +0000 (13:41 +0300)
committerAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Fri, 15 Mar 2024 10:41:04 +0000 (13:41 +0300)
erp24/controllers/SiteController.php

index b58b3b258aa9c3d1214da0b5c57b047c1a7995de..ad1c3a98e2279dd08f77a38ca01cb8a257a20b69 100644 (file)
@@ -5,12 +5,127 @@ namespace app\controllers;
 use GuzzleHttp\Client;
 use Yii;
 use yii\web\Controller;
+use yii\web\Response;
+use yii\filters\VerbFilter;
+use app\models\LoginForm;
+use app\models\ContactForm;
+use yii_app\records\CrmMenu;
+
+class SiteController extends Controller
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function behaviors()
+    {
+        return [
+            'verbs' => [
+                'class' => VerbFilter::class,
+                'actions' => [
+                    'logout' => ['get'],
+                ],
+            ],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function actions()
+    {
+        return [
+            'error' => [
+                'class' => 'yii\web\ErrorAction',
+            ],
+            'captcha' => [
+                'class' => 'yii\captcha\CaptchaAction',
+                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
+            ],
+        ];
+    }
+
+    /**
+     * Displays homepage.
+     *
+     * @return string
+     */
+    public function actionIndex()
+    {
+        return $this->render('index');
+    }
+
+    /**
+     * Login action.
+     *
+     * @return Response|string
+     */
+    public function actionLogin()
+    {
+        if (!Yii::$app->user->isGuest) {
+            return $this->goHome();
+        }
+
+        $model = new LoginForm();
+        if (Yii::$app->request->isPost) {
+            if ($model->load(Yii::$app->request->post()) && $model->login()) {
+                return $this->goBack();
+            } else {
+                return $this->refresh();
+            }
+        }
+
+        $model->password = '';
+        return $this->renderPartial('login', [
+            'model' => $model,
+        ]);
+    }
+
+    /**
+     * Logout action.
+     *
+     * @return Response
+     */
+    public function actionLogout()
+    {
+        if (!Yii::$app->user->isGuest) {
+            Yii::$app->user->logout();
+        }
+
+        return $this->redirect('/site/login');
+    }
+
+    /**
+     * Displays contact page.
+     *
+     * @return Response|string
+     */
+    public function actionContact()
+    {
+        $model = new ContactForm();
+        if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
+            Yii::$app->session->setFlash('contactFormSubmitted');
+
+            return $this->refresh();
+        }
+        return $this->render('contact', [
+            'model' => $model,
+        ]);
+    }
+
+    /**
+     * Displays about page.
+     *
+     * @return string
+     */
+    public function actionAbout()
+    {
+        return $this->render('about');
+    }
 
-class SiteController extends Controller {
     public function actionMenuTree() {
-        $client = new Client(['base_uri' => Yii::$app->params['API2_URL']]);
-        $response = $client->request('GET', '/site/menu-tree?user_id=' . Yii::$app->user->id . '&key=' . Yii::$app->params['API2_TOKEN']);
-//        Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
-        return $this->asJson(json_decode($response->getBody(), true));
+//        $client = new Client(['base_uri' => Yii::$app->params['API2_URL']]);
+//        $response = $client->request('GET', '/site/menu-tree?user_id=' . Yii::$app->user->id . '&key=' . Yii::$app->params['API2_TOKEN']);
+//        return $this->asJson(json_decode($response->getBody(), true));
+        return $this->asJson(CrmMenu::getTreeByUserId(Yii::$app->user->id));
     }
-}
\ No newline at end of file
+}