/**
  * Updates an existing ContactMsg model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->getSession()->setFlash('success', Adm::t('', 'Data successfully changed!'));
         return Adm::redirect(['update', 'id' => $model->id]);
     }
     return $this->render('update', ['model' => $model]);
 }
Ejemplo n.º 2
0
 /**
  * @return string
  */
 public function actionIndex()
 {
     $module = Module::getInstance();
     /* @var $model \app\modules\admlivechat\models\SettingsForm */
     $model = $module->manager->createSettingsForm();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if ($model->save()) {
             Yii::$app->getSession()->setFlash('success', Adm::t('', 'Data successfully changed!'));
             return Adm::redirect(['index']);
         }
     }
     return $this->render('index', ['model' => $model]);
 }
Ejemplo n.º 3
0
 /**
  * Updates an existing Page model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param string $id
  * @param null|integer $id_parent
  * @return mixed
  */
 public function actionUpdate($id, $id_parent = null)
 {
     $model = $this->findModel($id);
     $model->setLangScenario('update-page-lang');
     if ($model->loadAll(Yii::$app->request->post()) && $model->validateAll()) {
         if ($model->saveAll(false)) {
             Yii::$app->getSession()->setFlash('success', Adm::t('', 'Data successfully changed!'));
             if (!$id_parent) {
                 $id_parent = 0;
             }
             return Adm::redirect(['update', 'id' => $model->id, 'id_parent' => $id_parent]);
         }
     }
     return $this->render('update', ['model' => $model, 'id_parent' => $id_parent]);
 }
Ejemplo n.º 4
0
 /**
  * Deletes an existing Params model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $this->findModel($id)->delete();
     Yii::$app->getSession()->setFlash('success', Adm::t('', 'Data successfully removed!'));
     return Adm::redirect(['index']);
 }
Ejemplo n.º 5
0
 /**
  * @inheritdoc
  */
 public function actionLogout()
 {
     Adm::getInstance()->user->logout(false);
     return Adm::redirect(['login']);
 }
Ejemplo n.º 6
0
 /**
  * Updates an existing User model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param null $id
  * @return string|\yii\web\Response
  * @throws ForbiddenHttpException
  * @throws NotFoundHttpException
  * @throws \yii\base\InvalidConfigException
  */
 public function actionUpdate($id = null)
 {
     if ($id === null) {
         $id = Adm::getInstance()->user->getId();
     }
     /* @var $model \pavlinter\adm\models\User */
     $model = $this->findModel($id);
     if (Adm::getInstance()->user->can('Adm-UpdateOwnUser', $model)) {
         $model->setScenario('adm-updateOwn');
     } elseif (Adm::getInstance()->user->can('AdmRoot')) {
         $model->setScenario('adm-update');
     } else {
         throw new ForbiddenHttpException('Access denied');
     }
     $dynamicModel = DynamicModel::validateData(['password', 'password2'], [[['password', 'password2'], 'string', 'min' => 6], ['password2', 'compare', 'compareAttribute' => 'password']]);
     $post = Yii::$app->request->post();
     if ($model->load($post) && $dynamicModel->load($post)) {
         if ($model->validate() && $dynamicModel->validate()) {
             if (!empty($dynamicModel->password)) {
                 $model->setPassword($dynamicModel->password);
             }
             if (!Adm::getInstance()->user->can('Adm-UpdateOwnUser', $model)) {
                 //AdmRoot
                 $auth = Yii::$app->authManager;
                 $roles = Yii::$app->request->post('roles', []);
                 $auth->revokeAll($model->id);
                 //remove all assignments
                 if (in_array('AdmRoot', $roles) || in_array('AdmAdmin', $roles)) {
                     $model->role = \app\models\User::ROLE_ADM;
                 } else {
                     $model->role = \app\models\User::ROLE_USER;
                 }
                 foreach ($roles as $role) {
                     $newRole = $auth->createRole($role);
                     $auth->assign($newRole, $model->id);
                 }
             }
             $model->save(false);
             Yii::$app->getSession()->setFlash('success', Adm::t('', 'Data successfully changed!'));
             if (Adm::getInstance()->user->can('Adm-UpdateOwnUser', $model)) {
                 return $this->refresh();
             } else {
                 //AdmRoot
                 return Adm::redirect(['update', 'id' => $model->id]);
             }
         }
     }
     return $this->render('update', ['model' => $model, 'dynamicModel' => $dynamicModel]);
 }
 /**
  * @return \yii\web\Response
  */
 public function actionTest()
 {
     $error = Module::getInstance()->manager->createEmailConfigQuery('eachEmail', function ($email) {
         try {
             Yii::$app->mailer->compose()->setTo($email)->setFrom(Yii::$app->params['adminEmailName'])->setSubject(Adm::t('adm_email_config', 'Test subject', ['dot' => false]))->setHtmlBody(Adm::t('adm_email_config', 'Test text', ['dot' => false]))->send();
         } catch (\Exception $e) {
             if ($e instanceof \Swift_RfcComplianceException) {
                 Yii::$app->getSession()->setFlash('error', Adm::t('adm_email_config', 'Maybe incorrect email address: {error}', ['error' => $e->getMessage(), 'dot' => true]));
             } else {
                 Yii::$app->getSession()->setFlash('error', Adm::t('adm_email_config', 'Error: {error}', ['error' => $e->getMessage(), 'dot' => true]));
             }
             return true;
         }
     });
     if ($error) {
         Yii::$app->getSession()->removeFlash('success');
     } else {
         Yii::$app->getSession()->setFlash('success', Adm::t('adm_email_config', 'Email sent!', ['dot' => true]));
     }
     return Adm::redirect(['update']);
 }