public function actionLogin($modal = null) { if (!\Yii::$app->user->isGuest) { $this->goHome(); } $model = new LoginForm(); //make the captcha required if the unsuccessful attempts are more of thee if ($this->getLoginAttempts() >= $this->module->attemptsBeforeCaptcha) { $model->scenario = 'withCaptcha'; } if ($model->load($_POST)) { if ($model->login()) { $this->setLoginAttempts(0); //if login is successful, reset the attempts if ($modal) { ModalIFrame::refreshPage(); } return $this->goBack(); } else { //if login is not successful, increase the attempts $this->setLoginAttempts($this->getLoginAttempts() + 1); Yii::$app->session->setFlash(Alert::TYPE_DANGER, Yii::t('gromver.platform', 'Authorization is failed.')); } } if ($modal) { Yii::$app->grom->layout = 'modal'; } else { $this->module->layout = $this->module->loginLayout; } return $this->render('login', ['model' => $model]); }
public function actionParams($modal = null) { $paramsPath = Yii::getAlias($this->module->paramsPath); $paramsFile = $paramsPath . DIRECTORY_SEPARATOR . 'params.php'; $params = $this->module->params; $model = new ObjectModel(PlatformParams::className()); $model->setAttributes($params); if ($model->load(Yii::$app->request->post())) { if ($model->validate() && Yii::$app->request->getBodyParam('task') !== 'refresh') { FileHelper::createDirectory($paramsPath); file_put_contents($paramsFile, '<?php return ' . var_export($model->toArray(), true) . ';'); @chmod($paramsFile, 0777); Yii::$app->session->setFlash(Alert::TYPE_SUCCESS, Yii::t('gromver.platform', 'Configuration saved.')); if ($modal) { ModalIFrame::refreshPage(); } } } if ($modal) { $this->layout = 'modal'; } return $this->render('params', ['model' => $model]); }
public function actionConfigure($modal = null) { if (!($widget_id = Yii::$app->request->getBodyParam('widget_id'))) { throw new BadRequestHttpException(Yii::t('gromver.platform', "Widget ID isn't specified.")); } if (!($widget_class = Yii::$app->request->getBodyParam('widget_class'))) { throw new BadRequestHttpException(Yii::t('gromver.platform', "Widget Class isn't specified.")); } if (($widget_context = Yii::$app->request->getBodyParam('widget_context')) === null) { throw new BadRequestHttpException(Yii::t('gromver.platform', "Widget Context isn't specified.")); } $selected_context = Yii::$app->request->getBodyParam('selected_context', $widget_context); $task = Yii::$app->request->getBodyParam('task'); if (($url = Yii::$app->request->getBodyParam('url')) === null) { throw new BadRequestHttpException(Yii::t('gromver.platform', "Widget page url isn't specified.")); } //$url = Yii::$app->request->getBodyParam('url', Yii::$app->request->getReferrer()); if ($task == 'delete') { if (Yii::$app->request->getBodyParam('bulk-method')) { foreach (WidgetConfig::find()->where('widget_id=:widget_id AND context>=:context AND language=:language', [':widget_id' => $widget_id, ':context' => $selected_context, ':language' => Yii::$app->language])->each() as $configModel) { /** @var WidgetConfig $configModel */ $configModel->delete(); } } elseif ($configModel = WidgetConfig::findOne(['widget_id' => $widget_id, 'context' => $selected_context, 'language' => Yii::$app->language])) { $configModel->delete(); } } $widget_config = Yii::$app->request->getBodyParam('widget_config', '[]'); $widgetConfig = Json::decode($widget_config); $widgetConfig['id'] = $widget_id; $widgetConfig['context'] = $selected_context; $widget = new $widget_class($widgetConfig); $model = new ObjectModel($widget); if (($task == 'save' || $task == 'refresh') && $model->load(Yii::$app->request->post())) { if ($model->validate() && $task == 'save') { $configModel = WidgetConfig::findOne(['widget_id' => $widget_id, 'context' => $selected_context, 'language' => Yii::$app->language]) or $configModel = new WidgetConfig(); $configModel->loadDefaultValues(); $configModel->widget_id = $widget_id; $configModel->widget_class = $widget_class; $configModel->context = $selected_context; $configModel->url = $url; $configModel->setParamsArray($model->toArray()); $configModel->save(); if (Yii::$app->request->getBodyParam('bulk-method')) { foreach (WidgetConfig::find()->where('widget_id=:widget_id AND context>:context AND language=:language', [':widget_id' => $widget_id, ':context' => $selected_context, ':language' => Yii::$app->language])->each() as $configModel) { /** @var WidgetConfig $configModel */ $configModel->delete(); } } if ($modal) { ModalIFrame::refreshPage(); } else { return $this->redirect($url); } } } if ($modal) { Yii::$app->grom->layout = 'modal'; } return $this->render('_formConfig', ['model' => $model, 'widget' => $widget, 'widget_id' => $widget_id, 'widget_class' => $widget_class, 'widget_config' => $widget_config, 'widget_context' => $widget_context, 'selected_context' => $selected_context, 'url' => $url]); }
public function actionRestore($id, $modal = null) { $model = $this->findModel($id); if ($model->restore()) { if ($modal) { ModalIFrame::refreshPage(); } else { return $this->redirect(['view', 'id' => $model->id]); } } throw new HttpException(409, Yii::t('gromver.platform', "Version restore is failed:\n{errors}", ['errors' => implode("\n", $model->getRestoreErrors())])); }