From: Aleksey Filippov Date: Fri, 15 Mar 2024 10:41:04 +0000 (+0300) Subject: fix set actual code from erp X-Git-Tag: 1.1~171^2~2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=8a3ee91a43c094289922a0d8a72296a2e2a95b28;p=erp24_rep%2Fyii-erp24%2F.git fix set actual code from erp --- diff --git a/erp24/controllers/SiteController.php b/erp24/controllers/SiteController.php index b58b3b25..ad1c3a98 100644 --- a/erp24/controllers/SiteController.php +++ b/erp24/controllers/SiteController.php @@ -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 +}