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::refreshParent(); } 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) { $this->module->layout = null; Yii::$app->grom->applyModalLayout(); } 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); try { 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::refreshParent(); } } catch (\Exception $e) { Yii::$app->session->setFlash(Alert::TYPE_DANGER, $e->getMessage()); } } } if ($modal) { Yii::$app->grom->applyModalLayout(); } return $this->render('params', ['model' => $model]); }
public function actionParams($type = 'main', $modal = null) { /*$paramsPath = Yii::getAlias($this->module->paramsPath); $paramsFile = $paramsPath . DIRECTORY_SEPARATOR . 'params.php'; $params = $this->module->params; $model = new ObjectModel(MainParams::className()); $model->setAttributes($params);*/ /** @var \gromver\platform\core\components\ParamsObject $params */ $params = Yii::$app->paramsManager->{$type}; $model = new ObjectModel($params); $model->setAttributes($params->toArray()); if ($model->load(Yii::$app->request->post())) { if ($model->validate() && Yii::$app->request->getBodyParam('task') !== 'refresh') { try { $params->load($model->toArray())->save(); Yii::$app->session->setFlash(Alert::TYPE_SUCCESS, Yii::t('gromver.platform', 'Configuration saved.')); if ($modal) { ModalIFrame::refreshParent(); } } catch (\Exception $e) { Yii::$app->session->setFlash(Alert::TYPE_DANGER, $e->getMessage()); } } } if ($modal) { Yii::$app->applyModalLayout(); } $items = []; foreach (Yii::$app->paramsManager->getParamsInfo() as $itemType => $info) { /** @var \gromver\platform\core\components\ParamsObject $params */ $params = Yii::$app->paramsManager->{$itemType}; $items[] = ['label' => $params->paramsName(), 'url' => ['params', 'type' => $itemType, 'modal' => $modal], 'active' => $itemType == $type]; } return $this->render('params', ['paramsMenuItems' => $items, 'model' => $model]); }
public function run($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 (WidgetConfigPersonal::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) { $configModel->delete(); } } elseif ($configModel = WidgetConfigPersonal::findOne(['widget_id' => $widget_id, 'context' => $selected_context, 'language' => Yii::$app->language])) { $configModel->delete(); } if ($modal) { ModalIFrame::refreshParent(); } } $widget_config = Yii::$app->request->getBodyParam('widget_config', '[]'); $widgetConfig = Json::decode($widget_config); $widgetConfig['id'] = $widget_id; $widgetConfig['context'] = $selected_context; $widgetConfig['skipInit'] = true; /** @var \gromver\platform\basic\modules\widget\widgets\Widget $widget */ $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 = WidgetConfigPersonal::findOne(['widget_id' => $widget_id, 'context' => $selected_context, 'language' => Yii::$app->language]) or $configModel = new WidgetConfigPersonal(); $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 (WidgetConfigPersonal::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 $configModel WidgetConfigPersonal */ $configModel->delete(); } } if ($modal) { ModalIFrame::refreshParent(); } else { return $this->redirect($url); } } } if ($modal) { Yii::$app->grom->applyModalLayout(); } return $this->controller->render($this->view, ['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]); }
/** * @param integer $id * @param null $modal * @throws HttpException * @throws NotFoundHttpException */ public function actionRestore($id, $modal = null) { $model = $this->findModel($id); if ($model->restore()) { if ($modal) { ModalIFrame::refreshParent(); } 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())])); }
public function actionRequestPasswordResetToken($modal = null) { $model = new ForgotPasswordForm(); $model->scenario = ForgotPasswordForm::SCENARIO_REQUEST; if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($this->sendPasswordResetEmail($model->email)) { Yii::$app->getSession()->setFlash(Alert::TYPE_SUCCESS, Yii::t('gromver.platform', 'Check your email for further instructions.')); if ($modal) { ModalIFrame::refreshParent(); } return $this->goBack(); } else { Yii::$app->getSession()->setFlash(Alert::TYPE_DANGER, Yii::t('gromver.platform', 'There was an error sending email.')); } } if ($modal) { Yii::$app->applyModalLayout(); } elseif ($this->module->authLayout) { Yii::$app->layout = $this->module->authLayout; } return $this->render('requestPasswordResetToken', ['model' => $model]); }