<commit_before><?php

namespace backend\controllers;

use Yii;
use common\models\LoginForm;
use yii\web\VerbFilter;
use backend\models\Setting;
use yii\base\Model;

class SiteController extends \yii\web\Controller
{
	public function behaviors()
	{
		return [
			'access' => [
				'class' => \yii\web\AccessControl::className(),
				'rules' => [
					[
						'actions' => ['login', 'error', 'upload'],
						'allow' => true,
                        'roles' => ['?'],
					],
					[
						'actions' => ['logout', 'index', 'login', 'error', 'settings', 'upload', 'makeadmin'],
						'allow' => true,
						'roles' => ['admin'],
					],
				],
			],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'logout' => ['post'],
                ],
            ],
		];
	}

    public function actionIndex()
    {
        return $this->render('index');
    }

	public function actions()
	{
		return [
			'error' => [
				'class' => 'yii\web\ErrorAction',
			],
		];
	}

    public function actionLogin()
    {
        if (!\Yii::$app->user->isGuest) {
            return $this->goHome();
        }

        $model = new LoginForm();
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
            return $this->goBack();
        } else {
            return $this->render('login', [
                'model' => $model,
            ]);
        }
    }

    public function actionLogout()
    {
        Yii::$app->user->logout();
        return $this->goHome();
    }

    public function actionSettings()
    {
        $settings = Setting::find()->indexBy('id')->all();

        if (Model::loadMultiple($settings, Yii::$app->request->post()) && Model::validateMultiple($settings)) {
            foreach ($settings as $setting) {
                $setting->save(false);
            }

            return $this->redirect('settings');
        }

        return $this->render('settings', ['settings' => $settings]);
    }

    public function actionUpload()
    {
        //If any media upload catch it and upload it
        $mediaJson = \Yii::$app->kato->mediaUpload();

        $media = \yii\helpers\Json::decode($mediaJson);

        if (isset($_GET['content_id'])) {
            if (is_array($media) AND !!empty($media)) {
                //Do join here
            }
        }

        return $mediaJson;
    }

    public function actionMakeadmin()
    {
        $r=new \yii\rbac\DbManager;
        $r->init();
        $r->createRole("admin","Administrator");
        $r->save();

        $r->assign('1','admin');
    }
}<commit_msg>update in site controller<commit_after><?php

namespace backend\controllers;

use Yii;
use common\models\LoginForm;
use yii\web\VerbFilter;
use backend\models\Setting;
use yii\base\Model;

class SiteController extends \yii\web\Controller
{
	public function behaviors()
	{
		return [
			'access' => [
				'class' => \yii\web\AccessControl::className(),
				'rules' => [
					[
						'actions' => ['login', 'error', 'upload'],
						'allow' => true,
                        'roles' => ['?'],
					],
					[
						'actions' => ['logout', 'index', 'login', 'error', 'settings', 'upload', 'makeadmin'],
						'allow' => true,
						'roles' => ['admin'],
					],
				],
			],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'logout' => ['post'],
                ],
            ],
		];
	}

    public function actionIndex()
    {
        return $this->render('index');
    }

	public function actions()
	{
		return [
			'error' => [
				'class' => 'yii\web\ErrorAction',
			],
		];
	}

    public function actionLogin()
    {
        if (!\Yii::$app->user->isGuest) {
            return $this->goHome();
        }

        $model = new LoginForm();
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
            return $this->goBack();
        } else {
            return $this->render('login', [
                'model' => $model,
            ]);
        }
    }

    public function actionLogout()
    {
        Yii::$app->user->logout();
        return $this->goHome();
    }

    public function actionSettings()
    {
        $settings = Setting::find()->indexBy('id')->all();

        if (Model::loadMultiple($settings, Yii::$app->request->post()) && Model::validateMultiple($settings)) {
            foreach ($settings as $setting) {
                $setting->save(false);
            }

            return $this->redirect('settings');
        }

        return $this->render('settings', ['settings' => $settings]);
    }

    public function actionUpload()
    {
        //If any media upload catch it and upload it
        $mediaJson = \Yii::$app->kato->mediaUpload();

        $media = \yii\helpers\Json::decode($mediaJson);

        if (isset($_GET['content_id'])) {
            if (is_array($media) AND !!empty($media)) {
                //Do join here
            }
        }

        echo $mediaJson;
    }

    public function actionMakeadmin()
    {
        $r=new \yii\rbac\DbManager;
        $r->init();
        $r->createRole("admin","Administrator");
        $r->save();

        $r->assign('1','admin');
    }
}
{'fraction_non_alphanumeric': 0.18445121951219512, 'fraction_numerical': 0.00038109756097560977, 'mean_word_length': 1.846529284164859, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1198195', 'n_tokens_mistral': 1728, 'n_tokens_neox': 1560, 'n_words': 291}