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
+}