<commit_before><?php

namespace mrssoft\engine\controllers;

use mrssoft\engine\models\LoginForm;
use Yii;
use yii\base\UserException;
use yii\web\MethodNotAllowedHttpException;

class AuthController extends \yii\web\Controller
{
    public function actionLogin()
    {
        $model = new LoginForm();
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
            return $this->redirect(['/' . $this->module->id]);
        }

        $model->username = '';
        $model->password = '';

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

    public function actionLogout()
    {
        if (Yii::$app->request->isPost === false) {
            throw new MethodNotAllowedHttpException();
        }

        if (Yii::$app->user->isGuest) {
            throw new UserException('User not found.');
        }

        Yii::$app->user->logout();
        $this->redirect(['/' . $this->module->id]);
    }
}<commit_msg>Fix login / logout methods<commit_after><?php

namespace mrssoft\engine\controllers;

use mrssoft\engine\models\LoginForm;
use Yii;
use yii\web\MethodNotAllowedHttpException;

/**
 * Авторизация в ПУ
 */
class AuthController extends \yii\web\Controller
{
    /**
     * Вход
     * @return string|\yii\web\Response
     */
    public function actionLogin()
    {
        if (Yii::$app->user->isGuest === false) {
            return $this->redirect(['/' . $this->module->id]);
        }

        $model = new LoginForm();
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
            return $this->redirect(['/' . $this->module->id]);
        }

        $model->username = '';
        $model->password = '';

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

    /**
     * Выход
     * @return \yii\web\Response
     * @throws \yii\web\MethodNotAllowedHttpException
     */
    public function actionLogout()
    {
        if (Yii::$app->request->isPost === false) {
            throw new MethodNotAllowedHttpException();
        }
        if (Yii::$app->user->isGuest === false) {
            Yii::$app->user->logout();
        }

        return $this->redirect(['/' . $this->module->id]);
    }
}
{'fraction_non_alphanumeric': 0.18079350766456267, 'fraction_numerical': 0.0, 'mean_word_length': 2.2299854439592433, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 48, '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': '4601010', 'n_tokens_mistral': 681, 'n_tokens_neox': 685, 'n_words': 119}